@gnolang/tm2-js-client 1.3.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.cjs +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.cjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.mjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.cjs +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.mjs +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.cjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.mjs +11 -0
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/index.cjs +92 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +22 -0
- package/dist/index.mjs.map +1 -0
- package/dist/proto/google/protobuf/any.cjs +84 -0
- package/dist/proto/google/protobuf/any.cjs.map +1 -0
- package/dist/proto/google/protobuf/any.d.cts +141 -0
- package/dist/proto/google/protobuf/any.d.cts.map +1 -0
- package/dist/proto/google/protobuf/any.d.mts +141 -0
- package/dist/proto/google/protobuf/any.d.mts.map +1 -0
- package/dist/proto/google/protobuf/any.mjs +83 -0
- package/dist/proto/google/protobuf/any.mjs.map +1 -0
- package/dist/proto/index.cjs +2 -0
- package/dist/proto/index.d.cts +2 -0
- package/dist/proto/index.d.mts +2 -0
- package/dist/proto/index.mjs +3 -0
- package/dist/proto/tm2/abci.cjs +182 -0
- package/dist/proto/tm2/abci.cjs.map +1 -0
- package/dist/proto/tm2/abci.d.cts +33 -0
- package/dist/proto/tm2/abci.d.cts.map +1 -0
- package/dist/proto/tm2/abci.d.mts +33 -0
- package/dist/proto/tm2/abci.d.mts.map +1 -0
- package/dist/proto/tm2/abci.mjs +181 -0
- package/dist/proto/tm2/abci.mjs.map +1 -0
- package/dist/proto/tm2/tx.cjs +263 -0
- package/dist/proto/tm2/tx.cjs.map +1 -0
- package/dist/proto/tm2/tx.d.cts +49 -0
- package/dist/proto/tm2/tx.d.cts.map +1 -0
- package/dist/proto/tm2/tx.d.mts +49 -0
- package/dist/proto/tm2/tx.d.mts.map +1 -0
- package/dist/proto/tm2/tx.mjs +258 -0
- package/dist/proto/tm2/tx.mjs.map +1 -0
- package/dist/provider/endpoints.cjs +43 -0
- package/dist/provider/endpoints.cjs.map +1 -0
- package/dist/provider/endpoints.d.cts +33 -0
- package/dist/provider/endpoints.d.cts.map +1 -0
- package/dist/provider/endpoints.d.mts +33 -0
- package/dist/provider/endpoints.d.mts.map +1 -0
- package/dist/provider/endpoints.mjs +39 -0
- package/dist/provider/endpoints.mjs.map +1 -0
- package/dist/provider/errors/errors.cjs +122 -0
- package/dist/provider/errors/errors.cjs.map +1 -0
- package/dist/provider/errors/errors.d.cts +62 -0
- package/dist/provider/errors/errors.d.cts.map +1 -0
- package/dist/provider/errors/errors.d.mts +62 -0
- package/dist/provider/errors/errors.d.mts.map +1 -0
- package/dist/provider/errors/errors.mjs +104 -0
- package/dist/provider/errors/errors.mjs.map +1 -0
- package/dist/provider/errors/messages.cjs +40 -0
- package/dist/provider/errors/messages.cjs.map +1 -0
- package/dist/provider/errors/messages.mjs +23 -0
- package/dist/provider/errors/messages.mjs.map +1 -0
- package/dist/provider/index.cjs +12 -0
- package/dist/provider/index.d.cts +11 -0
- package/dist/provider/index.d.mts +11 -0
- package/dist/provider/index.mjs +13 -0
- package/dist/provider/jsonrpc/index.cjs +1 -0
- package/dist/provider/jsonrpc/index.d.cts +1 -0
- package/dist/provider/jsonrpc/index.d.mts +1 -0
- package/dist/provider/jsonrpc/index.mjs +2 -0
- package/dist/provider/jsonrpc/jsonrpc.cjs +20 -0
- package/dist/provider/jsonrpc/jsonrpc.cjs.map +1 -0
- package/dist/provider/jsonrpc/jsonrpc.d.cts +16 -0
- package/dist/provider/jsonrpc/jsonrpc.d.cts.map +1 -0
- package/dist/provider/jsonrpc/jsonrpc.d.mts +16 -0
- package/dist/provider/jsonrpc/jsonrpc.d.mts.map +1 -0
- package/dist/provider/jsonrpc/jsonrpc.mjs +19 -0
- package/dist/provider/jsonrpc/jsonrpc.mjs.map +1 -0
- package/dist/provider/provider.cjs +130 -0
- package/dist/provider/provider.cjs.map +1 -0
- package/dist/provider/provider.d.cts +130 -0
- package/dist/provider/provider.d.cts.map +1 -0
- package/dist/provider/provider.d.mts +130 -0
- package/dist/provider/provider.d.mts.map +1 -0
- package/dist/provider/provider.mjs +130 -0
- package/dist/provider/provider.mjs.map +1 -0
- package/dist/provider/types/abci.cjs +6 -0
- package/dist/provider/types/abci.cjs.map +1 -0
- package/dist/provider/types/abci.d.cts +42 -0
- package/dist/provider/types/abci.d.cts.map +1 -0
- package/dist/provider/types/abci.d.mts +42 -0
- package/dist/provider/types/abci.d.mts.map +1 -0
- package/dist/provider/types/abci.mjs +6 -0
- package/dist/provider/types/abci.mjs.map +1 -0
- package/dist/provider/types/common.d.cts +186 -0
- package/dist/provider/types/common.d.cts.map +1 -0
- package/dist/provider/types/common.d.mts +186 -0
- package/dist/provider/types/common.d.mts.map +1 -0
- package/dist/provider/types/jsonrpc.d.cts +30 -0
- package/dist/provider/types/jsonrpc.d.cts.map +1 -0
- package/dist/provider/types/jsonrpc.d.mts +30 -0
- package/dist/provider/types/jsonrpc.d.mts.map +1 -0
- package/dist/provider/utility/adapters.cjs +241 -0
- package/dist/provider/utility/adapters.cjs.map +1 -0
- package/dist/provider/utility/adapters.d.cts +19 -0
- package/dist/provider/utility/adapters.d.cts.map +1 -0
- package/dist/provider/utility/adapters.d.mts +19 -0
- package/dist/provider/utility/adapters.d.mts.map +1 -0
- package/dist/provider/utility/adapters.mjs +231 -0
- package/dist/provider/utility/adapters.mjs.map +1 -0
- package/dist/provider/utility/errors.utility.cjs +38 -0
- package/dist/provider/utility/errors.utility.cjs.map +1 -0
- package/dist/provider/utility/errors.utility.mjs +38 -0
- package/dist/provider/utility/errors.utility.mjs.map +1 -0
- package/dist/provider/utility/index.cjs +3 -0
- package/dist/provider/utility/index.d.cts +3 -0
- package/dist/provider/utility/index.d.mts +3 -0
- package/dist/provider/utility/index.mjs +4 -0
- package/dist/provider/utility/provider.utility.cjs +122 -0
- package/dist/provider/utility/provider.utility.cjs.map +1 -0
- package/{bin/provider/utility/provider.utility.d.ts → dist/provider/utility/provider.utility.d.cts} +15 -10
- package/dist/provider/utility/provider.utility.d.cts.map +1 -0
- package/dist/provider/utility/provider.utility.d.mts +45 -0
- package/dist/provider/utility/provider.utility.d.mts.map +1 -0
- package/dist/provider/utility/provider.utility.mjs +116 -0
- package/dist/provider/utility/provider.utility.mjs.map +1 -0
- package/dist/provider/utility/requests.utility.cjs +75 -0
- package/dist/provider/utility/requests.utility.cjs.map +1 -0
- package/dist/provider/utility/requests.utility.d.cts +40 -0
- package/dist/provider/utility/requests.utility.d.cts.map +1 -0
- package/dist/provider/utility/requests.utility.d.mts +40 -0
- package/dist/provider/utility/requests.utility.d.mts.map +1 -0
- package/dist/provider/utility/requests.utility.mjs +68 -0
- package/dist/provider/utility/requests.utility.mjs.map +1 -0
- package/dist/provider/websocket/index.cjs +1 -0
- package/dist/provider/websocket/index.d.cts +1 -0
- package/dist/provider/websocket/index.d.mts +1 -0
- package/dist/provider/websocket/index.mjs +2 -0
- package/dist/provider/websocket/ws.cjs +27 -0
- package/dist/provider/websocket/ws.cjs.map +1 -0
- package/dist/provider/websocket/ws.d.cts +21 -0
- package/dist/provider/websocket/ws.d.cts.map +1 -0
- package/dist/provider/websocket/ws.d.mts +21 -0
- package/dist/provider/websocket/ws.d.mts.map +1 -0
- package/dist/provider/websocket/ws.mjs +26 -0
- package/dist/provider/websocket/ws.mjs.map +1 -0
- package/dist/services/index.cjs +1 -0
- package/dist/services/index.d.cts +2 -0
- package/dist/services/index.d.mts +2 -0
- package/dist/services/index.mjs +2 -0
- package/dist/services/rest/restService.cjs +16 -0
- package/dist/services/rest/restService.cjs.map +1 -0
- package/dist/services/rest/restService.d.cts +9 -0
- package/dist/services/rest/restService.d.cts.map +1 -0
- package/dist/services/rest/restService.d.mts +9 -0
- package/dist/services/rest/restService.d.mts.map +1 -0
- package/dist/services/rest/restService.mjs +14 -0
- package/dist/services/rest/restService.mjs.map +1 -0
- package/dist/services/rest/restService.types.d.cts +11 -0
- package/dist/services/rest/restService.types.d.cts.map +1 -0
- package/dist/services/rest/restService.types.d.mts +11 -0
- package/dist/services/rest/restService.types.d.mts.map +1 -0
- package/dist/wallet/index.cjs +8 -0
- package/dist/wallet/index.d.cts +7 -0
- package/dist/wallet/index.d.mts +7 -0
- package/dist/wallet/index.mjs +9 -0
- package/dist/wallet/key/index.cjs +1 -0
- package/dist/wallet/key/index.mjs +2 -0
- package/dist/wallet/key/key.cjs +46 -0
- package/dist/wallet/key/key.cjs.map +1 -0
- package/dist/wallet/key/key.d.cts +26 -0
- package/dist/wallet/key/key.d.cts.map +1 -0
- package/dist/wallet/key/key.d.mts +26 -0
- package/dist/wallet/key/key.d.mts.map +1 -0
- package/dist/wallet/key/key.mjs +45 -0
- package/dist/wallet/key/key.mjs.map +1 -0
- package/dist/wallet/ledger/index.cjs +1 -0
- package/dist/wallet/ledger/index.d.cts +1 -0
- package/dist/wallet/ledger/index.d.mts +1 -0
- package/dist/wallet/ledger/index.mjs +2 -0
- package/dist/wallet/ledger/ledger.cjs +49 -0
- package/dist/wallet/ledger/ledger.cjs.map +1 -0
- package/dist/wallet/ledger/ledger.d.cts +27 -0
- package/dist/wallet/ledger/ledger.d.cts.map +1 -0
- package/dist/wallet/ledger/ledger.d.mts +27 -0
- package/dist/wallet/ledger/ledger.d.mts.map +1 -0
- package/dist/wallet/ledger/ledger.mjs +48 -0
- package/dist/wallet/ledger/ledger.mjs.map +1 -0
- package/dist/wallet/signer.d.cts +33 -0
- package/dist/wallet/signer.d.cts.map +1 -0
- package/dist/wallet/signer.d.mts +33 -0
- package/dist/wallet/signer.d.mts.map +1 -0
- package/dist/wallet/types/sign.cjs +6 -0
- package/dist/wallet/types/sign.cjs.map +1 -0
- package/dist/wallet/types/sign.d.cts +20 -0
- package/dist/wallet/types/sign.d.cts.map +1 -0
- package/dist/wallet/types/sign.d.mts +20 -0
- package/dist/wallet/types/sign.d.mts.map +1 -0
- package/dist/wallet/types/sign.mjs +6 -0
- package/dist/wallet/types/sign.mjs.map +1 -0
- package/dist/wallet/types/wallet.d.cts +9 -0
- package/dist/wallet/types/wallet.d.cts.map +1 -0
- package/dist/wallet/types/wallet.d.mts +9 -0
- package/dist/wallet/types/wallet.d.mts.map +1 -0
- package/dist/wallet/utility/index.cjs +1 -0
- package/dist/wallet/utility/index.d.cts +1 -0
- package/dist/wallet/utility/index.d.mts +1 -0
- package/dist/wallet/utility/index.mjs +2 -0
- package/dist/wallet/utility/utility.cjs +83 -0
- package/dist/wallet/utility/utility.cjs.map +1 -0
- package/dist/wallet/utility/utility.d.cts +42 -0
- package/dist/wallet/utility/utility.d.cts.map +1 -0
- package/dist/wallet/utility/utility.d.mts +42 -0
- package/dist/wallet/utility/utility.d.mts.map +1 -0
- package/dist/wallet/utility/utility.mjs +75 -0
- package/dist/wallet/utility/utility.mjs.map +1 -0
- package/dist/wallet/wallet.cjs +223 -0
- package/dist/wallet/wallet.cjs.map +1 -0
- package/dist/wallet/wallet.d.cts +113 -0
- package/dist/wallet/wallet.d.cts.map +1 -0
- package/dist/wallet/wallet.d.mts +113 -0
- package/dist/wallet/wallet.d.mts.map +1 -0
- package/dist/wallet/wallet.mjs +222 -0
- package/dist/wallet/wallet.mjs.map +1 -0
- package/package.json +57 -38
- package/bin/index.d.ts +0 -4
- package/bin/index.js +0 -20
- package/bin/proto/google/protobuf/any.d.ts +0 -145
- package/bin/proto/google/protobuf/any.js +0 -113
- package/bin/proto/index.d.ts +0 -2
- package/bin/proto/index.js +0 -20
- package/bin/proto/tm2/abci.d.ts +0 -37
- package/bin/proto/tm2/abci.js +0 -277
- package/bin/proto/tm2/multisig.d.ts +0 -43
- package/bin/proto/tm2/multisig.js +0 -322
- package/bin/proto/tm2/multisig.test.d.ts +0 -1
- package/bin/proto/tm2/multisig.test.js +0 -63
- package/bin/proto/tm2/tx.d.ts +0 -52
- package/bin/proto/tm2/tx.js +0 -360
- package/bin/provider/endpoints.d.ts +0 -29
- package/bin/provider/endpoints.js +0 -37
- package/bin/provider/errors/errors.d.ts +0 -59
- package/bin/provider/errors/errors.js +0 -173
- package/bin/provider/errors/index.d.ts +0 -1
- package/bin/provider/errors/index.js +0 -17
- package/bin/provider/errors/messages.d.ts +0 -19
- package/bin/provider/errors/messages.js +0 -41
- package/bin/provider/index.d.ts +0 -7
- package/bin/provider/index.js +0 -23
- package/bin/provider/jsonrpc/index.d.ts +0 -1
- package/bin/provider/jsonrpc/index.js +0 -17
- package/bin/provider/jsonrpc/jsonrpc.d.ts +0 -31
- package/bin/provider/jsonrpc/jsonrpc.js +0 -327
- package/bin/provider/jsonrpc/jsonrpc.test.d.ts +0 -1
- package/bin/provider/jsonrpc/jsonrpc.test.js +0 -488
- package/bin/provider/provider.d.ts +0 -98
- package/bin/provider/provider.js +0 -2
- package/bin/provider/types/abci.d.ts +0 -39
- package/bin/provider/types/abci.js +0 -4
- package/bin/provider/types/common.d.ts +0 -184
- package/bin/provider/types/common.js +0 -3
- package/bin/provider/types/index.d.ts +0 -3
- package/bin/provider/types/index.js +0 -19
- package/bin/provider/types/jsonrpc.d.ts +0 -26
- package/bin/provider/types/jsonrpc.js +0 -2
- package/bin/provider/utility/errors.utility.d.ts +0 -11
- package/bin/provider/utility/errors.utility.js +0 -56
- package/bin/provider/utility/index.d.ts +0 -2
- package/bin/provider/utility/index.js +0 -18
- package/bin/provider/utility/provider.utility.js +0 -244
- package/bin/provider/utility/requests.utility.d.ts +0 -35
- package/bin/provider/utility/requests.utility.js +0 -80
- package/bin/provider/websocket/index.d.ts +0 -1
- package/bin/provider/websocket/index.js +0 -17
- package/bin/provider/websocket/ws.d.ts +0 -58
- package/bin/provider/websocket/ws.js +0 -415
- package/bin/provider/websocket/ws.test.d.ts +0 -1
- package/bin/provider/websocket/ws.test.js +0 -648
- package/bin/services/index.d.ts +0 -2
- package/bin/services/index.js +0 -18
- package/bin/services/rest/restService.d.ts +0 -4
- package/bin/services/rest/restService.js +0 -72
- package/bin/services/rest/restService.types.d.ts +0 -6
- package/bin/services/rest/restService.types.js +0 -2
- package/bin/wallet/index.d.ts +0 -6
- package/bin/wallet/index.js +0 -22
- package/bin/wallet/key/index.d.ts +0 -1
- package/bin/wallet/key/index.js +0 -17
- package/bin/wallet/key/key.d.ts +0 -21
- package/bin/wallet/key/key.js +0 -102
- package/bin/wallet/key/key.test.d.ts +0 -1
- package/bin/wallet/key/key.test.js +0 -121
- package/bin/wallet/ledger/index.d.ts +0 -1
- package/bin/wallet/ledger/index.js +0 -17
- package/bin/wallet/ledger/ledger.d.ts +0 -22
- package/bin/wallet/ledger/ledger.js +0 -109
- package/bin/wallet/signer.d.ts +0 -29
- package/bin/wallet/signer.js +0 -2
- package/bin/wallet/types/index.d.ts +0 -2
- package/bin/wallet/types/index.js +0 -18
- package/bin/wallet/types/sign.d.ts +0 -16
- package/bin/wallet/types/sign.js +0 -4
- package/bin/wallet/types/wallet.d.ts +0 -5
- package/bin/wallet/types/wallet.js +0 -2
- package/bin/wallet/utility/index.d.ts +0 -1
- package/bin/wallet/utility/index.js +0 -17
- package/bin/wallet/utility/utility.d.ts +0 -36
- package/bin/wallet/utility/utility.js +0 -117
- package/bin/wallet/wallet.d.ts +0 -106
- package/bin/wallet/wallet.js +0 -361
- package/bin/wallet/wallet.test.d.ts +0 -1
- package/bin/wallet/wallet.test.js +0 -423
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/wallet/types/sign.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The transaction payload that is signed to generate
|
|
4
|
+
* a valid transaction signature
|
|
5
|
+
*/
|
|
6
|
+
interface TxSignPayload {
|
|
7
|
+
chain_id: string;
|
|
8
|
+
account_number: string;
|
|
9
|
+
sequence: string;
|
|
10
|
+
fee: {
|
|
11
|
+
gas_fee: string;
|
|
12
|
+
gas_wanted: string;
|
|
13
|
+
};
|
|
14
|
+
msgs: any[];
|
|
15
|
+
memo: string;
|
|
16
|
+
}
|
|
17
|
+
declare const Secp256k1PubKeyType = "/tm.PubKeySecp256k1";
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Secp256k1PubKeyType, TxSignPayload };
|
|
20
|
+
//# sourceMappingURL=sign.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.cts","names":[],"sources":["../../../src/wallet/types/sign.ts"],"mappings":";;AAIA;;;UAAiB,aAAA;EAEf,QAAA;EAGA,cAAA;EAGA,QAAA;EAEA,GAAA;IAGE,OAAA;IAEA,UAAA;EAAA;EASF,IAAA;EAEA,IAAA;AAAA;AAAA,cAGW,mBAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/wallet/types/sign.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The transaction payload that is signed to generate
|
|
4
|
+
* a valid transaction signature
|
|
5
|
+
*/
|
|
6
|
+
interface TxSignPayload {
|
|
7
|
+
chain_id: string;
|
|
8
|
+
account_number: string;
|
|
9
|
+
sequence: string;
|
|
10
|
+
fee: {
|
|
11
|
+
gas_fee: string;
|
|
12
|
+
gas_wanted: string;
|
|
13
|
+
};
|
|
14
|
+
msgs: any[];
|
|
15
|
+
memo: string;
|
|
16
|
+
}
|
|
17
|
+
declare const Secp256k1PubKeyType = "/tm.PubKeySecp256k1";
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Secp256k1PubKeyType, TxSignPayload };
|
|
20
|
+
//# sourceMappingURL=sign.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.mts","names":[],"sources":["../../../src/wallet/types/sign.ts"],"mappings":";;AAIA;;;UAAiB,aAAA;EAEf,QAAA;EAGA,cAAA;EAGA,QAAA;EAEA,GAAA;IAGE,OAAA;IAEA,UAAA;EAAA;EASF,IAAA;EAEA,IAAA;AAAA;AAAA,cAGW,mBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.mjs","names":[],"sources":["../../../src/wallet/types/sign.ts"],"sourcesContent":["/**\n * The transaction payload that is signed to generate\n * a valid transaction signature\n */\nexport interface TxSignPayload {\n // the ID of the chain\n chain_id: string\n // the account number of the\n // account that's signing (decimal)\n account_number: string\n // the sequence number of the\n // account that's signing (decimal)\n sequence: string\n // the fee of the transaction\n fee: {\n // gas price of the transaction\n // in the format <amount (decimal)><denomination>\n gas_fee: string\n // gas limit of the transaction (decimal)\n gas_wanted: string\n }\n // the messages associated\n // with the transaction.\n // These messages have the form: \\\n // @type: ...\n // value: ...\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n msgs: any[]\n // the transaction memo\n memo: string\n}\n\nexport const Secp256k1PubKeyType = \"/tm.PubKeySecp256k1\";\n"],"mappings":";AAiCA,MAAa,sBAAsB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/wallet/types/wallet.d.ts
|
|
2
|
+
interface CreateWalletOptions {
|
|
3
|
+
addressPrefix?: string;
|
|
4
|
+
accountIndex?: number;
|
|
5
|
+
}
|
|
6
|
+
type AccountWalletOption = Pick<CreateWalletOptions, "addressPrefix">;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { AccountWalletOption, CreateWalletOptions };
|
|
9
|
+
//# sourceMappingURL=wallet.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.cts","names":[],"sources":["../../../src/wallet/types/wallet.ts"],"mappings":";UAAiB,mBAAA;EAEf,aAAA;EAEA,YAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,IAAA,CAAK,mBAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/wallet/types/wallet.d.ts
|
|
2
|
+
interface CreateWalletOptions {
|
|
3
|
+
addressPrefix?: string;
|
|
4
|
+
accountIndex?: number;
|
|
5
|
+
}
|
|
6
|
+
type AccountWalletOption = Pick<CreateWalletOptions, "addressPrefix">;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { AccountWalletOption, CreateWalletOptions };
|
|
9
|
+
//# sourceMappingURL=wallet.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.mts","names":[],"sources":["../../../src/wallet/types/wallet.ts"],"mappings":";UAAiB,mBAAA;EAEf,aAAA;EAEA,YAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,IAAA,CAAK,mBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./utility.cjs");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { defaultAddressPrefix, encodeCharacterSet, generateEntropy, generateHDPath, generateKeyPair, sortedJsonStringify, stringToUTF8 } from "./utility.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { defaultAddressPrefix, encodeCharacterSet, generateEntropy, generateHDPath, generateKeyPair, sortedJsonStringify, stringToUTF8 } from "./utility.mjs";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _cosmjs_crypto = require("@cosmjs/crypto");
|
|
3
|
+
let crypto = require("crypto");
|
|
4
|
+
crypto = require_runtime.__toESM(crypto);
|
|
5
|
+
//#region src/wallet/utility/utility.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',
|
|
8
|
+
* where 'i' is the account index
|
|
9
|
+
* @param {number} [index=0] the account index
|
|
10
|
+
*/
|
|
11
|
+
const generateHDPath = (index) => {
|
|
12
|
+
return [
|
|
13
|
+
_cosmjs_crypto.Slip10RawIndex.hardened(44),
|
|
14
|
+
_cosmjs_crypto.Slip10RawIndex.hardened(118),
|
|
15
|
+
_cosmjs_crypto.Slip10RawIndex.hardened(0),
|
|
16
|
+
_cosmjs_crypto.Slip10RawIndex.normal(0),
|
|
17
|
+
_cosmjs_crypto.Slip10RawIndex.normal(index ? index : 0)
|
|
18
|
+
];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Generates random entropy of the specified size (in B)
|
|
22
|
+
* @param {number} [size=32] the entropy size in bytes
|
|
23
|
+
*/
|
|
24
|
+
const generateEntropy = (size) => {
|
|
25
|
+
const array = new Uint8Array(size ? size : 32);
|
|
26
|
+
crypto.default.randomFillSync(array);
|
|
27
|
+
return array;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Generates a new Secp256k1 key-pair using
|
|
31
|
+
* the provided English mnemonic and account index
|
|
32
|
+
* @param {string} mnemonic the English mnemonic
|
|
33
|
+
* @param {number} [accountIndex=0] the account index
|
|
34
|
+
*/
|
|
35
|
+
const generateKeyPair = async (mnemonic, accountIndex) => {
|
|
36
|
+
const seed = await _cosmjs_crypto.Bip39.mnemonicToSeed(new _cosmjs_crypto.EnglishMnemonic(mnemonic));
|
|
37
|
+
const { privkey: privateKey } = _cosmjs_crypto.Slip10.derivePath(_cosmjs_crypto.Slip10Curve.Secp256k1, seed, generateHDPath(accountIndex));
|
|
38
|
+
const { pubkey: publicKey } = await _cosmjs_crypto.Secp256k1.makeKeypair(privateKey);
|
|
39
|
+
return {
|
|
40
|
+
publicKey,
|
|
41
|
+
privateKey
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const defaultAddressPrefix = "g";
|
|
45
|
+
/**
|
|
46
|
+
* Encodes a string into a Uint8Array
|
|
47
|
+
* @param {string} str the string to be encoded
|
|
48
|
+
*/
|
|
49
|
+
const stringToUTF8 = (str) => {
|
|
50
|
+
return new TextEncoder().encode(str);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Escapes <,>,& in string.
|
|
54
|
+
* Golang's json marshaller escapes <,>,& by default.
|
|
55
|
+
* https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53
|
|
56
|
+
*/
|
|
57
|
+
function encodeCharacterSet(data) {
|
|
58
|
+
return data.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
59
|
+
}
|
|
60
|
+
function sortedObject(obj) {
|
|
61
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
62
|
+
if (Array.isArray(obj)) return obj.map(sortedObject);
|
|
63
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
64
|
+
const result = {};
|
|
65
|
+
sortedKeys.forEach((key) => {
|
|
66
|
+
result[key] = sortedObject(obj[key]);
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
/** Returns a JSON string with objects sorted by key */
|
|
71
|
+
function sortedJsonStringify(obj) {
|
|
72
|
+
return JSON.stringify(sortedObject(obj));
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.defaultAddressPrefix = defaultAddressPrefix;
|
|
76
|
+
exports.encodeCharacterSet = encodeCharacterSet;
|
|
77
|
+
exports.generateEntropy = generateEntropy;
|
|
78
|
+
exports.generateHDPath = generateHDPath;
|
|
79
|
+
exports.generateKeyPair = generateKeyPair;
|
|
80
|
+
exports.sortedJsonStringify = sortedJsonStringify;
|
|
81
|
+
exports.stringToUTF8 = stringToUTF8;
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=utility.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.cjs","names":["Slip10RawIndex","Bip39","EnglishMnemonic","Slip10","Slip10Curve","Secp256k1"],"sources":["../../../src/wallet/utility/utility.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n Bip39,\n EnglishMnemonic,\n HdPath,\n Secp256k1,\n Slip10,\n Slip10Curve,\n Slip10RawIndex,\n} from \"@cosmjs/crypto\";\nimport crypto from \"crypto\";\n\n/**\n * Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',\n * where 'i' is the account index\n * @param {number} [index=0] the account index\n */\nexport const generateHDPath = (index?: number): HdPath => {\n return [Slip10RawIndex.hardened(44), Slip10RawIndex.hardened(118), Slip10RawIndex.hardened(0), Slip10RawIndex.normal(0), Slip10RawIndex.normal(index ? index : 0)];\n};\n\n/**\n * Generates random entropy of the specified size (in B)\n * @param {number} [size=32] the entropy size in bytes\n */\nexport const generateEntropy = (size?: number): Uint8Array => {\n const array = new Uint8Array(size ? size : 32);\n\n // Generate random data\n crypto.randomFillSync(array);\n\n return array;\n};\n\ninterface keyPair {\n privateKey: Uint8Array\n publicKey: Uint8Array\n}\n\n/**\n * Generates a new Secp256k1 key-pair using\n * the provided English mnemonic and account index\n * @param {string} mnemonic the English mnemonic\n * @param {number} [accountIndex=0] the account index\n */\nexport const generateKeyPair = async (\n mnemonic: string,\n accountIndex?: number,\n): Promise<keyPair> => {\n // Generate the seed\n const seed = await Bip39.mnemonicToSeed(new EnglishMnemonic(mnemonic));\n\n // Derive the private key\n const {\n privkey: privateKey,\n } = Slip10.derivePath(\n Slip10Curve.Secp256k1,\n seed,\n generateHDPath(accountIndex),\n );\n\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n return {\n publicKey: publicKey,\n privateKey: privateKey,\n };\n};\n\n// Address prefix for TM2 networks\nexport const defaultAddressPrefix = \"g\";\n\n/**\n * Encodes a string into a Uint8Array\n * @param {string} str the string to be encoded\n */\nexport const stringToUTF8 = (str: string): Uint8Array => {\n return new TextEncoder().encode(str);\n};\n\n/**\n * Escapes <,>,& in string.\n * Golang's json marshaller escapes <,>,& by default.\n * https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53\n */\nexport function encodeCharacterSet(data: string) {\n return data\n .replace(/</g, \"\\\\u003c\")\n .replace(/>/g, \"\\\\u003e\")\n .replace(/&/g, \"\\\\u0026\");\n}\n\nfunction sortedObject(obj: any): any {\n if (typeof obj !== \"object\" || obj === null) {\n return obj;\n }\n if (Array.isArray(obj)) {\n return obj.map(sortedObject);\n }\n const sortedKeys = Object.keys(obj).sort();\n const result: Record<string, any> = {\n };\n // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code\n sortedKeys.forEach((key) => {\n result[key] = sortedObject(obj[key]);\n });\n return result;\n}\n\n/** Returns a JSON string with objects sorted by key */\n\nexport function sortedJsonStringify(obj: any): string {\n return JSON.stringify(sortedObject(obj));\n}\n"],"mappings":";;;;;;;;;;AAiBA,MAAa,kBAAkB,UAA2B;AACxD,QAAO;EAACA,eAAAA,eAAe,SAAS,GAAG;EAAEA,eAAAA,eAAe,SAAS,IAAI;EAAEA,eAAAA,eAAe,SAAS,EAAE;EAAEA,eAAAA,eAAe,OAAO,EAAE;EAAEA,eAAAA,eAAe,OAAO,QAAQ,QAAQ,EAAE;EAAC;;;;;;AAOpK,MAAa,mBAAmB,SAA8B;CAC5D,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO,GAAG;AAG9C,QAAA,QAAO,eAAe,MAAM;AAE5B,QAAO;;;;;;;;AAcT,MAAa,kBAAkB,OAC7B,UACA,iBACqB;CAErB,MAAM,OAAO,MAAMC,eAAAA,MAAM,eAAe,IAAIC,eAAAA,gBAAgB,SAAS,CAAC;CAGtE,MAAM,EACJ,SAAS,eACPC,eAAAA,OAAO,WACTC,eAAAA,YAAY,WACZ,MACA,eAAe,aAAa,CAC7B;CAGD,MAAM,EACJ,QAAQ,cACN,MAAMC,eAAAA,UAAU,YAAY,WAAW;AAE3C,QAAO;EACM;EACC;EACb;;AAIH,MAAa,uBAAuB;;;;;AAMpC,MAAa,gBAAgB,QAA4B;AACvD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;AAQtC,SAAgB,mBAAmB,MAAc;AAC/C,QAAO,KACJ,QAAQ,MAAM,UAAU,CACxB,QAAQ,MAAM,UAAU,CACxB,QAAQ,MAAM,UAAU;;AAG7B,SAAS,aAAa,KAAe;AACnC,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;AAET,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,aAAa;CAE9B,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,MAAM;CAC1C,MAAM,SAA8B,EACnC;AAED,YAAW,SAAS,QAAQ;AAC1B,SAAO,OAAO,aAAa,IAAI,KAAK;GACpC;AACF,QAAO;;;AAKT,SAAgB,oBAAoB,KAAkB;AACpD,QAAO,KAAK,UAAU,aAAa,IAAI,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HdPath } from "@cosmjs/crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/wallet/utility/utility.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',
|
|
6
|
+
* where 'i' is the account index
|
|
7
|
+
* @param {number} [index=0] the account index
|
|
8
|
+
*/
|
|
9
|
+
declare const generateHDPath: (index?: number) => HdPath;
|
|
10
|
+
/**
|
|
11
|
+
* Generates random entropy of the specified size (in B)
|
|
12
|
+
* @param {number} [size=32] the entropy size in bytes
|
|
13
|
+
*/
|
|
14
|
+
declare const generateEntropy: (size?: number) => Uint8Array;
|
|
15
|
+
interface keyPair {
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
publicKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generates a new Secp256k1 key-pair using
|
|
21
|
+
* the provided English mnemonic and account index
|
|
22
|
+
* @param {string} mnemonic the English mnemonic
|
|
23
|
+
* @param {number} [accountIndex=0] the account index
|
|
24
|
+
*/
|
|
25
|
+
declare const generateKeyPair: (mnemonic: string, accountIndex?: number) => Promise<keyPair>;
|
|
26
|
+
declare const defaultAddressPrefix = "g";
|
|
27
|
+
/**
|
|
28
|
+
* Encodes a string into a Uint8Array
|
|
29
|
+
* @param {string} str the string to be encoded
|
|
30
|
+
*/
|
|
31
|
+
declare const stringToUTF8: (str: string) => Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Escapes <,>,& in string.
|
|
34
|
+
* Golang's json marshaller escapes <,>,& by default.
|
|
35
|
+
* https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53
|
|
36
|
+
*/
|
|
37
|
+
declare function encodeCharacterSet(data: string): string;
|
|
38
|
+
/** Returns a JSON string with objects sorted by key */
|
|
39
|
+
declare function sortedJsonStringify(obj: any): string;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { defaultAddressPrefix, encodeCharacterSet, generateEntropy, generateHDPath, generateKeyPair, sortedJsonStringify, stringToUTF8 };
|
|
42
|
+
//# sourceMappingURL=utility.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.d.cts","names":[],"sources":["../../../src/wallet/utility/utility.ts"],"mappings":";;;;;AAiBA;;;cAAa,cAAA,GAAkB,KAAA,cAAiB,MAAA;;AAQhD;;;cAAa,eAAA,GAAmB,IAAA,cAAgB,UAAA;AAAA,UAStC,OAAA;EACR,UAAA,EAAY,UAAA;EACZ,SAAA,EAAW,UAAA;AAAA;;;;;;;cASA,eAAA,GACX,QAAA,UACA,YAAA,cACC,OAAA,CAAQ,OAAA;AAAA,cAyBE,oBAAA;;;;;cAMA,YAAA,GAAgB,GAAA,aAAc,UAAA;;;;;AAN3C;iBAegB,kBAAA,CAAmB,IAAA;;iBA0BnB,mBAAA,CAAoB,GAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HdPath } from "@cosmjs/crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/wallet/utility/utility.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',
|
|
6
|
+
* where 'i' is the account index
|
|
7
|
+
* @param {number} [index=0] the account index
|
|
8
|
+
*/
|
|
9
|
+
declare const generateHDPath: (index?: number) => HdPath;
|
|
10
|
+
/**
|
|
11
|
+
* Generates random entropy of the specified size (in B)
|
|
12
|
+
* @param {number} [size=32] the entropy size in bytes
|
|
13
|
+
*/
|
|
14
|
+
declare const generateEntropy: (size?: number) => Uint8Array;
|
|
15
|
+
interface keyPair {
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
publicKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generates a new Secp256k1 key-pair using
|
|
21
|
+
* the provided English mnemonic and account index
|
|
22
|
+
* @param {string} mnemonic the English mnemonic
|
|
23
|
+
* @param {number} [accountIndex=0] the account index
|
|
24
|
+
*/
|
|
25
|
+
declare const generateKeyPair: (mnemonic: string, accountIndex?: number) => Promise<keyPair>;
|
|
26
|
+
declare const defaultAddressPrefix = "g";
|
|
27
|
+
/**
|
|
28
|
+
* Encodes a string into a Uint8Array
|
|
29
|
+
* @param {string} str the string to be encoded
|
|
30
|
+
*/
|
|
31
|
+
declare const stringToUTF8: (str: string) => Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Escapes <,>,& in string.
|
|
34
|
+
* Golang's json marshaller escapes <,>,& by default.
|
|
35
|
+
* https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53
|
|
36
|
+
*/
|
|
37
|
+
declare function encodeCharacterSet(data: string): string;
|
|
38
|
+
/** Returns a JSON string with objects sorted by key */
|
|
39
|
+
declare function sortedJsonStringify(obj: any): string;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { defaultAddressPrefix, encodeCharacterSet, generateEntropy, generateHDPath, generateKeyPair, sortedJsonStringify, stringToUTF8 };
|
|
42
|
+
//# sourceMappingURL=utility.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.d.mts","names":[],"sources":["../../../src/wallet/utility/utility.ts"],"mappings":";;;;;AAiBA;;;cAAa,cAAA,GAAkB,KAAA,cAAiB,MAAA;;AAQhD;;;cAAa,eAAA,GAAmB,IAAA,cAAgB,UAAA;AAAA,UAStC,OAAA;EACR,UAAA,EAAY,UAAA;EACZ,SAAA,EAAW,UAAA;AAAA;;;;;;;cASA,eAAA,GACX,QAAA,UACA,YAAA,cACC,OAAA,CAAQ,OAAA;AAAA,cAyBE,oBAAA;;;;;cAMA,YAAA,GAAgB,GAAA,aAAc,UAAA;;;;;AAN3C;iBAegB,kBAAA,CAAmB,IAAA;;iBA0BnB,mBAAA,CAAoB,GAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Bip39, EnglishMnemonic, Secp256k1, Slip10, Slip10Curve, Slip10RawIndex } from "@cosmjs/crypto";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
//#region src/wallet/utility/utility.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',
|
|
6
|
+
* where 'i' is the account index
|
|
7
|
+
* @param {number} [index=0] the account index
|
|
8
|
+
*/
|
|
9
|
+
const generateHDPath = (index) => {
|
|
10
|
+
return [
|
|
11
|
+
Slip10RawIndex.hardened(44),
|
|
12
|
+
Slip10RawIndex.hardened(118),
|
|
13
|
+
Slip10RawIndex.hardened(0),
|
|
14
|
+
Slip10RawIndex.normal(0),
|
|
15
|
+
Slip10RawIndex.normal(index ? index : 0)
|
|
16
|
+
];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Generates random entropy of the specified size (in B)
|
|
20
|
+
* @param {number} [size=32] the entropy size in bytes
|
|
21
|
+
*/
|
|
22
|
+
const generateEntropy = (size) => {
|
|
23
|
+
const array = new Uint8Array(size ? size : 32);
|
|
24
|
+
crypto.randomFillSync(array);
|
|
25
|
+
return array;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Generates a new Secp256k1 key-pair using
|
|
29
|
+
* the provided English mnemonic and account index
|
|
30
|
+
* @param {string} mnemonic the English mnemonic
|
|
31
|
+
* @param {number} [accountIndex=0] the account index
|
|
32
|
+
*/
|
|
33
|
+
const generateKeyPair = async (mnemonic, accountIndex) => {
|
|
34
|
+
const seed = await Bip39.mnemonicToSeed(new EnglishMnemonic(mnemonic));
|
|
35
|
+
const { privkey: privateKey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, generateHDPath(accountIndex));
|
|
36
|
+
const { pubkey: publicKey } = await Secp256k1.makeKeypair(privateKey);
|
|
37
|
+
return {
|
|
38
|
+
publicKey,
|
|
39
|
+
privateKey
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const defaultAddressPrefix = "g";
|
|
43
|
+
/**
|
|
44
|
+
* Encodes a string into a Uint8Array
|
|
45
|
+
* @param {string} str the string to be encoded
|
|
46
|
+
*/
|
|
47
|
+
const stringToUTF8 = (str) => {
|
|
48
|
+
return new TextEncoder().encode(str);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Escapes <,>,& in string.
|
|
52
|
+
* Golang's json marshaller escapes <,>,& by default.
|
|
53
|
+
* https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53
|
|
54
|
+
*/
|
|
55
|
+
function encodeCharacterSet(data) {
|
|
56
|
+
return data.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
57
|
+
}
|
|
58
|
+
function sortedObject(obj) {
|
|
59
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
60
|
+
if (Array.isArray(obj)) return obj.map(sortedObject);
|
|
61
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
62
|
+
const result = {};
|
|
63
|
+
sortedKeys.forEach((key) => {
|
|
64
|
+
result[key] = sortedObject(obj[key]);
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/** Returns a JSON string with objects sorted by key */
|
|
69
|
+
function sortedJsonStringify(obj) {
|
|
70
|
+
return JSON.stringify(sortedObject(obj));
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { defaultAddressPrefix, encodeCharacterSet, generateEntropy, generateHDPath, generateKeyPair, sortedJsonStringify, stringToUTF8 };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=utility.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.mjs","names":[],"sources":["../../../src/wallet/utility/utility.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n Bip39,\n EnglishMnemonic,\n HdPath,\n Secp256k1,\n Slip10,\n Slip10Curve,\n Slip10RawIndex,\n} from \"@cosmjs/crypto\";\nimport crypto from \"crypto\";\n\n/**\n * Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',\n * where 'i' is the account index\n * @param {number} [index=0] the account index\n */\nexport const generateHDPath = (index?: number): HdPath => {\n return [Slip10RawIndex.hardened(44), Slip10RawIndex.hardened(118), Slip10RawIndex.hardened(0), Slip10RawIndex.normal(0), Slip10RawIndex.normal(index ? index : 0)];\n};\n\n/**\n * Generates random entropy of the specified size (in B)\n * @param {number} [size=32] the entropy size in bytes\n */\nexport const generateEntropy = (size?: number): Uint8Array => {\n const array = new Uint8Array(size ? size : 32);\n\n // Generate random data\n crypto.randomFillSync(array);\n\n return array;\n};\n\ninterface keyPair {\n privateKey: Uint8Array\n publicKey: Uint8Array\n}\n\n/**\n * Generates a new Secp256k1 key-pair using\n * the provided English mnemonic and account index\n * @param {string} mnemonic the English mnemonic\n * @param {number} [accountIndex=0] the account index\n */\nexport const generateKeyPair = async (\n mnemonic: string,\n accountIndex?: number,\n): Promise<keyPair> => {\n // Generate the seed\n const seed = await Bip39.mnemonicToSeed(new EnglishMnemonic(mnemonic));\n\n // Derive the private key\n const {\n privkey: privateKey,\n } = Slip10.derivePath(\n Slip10Curve.Secp256k1,\n seed,\n generateHDPath(accountIndex),\n );\n\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n return {\n publicKey: publicKey,\n privateKey: privateKey,\n };\n};\n\n// Address prefix for TM2 networks\nexport const defaultAddressPrefix = \"g\";\n\n/**\n * Encodes a string into a Uint8Array\n * @param {string} str the string to be encoded\n */\nexport const stringToUTF8 = (str: string): Uint8Array => {\n return new TextEncoder().encode(str);\n};\n\n/**\n * Escapes <,>,& in string.\n * Golang's json marshaller escapes <,>,& by default.\n * https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/encoding/json/encode.go;l=46-53\n */\nexport function encodeCharacterSet(data: string) {\n return data\n .replace(/</g, \"\\\\u003c\")\n .replace(/>/g, \"\\\\u003e\")\n .replace(/&/g, \"\\\\u0026\");\n}\n\nfunction sortedObject(obj: any): any {\n if (typeof obj !== \"object\" || obj === null) {\n return obj;\n }\n if (Array.isArray(obj)) {\n return obj.map(sortedObject);\n }\n const sortedKeys = Object.keys(obj).sort();\n const result: Record<string, any> = {\n };\n // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code\n sortedKeys.forEach((key) => {\n result[key] = sortedObject(obj[key]);\n });\n return result;\n}\n\n/** Returns a JSON string with objects sorted by key */\n\nexport function sortedJsonStringify(obj: any): string {\n return JSON.stringify(sortedObject(obj));\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,kBAAkB,UAA2B;AACxD,QAAO;EAAC,eAAe,SAAS,GAAG;EAAE,eAAe,SAAS,IAAI;EAAE,eAAe,SAAS,EAAE;EAAE,eAAe,OAAO,EAAE;EAAE,eAAe,OAAO,QAAQ,QAAQ,EAAE;EAAC;;;;;;AAOpK,MAAa,mBAAmB,SAA8B;CAC5D,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO,GAAG;AAG9C,QAAO,eAAe,MAAM;AAE5B,QAAO;;;;;;;;AAcT,MAAa,kBAAkB,OAC7B,UACA,iBACqB;CAErB,MAAM,OAAO,MAAM,MAAM,eAAe,IAAI,gBAAgB,SAAS,CAAC;CAGtE,MAAM,EACJ,SAAS,eACP,OAAO,WACT,YAAY,WACZ,MACA,eAAe,aAAa,CAC7B;CAGD,MAAM,EACJ,QAAQ,cACN,MAAM,UAAU,YAAY,WAAW;AAE3C,QAAO;EACM;EACC;EACb;;AAIH,MAAa,uBAAuB;;;;;AAMpC,MAAa,gBAAgB,QAA4B;AACvD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;AAQtC,SAAgB,mBAAmB,MAAc;AAC/C,QAAO,KACJ,QAAQ,MAAM,UAAU,CACxB,QAAQ,MAAM,UAAU,CACxB,QAAQ,MAAM,UAAU;;AAG7B,SAAS,aAAa,KAAe;AACnC,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;AAET,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,aAAa;CAE9B,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,MAAM;CAC1C,MAAM,SAA8B,EACnC;AAED,YAAW,SAAS,QAAQ;AAC1B,SAAO,OAAO,aAAa,IAAI,KAAK;GACpC;AACF,QAAO;;;AAKT,SAAgB,oBAAoB,KAAkB;AACpD,QAAO,KAAK,UAAU,aAAa,IAAI,CAAC"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_tx = require("../proto/tm2/tx.cjs");
|
|
3
|
+
require("../proto/index.cjs");
|
|
4
|
+
const require_defineProperty = require("../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.cjs");
|
|
5
|
+
const require_requests_utility = require("../provider/utility/requests.utility.cjs");
|
|
6
|
+
require("../provider/index.cjs");
|
|
7
|
+
const require_utility = require("./utility/utility.cjs");
|
|
8
|
+
require("./utility/index.cjs");
|
|
9
|
+
const require_key = require("./key/key.cjs");
|
|
10
|
+
require("./key/index.cjs");
|
|
11
|
+
const require_ledger = require("./ledger/ledger.cjs");
|
|
12
|
+
require("./ledger/index.cjs");
|
|
13
|
+
const require_sign = require("./types/sign.cjs");
|
|
14
|
+
let _cosmjs_crypto = require("@cosmjs/crypto");
|
|
15
|
+
//#region src/wallet/wallet.ts
|
|
16
|
+
var _Wallet;
|
|
17
|
+
/**
|
|
18
|
+
* Wallet is a single account abstraction
|
|
19
|
+
* that can interact with the blockchain
|
|
20
|
+
*/
|
|
21
|
+
var Wallet = class {
|
|
22
|
+
constructor() {
|
|
23
|
+
require_defineProperty._defineProperty(
|
|
24
|
+
this,
|
|
25
|
+
/**
|
|
26
|
+
* Connects the wallet to the specified {@link Provider}
|
|
27
|
+
* @param {Provider} provider the active {@link Provider}, if any
|
|
28
|
+
*/
|
|
29
|
+
"connect",
|
|
30
|
+
(provider) => {
|
|
31
|
+
this.provider = provider;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
require_defineProperty._defineProperty(
|
|
35
|
+
this,
|
|
36
|
+
/**
|
|
37
|
+
* Fetches the address associated with the wallet
|
|
38
|
+
*/
|
|
39
|
+
"getAddress",
|
|
40
|
+
() => {
|
|
41
|
+
return this.signer.getAddress();
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
require_defineProperty._defineProperty(
|
|
45
|
+
this,
|
|
46
|
+
/**
|
|
47
|
+
* Fetches the account sequence for the wallet
|
|
48
|
+
* @param {number} [height=latest] the block height
|
|
49
|
+
*/
|
|
50
|
+
"getAccountSequence",
|
|
51
|
+
async (height) => {
|
|
52
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
53
|
+
const address = await this.getAddress();
|
|
54
|
+
return this.provider.getAccountSequence(address, height);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
require_defineProperty._defineProperty(
|
|
58
|
+
this,
|
|
59
|
+
/**
|
|
60
|
+
* Fetches the account number for the wallet. Errors out if the
|
|
61
|
+
* account is not initialized
|
|
62
|
+
* @param {number} [height=latest] the block height
|
|
63
|
+
*/
|
|
64
|
+
"getAccountNumber",
|
|
65
|
+
async (height) => {
|
|
66
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
67
|
+
const address = await this.getAddress();
|
|
68
|
+
return this.provider.getAccountNumber(address, height);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
require_defineProperty._defineProperty(
|
|
72
|
+
this,
|
|
73
|
+
/**
|
|
74
|
+
* Fetches the account balance for the specific denomination
|
|
75
|
+
* @param {string} [denomination=ugnot] the fund denomination
|
|
76
|
+
*/
|
|
77
|
+
"getBalance",
|
|
78
|
+
async (denomination) => {
|
|
79
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
80
|
+
const address = await this.getAddress();
|
|
81
|
+
return this.provider.getBalance(address, denomination ? denomination : "ugnot");
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
require_defineProperty._defineProperty(
|
|
85
|
+
this,
|
|
86
|
+
/**
|
|
87
|
+
* Fetches the current (recommended) average gas price
|
|
88
|
+
*/
|
|
89
|
+
"getGasPrice",
|
|
90
|
+
async () => {
|
|
91
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
92
|
+
return this.provider.getGasPrice();
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
require_defineProperty._defineProperty(
|
|
96
|
+
this,
|
|
97
|
+
/**
|
|
98
|
+
* Estimates the gas limit for the transaction
|
|
99
|
+
* @param {Tx} tx the transaction that needs estimating
|
|
100
|
+
*/
|
|
101
|
+
"estimateGas",
|
|
102
|
+
async (tx) => {
|
|
103
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
104
|
+
return this.provider.estimateGas(tx);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
require_defineProperty._defineProperty(
|
|
108
|
+
this,
|
|
109
|
+
/**
|
|
110
|
+
* Returns the connected provider, if any
|
|
111
|
+
*/
|
|
112
|
+
"getProvider",
|
|
113
|
+
() => {
|
|
114
|
+
return this.provider;
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
require_defineProperty._defineProperty(
|
|
118
|
+
this,
|
|
119
|
+
/**
|
|
120
|
+
* Generates a transaction signature, and appends it to the transaction
|
|
121
|
+
* @param {Tx} tx the transaction to be signed
|
|
122
|
+
* @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback
|
|
123
|
+
* that should expand the concrete message fields into an object. Required because
|
|
124
|
+
* the transaction sign bytes are generated using sorted JSON, which requires
|
|
125
|
+
* encoded message values to be decoded for sorting
|
|
126
|
+
*/
|
|
127
|
+
"signTransaction",
|
|
128
|
+
async (tx, decodeTxMessages, opts) => {
|
|
129
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
130
|
+
if (!tx.fee) throw new Error("invalid transaction fee provided");
|
|
131
|
+
const chainID = (await this.provider.getStatus()).node_info.network;
|
|
132
|
+
let accountNumber = opts?.accountNumber;
|
|
133
|
+
let accountSequence = opts?.sequence;
|
|
134
|
+
if (accountNumber === void 0 || accountSequence === void 0) {
|
|
135
|
+
const address = await this.getAddress();
|
|
136
|
+
const account = await this.provider.getAccount(address);
|
|
137
|
+
if (accountNumber === void 0) accountNumber = account.BaseAccount.account_number;
|
|
138
|
+
if (accountSequence === void 0) accountSequence = account.BaseAccount.sequence;
|
|
139
|
+
}
|
|
140
|
+
const publicKey = await this.signer.getPublicKey();
|
|
141
|
+
const signBytes = require_utility.stringToUTF8(require_utility.encodeCharacterSet(require_utility.sortedJsonStringify({
|
|
142
|
+
chain_id: chainID,
|
|
143
|
+
account_number: accountNumber,
|
|
144
|
+
sequence: accountSequence,
|
|
145
|
+
fee: {
|
|
146
|
+
gas_fee: tx.fee.gas_fee,
|
|
147
|
+
gas_wanted: tx.fee.gas_wanted.toString(10)
|
|
148
|
+
},
|
|
149
|
+
msgs: decodeTxMessages(tx.messages),
|
|
150
|
+
memo: tx.memo
|
|
151
|
+
})));
|
|
152
|
+
const wrappedKey = { key: publicKey };
|
|
153
|
+
const txSignature = {
|
|
154
|
+
pub_key: {
|
|
155
|
+
type_url: require_sign.Secp256k1PubKeyType,
|
|
156
|
+
value: require_tx.PubKeySecp256k1.encode(wrappedKey).finish()
|
|
157
|
+
},
|
|
158
|
+
signature: await this.getSigner().signData(signBytes)
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
...tx,
|
|
162
|
+
signatures: [...tx.signatures, txSignature]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
require_defineProperty._defineProperty(
|
|
167
|
+
this,
|
|
168
|
+
/**
|
|
169
|
+
* Returns the associated signer
|
|
170
|
+
*/
|
|
171
|
+
"getSigner",
|
|
172
|
+
() => {
|
|
173
|
+
return this.signer;
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Encodes and sends the transaction. If the type of endpoint
|
|
179
|
+
* is a broadcast commit, waits for the transaction to be committed to the chain.
|
|
180
|
+
* The transaction needs to be signed beforehand.
|
|
181
|
+
* Returns the transaction hash (base-64)
|
|
182
|
+
* @param {Tx} tx the signed transaction
|
|
183
|
+
* @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)
|
|
184
|
+
*/
|
|
185
|
+
async sendTransaction(tx, endpoint) {
|
|
186
|
+
if (!this.provider) throw new Error("provider not connected");
|
|
187
|
+
const encodedTx = require_requests_utility.uint8ArrayToBase64(require_tx.Tx.encode(tx).finish());
|
|
188
|
+
return this.provider.sendTransaction(encodedTx, endpoint);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
_Wallet = Wallet;
|
|
192
|
+
require_defineProperty._defineProperty(Wallet, "createRandom", async (options) => {
|
|
193
|
+
const { publicKey, privateKey } = await require_utility.generateKeyPair(_cosmjs_crypto.Bip39.encode(require_utility.generateEntropy()).toString(), 0);
|
|
194
|
+
const wallet = new _Wallet();
|
|
195
|
+
wallet.signer = new require_key.KeySigner(privateKey, _cosmjs_crypto.Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
|
|
196
|
+
return wallet;
|
|
197
|
+
});
|
|
198
|
+
require_defineProperty._defineProperty(Wallet, "fromSigner", async (signer) => {
|
|
199
|
+
const wallet = new _Wallet();
|
|
200
|
+
wallet.signer = signer;
|
|
201
|
+
return wallet;
|
|
202
|
+
});
|
|
203
|
+
require_defineProperty._defineProperty(Wallet, "fromMnemonic", async (mnemonic, options) => {
|
|
204
|
+
const { publicKey, privateKey } = await require_utility.generateKeyPair(mnemonic, options?.accountIndex);
|
|
205
|
+
const wallet = new _Wallet();
|
|
206
|
+
wallet.signer = new require_key.KeySigner(privateKey, _cosmjs_crypto.Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
|
|
207
|
+
return wallet;
|
|
208
|
+
});
|
|
209
|
+
require_defineProperty._defineProperty(Wallet, "fromPrivateKey", async (privateKey, options) => {
|
|
210
|
+
const { pubkey: publicKey } = await _cosmjs_crypto.Secp256k1.makeKeypair(privateKey);
|
|
211
|
+
const wallet = new _Wallet();
|
|
212
|
+
wallet.signer = new require_key.KeySigner(privateKey, _cosmjs_crypto.Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
|
|
213
|
+
return wallet;
|
|
214
|
+
});
|
|
215
|
+
require_defineProperty._defineProperty(Wallet, "fromLedger", (connector, options) => {
|
|
216
|
+
const wallet = new _Wallet();
|
|
217
|
+
wallet.signer = new require_ledger.LedgerSigner(connector, options?.accountIndex ?? 0, options?.addressPrefix);
|
|
218
|
+
return wallet;
|
|
219
|
+
});
|
|
220
|
+
//#endregion
|
|
221
|
+
exports.Wallet = Wallet;
|
|
222
|
+
|
|
223
|
+
//# sourceMappingURL=wallet.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.cjs","names":["stringToUTF8","encodeCharacterSet","sortedJsonStringify","Secp256k1PubKeyType","PubKeySecp256k1","uint8ArrayToBase64","Tx","generateKeyPair","Bip39","generateEntropy","Wallet","KeySigner","Secp256k1","LedgerSigner"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\n\n /**\n * Returns the associated signer\n */\n getSigner = (): Signer => {\n return this.signer;\n };\n}\n"],"mappings":"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"}
|