@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-big.mjs","names":["JsonBig","BigNumber","mapObject","jsonBig","storeAsString","convertValuesToBigNumbers","value","constructor","Object","
|
|
1
|
+
{"version":3,"file":"json-big.mjs","names":["JsonBig","BigNumber","mapObject","jsonBig","storeAsString","convertValuesToBigNumbers","value","constructor","Object","k","v","Array","isArray","map","item","toString","bn","toJSON","stringify","args","slice","parse"],"sources":["../../src/utils/json-big.ts"],"sourcesContent":["import JsonBig from 'json-bigint';\nimport BigNumber from 'bignumber.js';\nimport { mapObject } from './other';\n\nconst jsonBig = JsonBig({ storeAsString: true });\n\nconst convertValuesToBigNumbers = (value: any): any => {\n if (typeof value === 'object' && value !== null && value.constructor === Object) {\n return mapObject(value, ([k, v]) => [k, convertValuesToBigNumbers(v)]);\n }\n if (Array.isArray(value)) {\n return value.map((item) => convertValuesToBigNumbers(item));\n }\n if (typeof value === 'string' && new BigNumber(value).toString(10) === value) {\n const bn = new BigNumber(value);\n bn.toJSON = () => bn.toString(10);\n return bn;\n }\n return value;\n};\n\nexport default {\n stringify: (...args: Parameters<typeof JsonBig['stringify']>): string => (\n jsonBig.stringify(convertValuesToBigNumbers(args[0]), ...args.slice(1))\n ),\n parse: jsonBig.parse,\n};\n"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,aAApB;AACA,OAAOC,SAAP,MAAsB,cAAtB;SACSC,S;AAET,MAAMC,OAAO,GAAGH,OAAO,CAAC;EAAEI,aAAa,EAAE;AAAjB,CAAD,CAAvB;;AAEA,MAAMC,yBAAyB,GAAIC,KAAD,IAAqB;EACrD,IAAI,OAAOA,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,KAAK,IAAvC,IAA+CA,KAAK,CAACC,WAAN,KAAsBC,MAAzE,EAAiF;IAC/E,OAAON,SAAS,CAACI,KAAD,EAAQ;MAAA,IAAC,CAACG,CAAD,EAAIC,CAAJ,CAAD;MAAA,OAAY,CAACD,CAAD,EAAIJ,yBAAyB,CAACK,CAAD,CAA7B,CAAZ;IAAA,CAAR,CAAhB;EACD;;EACD,IAAIC,KAAK,CAACC,OAAN,CAAcN,KAAd,CAAJ,EAA0B;IACxB,OAAOA,KAAK,CAACO,GAAN,CAAWC,IAAD,IAAUT,yBAAyB,CAACS,IAAD,CAA7C,CAAP;EACD;;EACD,IAAI,OAAOR,KAAP,KAAiB,QAAjB,IAA6B,IAAIL,SAAJ,CAAcK,KAAd,EAAqBS,QAArB,CAA8B,EAA9B,MAAsCT,KAAvE,EAA8E;IAC5E,MAAMU,EAAE,GAAG,IAAIf,SAAJ,CAAcK,KAAd,CAAX;;IACAU,EAAE,CAACC,MAAH,GAAY,MAAMD,EAAE,CAACD,QAAH,CAAY,EAAZ,CAAlB;;IACA,OAAOC,EAAP;EACD;;EACD,OAAOV,KAAP;AACD,CAbD;;AAeA,eAAe;EACbY,SAAS,EAAE;IAAA,kCAAIC,IAAJ;MAAIA,IAAJ;IAAA;;IAAA,OACThB,OAAO,CAACe,SAAR,CAAkBb,yBAAyB,CAACc,IAAI,CAAC,CAAD,CAAL,CAA3C,EAAsD,GAAGA,IAAI,CAACC,KAAL,CAAW,CAAX,CAAzD,CADS;EAAA,CADE;EAIbC,KAAK,EAAElB,OAAO,CAACkB;AAJF,CAAf"}
|
package/es/utils/keystore.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import nacl from 'tweetnacl';
|
|
2
|
-
import { v4 as uuid } from '@aeternity/uuid';
|
|
2
|
+
import { v4 as uuid } from '@aeternity/uuid'; // js extension is required for mjs build
|
|
3
|
+
// eslint-disable-next-line import/extensions
|
|
4
|
+
|
|
3
5
|
import _aeternityArgon2BrowserDistArgon2BundledMinJs from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';
|
|
4
6
|
const {
|
|
5
7
|
ArgonType,
|
|
@@ -85,7 +87,7 @@ function decrypt(ciphertext, key, nonce) {
|
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
async function deriveKey(password, nonce, kdf, kdfParams) {
|
|
88
|
-
return
|
|
90
|
+
return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* Recover plaintext private key from secret-storage key object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","getAddressFromPriv","bytesToHex","hexToBytes","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","argon2id","pass","salt","params","memlimit_kib","mem","opslimit","time","hash","hashLen","type","ArgonType","Argon2id","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","res","open","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","ciphertext","deriveKey","password","kdfParams","recover","crypto","cipher_params","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl'
|
|
1
|
+
{"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","getAddressFromPriv","bytesToHex","hexToBytes","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","argon2id","pass","salt","params","memlimit_kib","mem","opslimit","time","hash","hashLen","type","ArgonType","Argon2id","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","res","open","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","ciphertext","deriveKey","password","kdfParams","recover","crypto","cipher_params","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { v4 as uuid } from '@aeternity/uuid';\n// js extension is required for mjs build\n// eslint-disable-next-line import/extensions\nimport { ArgonType, hash } from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';\nimport { getAddressFromPriv } from './crypto';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport { InvalidPasswordError } from './errors';\n\nconst DERIVED_KEY_FUNCTIONS = {\n async argon2id(\n pass: string | Uint8Array,\n salt: string | Uint8Array,\n params: Partial<Keystore['crypto']['kdf_params']>,\n ): Promise<Uint8Array> {\n const { memlimit_kib: mem, opslimit: time } = params;\n\n return (await hash({\n hashLen: 32,\n pass,\n salt,\n time,\n mem,\n type: ArgonType.Argon2id,\n })).hash;\n },\n};\n\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': {\n encrypt: nacl.secretbox,\n decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {\n const res = nacl.secretbox.open(...args);\n if (res == null) throw new InvalidPasswordError();\n return res;\n },\n },\n};\n\nexport interface Keystore {\n name: string;\n version: 1;\n public_key: string;\n id: string;\n crypto: {\n secret_type: 'ed25519';\n symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;\n ciphertext: string;\n cipher_params: {\n nonce: string;\n };\n kdf: keyof typeof DERIVED_KEY_FUNCTIONS;\n kdf_params: {\n memlimit_kib: number;\n opslimit: number;\n parallelism: number;\n salt: string;\n };\n };\n}\n\nconst CRYPTO_DEFAULTS = {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1,\n },\n} as const;\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @param plaintext - Data to be encrypted.\n * @param key - Secret key.\n * @param nonce - Randomly generated nonce.\n * @param algo - Encryption algorithm.\n * @returns Encrypted data.\n */\nfunction encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @param ciphertext - Data to be decrypted.\n * @param key - Secret key.\n * @param nonce - Nonce from key-object.\n * @param algo - Encryption algorithm.\n * @returns Decrypted data.\n */\nfunction decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @param password - User-supplied password.\n * @param nonce - Randomly generated nonce.\n * @param kdf - Key derivation function.\n * @param kdfParams - KDF parameters.\n * @returns Secret key derived from password.\n */\nasync function deriveKey(\n password: string | Uint8Array,\n nonce: string | Uint8Array,\n kdf: Keystore['crypto']['kdf'],\n kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,\n): Promise<Uint8Array> {\n return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @param password - Keystore object password.\n * @param keystore - Keystore object.\n * @returns Plaintext private key.\n */\nexport async function recover(\n password: string | Uint8Array,\n { crypto }: Keystore,\n): Promise<string> {\n const salt = hexToBytes(crypto.kdf_params.salt);\n return bytesToHex(decrypt(\n hexToBytes(crypto.ciphertext),\n await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),\n hexToBytes(crypto.cipher_params.nonce),\n crypto.symmetric_alg,\n ));\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @param name - Key name.\n * @param password - User-supplied password.\n * @param privateKey - Private key as hex-string or a Buffer.\n * @param nonce - Randomly generated 24byte nonce.\n * @param salt - Randomly generated 16byte salt.\n * @param options - Encryption parameters.\n * @param options.kdf - Key derivation function.\n * @param options.kdf_params - KDF parameters.\n */\nexport async function dump(\n name: string,\n password: string | Uint8Array,\n privateKey: string | Uint8Array,\n nonce: Uint8Array = nacl.randomBytes(24),\n salt: Uint8Array = nacl.randomBytes(16),\n options?: Partial<Keystore['crypto']>,\n): Promise<Keystore> {\n const opt = { ...CRYPTO_DEFAULTS, ...options };\n const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);\n const payload = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey;\n return {\n name,\n version: 1,\n public_key: getAddressFromPriv(payload),\n id: uuid(),\n crypto: {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: bytesToHex(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)),\n cipher_params: { nonce: bytesToHex(nonce) },\n kdf: opt.kdf,\n kdf_params: {\n ...opt.kdf_params,\n salt: bytesToHex(salt),\n },\n },\n };\n}\n"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,WAAjB;AACA,SAASC,EAAE,IAAIC,IAAf,QAA2B,iBAA3B,C,CACA;AACA;;AACA,0DAAgC,sDAAhC;;;;;SACSC,kB;SACAC,U,EAAYC,U;SACZC,oB;AAET,MAAMC,qBAAqB,GAAG;EAC5B,MAAMC,QAAN,CACEC,IADF,EAEEC,IAFF,EAGEC,MAHF,EAIuB;IACrB,MAAM;MAAEC,YAAY,EAAEC,GAAhB;MAAqBC,QAAQ,EAAEC;IAA/B,IAAwCJ,MAA9C;IAEA,OAAO,CAAC,MAAMK,IAAI,CAAC;MACjBC,OAAO,EAAE,EADQ;MAEjBR,IAFiB;MAGjBC,IAHiB;MAIjBK,IAJiB;MAKjBF,GALiB;MAMjBK,IAAI,EAAEC,SAAS,CAACC;IANC,CAAD,CAAX,EAOHJ,IAPJ;EAQD;;AAhB2B,CAA9B;AAmBA,MAAMK,gBAAgB,GAAG;EACvB,qBAAqB;IACnBC,OAAO,EAAEtB,IAAI,CAACuB,SADK;;IAEnBC,OAAO,GAA8D;MACnE,MAAMC,GAAG,GAAGzB,IAAI,CAACuB,SAAL,CAAeG,IAAf,CAAoB,YAApB,CAAZ;MACA,IAAID,GAAG,IAAI,IAAX,EAAiB,MAAM,IAAInB,oBAAJ,EAAN;MACjB,OAAOmB,GAAP;IACD;;EANkB;AADE,CAAzB;AAiCA,MAAME,eAAe,GAAG;EACtBC,WAAW,EAAE,SADS;EAEtBC,aAAa,EAAE,mBAFO;EAGtBC,GAAG,EAAE,UAHiB;EAItBC,UAAU,EAAE;IACVnB,YAAY,EAAE,KADJ;IAEVE,QAAQ,EAAE,CAFA;IAGVkB,WAAW,E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 -19,8 +19,8 @@ export default class MPTree {
|
|
|
19
19
|
serialize(): MPTreeBinary;
|
|
20
20
|
/**
|
|
21
21
|
* Retrieve value from Merkle Patricia Tree
|
|
22
|
-
* @param
|
|
22
|
+
* @param _key - The key of the element to retrieve
|
|
23
23
|
* @returns Value associated to the specified key
|
|
24
24
|
*/
|
|
25
|
-
get(
|
|
25
|
+
get(_key: string): Buffer | undefined;
|
|
26
26
|
}
|
package/es/utils/mptree.mjs
CHANGED
|
@@ -20,6 +20,8 @@ const {
|
|
|
20
20
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
21
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
22
22
|
*/
|
|
23
|
+
|
|
24
|
+
/* eslint-disable default-case */
|
|
23
25
|
import _rlp from 'rlp';
|
|
24
26
|
const {
|
|
25
27
|
encode: rlpEncode
|
|
@@ -92,7 +94,8 @@ export default class MPTree {
|
|
|
92
94
|
{
|
|
93
95
|
var _context;
|
|
94
96
|
|
|
95
|
-
const nibble = node[0][0] >> 4;
|
|
97
|
+
const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
|
|
98
|
+
|
|
96
99
|
if (nibble > 3) throw new UnknownPathNibbleError(nibble);
|
|
97
100
|
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
98
101
|
const slice = _includesInstanceProperty(_context = [0, 2]).call(_context, nibble) ? 2 : 1;
|
|
@@ -121,15 +124,17 @@ export default class MPTree {
|
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Retrieve value from Merkle Patricia Tree
|
|
124
|
-
* @param
|
|
127
|
+
* @param _key - The key of the element to retrieve
|
|
125
128
|
* @returns Value associated to the specified key
|
|
126
129
|
*/
|
|
127
130
|
|
|
128
131
|
|
|
129
|
-
get(
|
|
132
|
+
get(_key) {
|
|
130
133
|
let searchFrom = this.rootHash;
|
|
134
|
+
let key = _key;
|
|
131
135
|
|
|
132
136
|
while (true) {
|
|
137
|
+
// eslint-disable-line no-constant-condition
|
|
133
138
|
const {
|
|
134
139
|
type,
|
|
135
140
|
payload,
|
|
@@ -140,13 +145,13 @@ export default class MPTree {
|
|
|
140
145
|
case NodeType.Branch:
|
|
141
146
|
if (key.length === 0) return payload[16];
|
|
142
147
|
searchFrom = payload[+`0x${key[0]}`].toString('hex');
|
|
143
|
-
key = key.
|
|
148
|
+
key = key.substring(1);
|
|
144
149
|
break;
|
|
145
150
|
|
|
146
151
|
case NodeType.Extension:
|
|
147
|
-
if (key.
|
|
152
|
+
if (key.substring(0, path === null || path === void 0 ? void 0 : path.length) !== path) return undefined;
|
|
148
153
|
searchFrom = payload[0].toString('hex');
|
|
149
|
-
key = key.
|
|
154
|
+
key = key.substring(path.length);
|
|
150
155
|
break;
|
|
151
156
|
|
|
152
157
|
case NodeType.Leaf:
|
package/es/utils/mptree.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mptree.mjs","names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","Leaf","serialize","mptHash","value","get","searchFrom","
|
|
1
|
+
{"version":3,"file":"mptree.mjs","names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","Leaf","serialize","mptHash","value","get","_key","searchFrom","substring"],"sources":["../../src/utils/mptree.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/* eslint-disable default-case */\nimport { encode as rlpEncode } from 'rlp';\nimport type { Input } from 'rlp';\nimport { hash } from './crypto';\nimport {\n MerkleTreeHashMismatchError,\n MissingNodeInTreeError,\n UnknownPathNibbleError,\n UnknownNodeLengthError,\n} from './errors';\n\nenum NodeType {\n Branch,\n Extension,\n Leaf,\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];\n\nexport default class MPTree {\n private readonly rootHash: string;\n\n private readonly nodes: { [key: string]: Buffer[] };\n\n private static nodeHash(node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex');\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @param binary - Binary\n * @returns Merkle Patricia Tree\n */\n constructor(binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex');\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]]),\n );\n\n if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\\'t find a node by root hash');\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();\n const { type, payload } = MPTree.parseNode(node);\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter((n) => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in branch node');\n }\n });\n break;\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in extension node');\n }\n }\n });\n }\n\n isEqual(tree: MPTree): boolean {\n return this.rootHash === tree.rootHash;\n }\n\n private static parseNode(node: Buffer[]): {\n type: NodeType;\n payload: Buffer[];\n path: string | null;\n } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null };\n case 2: {\n const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise\n if (nibble > 3) throw new UnknownPathNibbleError(nibble);\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;\n const slice = [0, 2].includes(nibble) ? 2 : 1;\n return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };\n }\n default:\n throw new UnknownNodeLengthError(node.length);\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @returns Binary\n */\n serialize(): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value,\n ])),\n ];\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @param _key - The key of the element to retrieve\n * @returns Value associated to the specified key\n */\n get(_key: string): Buffer | undefined {\n let searchFrom = this.rootHash;\n let key = _key;\n while (true) { // eslint-disable-line no-constant-condition\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16];\n searchFrom = payload[+`0x${key[0]}`].toString('hex');\n key = key.substring(1);\n break;\n case NodeType.Extension:\n if (key.substring(0, path?.length) !== path) return undefined;\n searchFrom = payload[0].toString('hex');\n key = key.substring(path.length);\n break;\n case NodeType.Leaf:\n if (path !== key) return undefined;\n return payload[0];\n }\n }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AG,CAAC,CAAD,CAAI,EAAd,CAAP,CAAwBX,QAAxB,CAAiC,KAAjC,CAAb;UACAW,GAAG,GAAGA,GAAG,CAACqB,SAAJ,CAAc,CAAd,CAAN;UACA;;QACF,KAAKtC,QAAQ,CAAC0B,SAAd;UACE,IAAIT,GAAG,CAACqB,SAAJ,CAAc,CAAd,EAAiBT,IAAjB,aAAiBA,IAAjB,uBAAiBA,IAAI,CAAEJ,MAAvB,MAAmCI,IAAvC,EAA6C,OAAOf,SAAP;UAC7CuB,UAAU,GAAGlB,OAAO,CAAC,CAAD,CAAP,CAAWb,QAAX,CAAoB,KAApB,CAAb;UACAW,GAAG,GAAGA,GAAG,CAACqB,SAAJ,CAAcT,IAAI,CAACJ,MAAnB,CAAN;UACA;;QACF,KAAKzB,QAAQ,CAAC+B,IAAd;UACE,IAAIF,IAAI,KAAKZ,GAAb,EAAkB,OAAOH,SAAP;UAClB,OAAOK,OAAO,CAAC,CAAD,CAAd;MAbJ;IAeD;EACF;;AA3GyB"}
|
package/es/utils/other.d.ts
CHANGED
|
@@ -8,7 +8,13 @@ export declare const mapObject: <InputV, OutputV>(object: {
|
|
|
8
8
|
export declare const concatBuffers: (list: readonly Uint8Array[], totalLength?: number | undefined) => Buffer;
|
|
9
9
|
/**
|
|
10
10
|
* Object key type guard
|
|
11
|
-
* @param key -
|
|
12
|
-
* @param object -
|
|
11
|
+
* @param key - Maybe object key
|
|
12
|
+
* @param object - Object
|
|
13
13
|
*/
|
|
14
14
|
export declare function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T;
|
|
15
|
+
/**
|
|
16
|
+
* Array item type guard
|
|
17
|
+
* @param item - Maybe array item
|
|
18
|
+
* @param array - Array
|
|
19
|
+
*/
|
|
20
|
+
export declare function isItemOfArray<T>(item: any, array: readonly T[]): item is T;
|
package/es/utils/other.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import _buffer from "buffer";
|
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
3
|
const {
|
|
3
4
|
Buffer: _Buffer
|
|
4
5
|
} = _buffer;
|
|
5
|
-
export const pause = async duration =>
|
|
6
|
+
export const pause = async duration => new Promise(resolve => {
|
|
7
|
+
setTimeout(resolve, duration);
|
|
8
|
+
});
|
|
6
9
|
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn)); // remove after dropping webpack4 support
|
|
7
10
|
|
|
8
11
|
const isWebpack4Buffer = (() => {
|
|
@@ -18,11 +21,20 @@ const isWebpack4Buffer = (() => {
|
|
|
18
21
|
export const concatBuffers = isWebpack4Buffer ? (list, totalLength) => _Buffer.concat(list.map(el => _Buffer.from(el)), totalLength) : _Buffer.concat;
|
|
19
22
|
/**
|
|
20
23
|
* Object key type guard
|
|
21
|
-
* @param key -
|
|
22
|
-
* @param object -
|
|
24
|
+
* @param key - Maybe object key
|
|
25
|
+
* @param object - Object
|
|
23
26
|
*/
|
|
24
27
|
|
|
25
28
|
export function isKeyOfObject(key, object) {
|
|
26
29
|
return key in object;
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Array item type guard
|
|
33
|
+
* @param item - Maybe array item
|
|
34
|
+
* @param array - Array
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export function isItemOfArray(item, array) {
|
|
38
|
+
return _includesInstanceProperty(array).call(array, item);
|
|
39
|
+
}
|
|
28
40
|
//# sourceMappingURL=other.mjs.map
|
package/es/utils/other.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"other.mjs","names":["pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","isWebpack4Buffer","concat","Uint8Array","from","error","concatBuffers","list","totalLength","el","isKeyOfObject","key"],"sources":["../../src/utils/other.ts"],"sourcesContent":["export const pause = async (duration: number): Promise<void>
|
|
1
|
+
{"version":3,"file":"other.mjs","names":["pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","isWebpack4Buffer","concat","Uint8Array","from","error","concatBuffers","list","totalLength","el","isKeyOfObject","key","isItemOfArray","item","array"],"sources":["../../src/utils/other.ts"],"sourcesContent":["export const pause = async (duration: number): Promise<void> => new Promise((resolve) => {\n setTimeout(resolve, duration);\n});\n\nexport const mapObject = <InputV, OutputV>(\n object: { [k: string]: InputV },\n fn: (\n value: [string, InputV], index: number, array: Array<[string, InputV]>\n ) => [number | string, OutputV],\n): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn));\n\n// remove after dropping webpack4 support\nconst isWebpack4Buffer = (() => {\n try {\n Buffer.concat([Uint8Array.from([])]);\n return false;\n } catch (error) {\n return true;\n }\n})();\n\nexport const concatBuffers = isWebpack4Buffer\n ? (list: readonly Uint8Array[], totalLength?: number): Buffer => (\n Buffer.concat(list.map((el) => Buffer.from(el)), totalLength)\n )\n : Buffer.concat;\n\n/**\n * Object key type guard\n * @param key - Maybe object key\n * @param object - Object\n */\nexport function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T {\n return key in object;\n}\n\n/**\n * Array item type guard\n * @param item - Maybe array item\n * @param array - Array\n */\nexport function isItemOfArray<T>(item: any, array: readonly T[]): item is T {\n return array.includes(item);\n}\n"],"mappings":";;;;;AAAA,OAAO,MAAMA,KAAK,GAAG,MAAOC,QAAP,IAA2C,IAAIC,OAAJ,CAAaC,OAAD,IAAa;EACvFC,UAAU,CAACD,OAAD,EAAUF,QAAV,CAAV;AACD,CAF+D,CAAzD;AAIP,OAAO,MAAMI,SAAS,GAAG,CACvBC,MADuB,EAEvBC,EAFuB,KAKMC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBK,GAAvB,CAA2BJ,EAA3B,CAAnB,CALxB,C,CAOP;;AACA,MAAMK,gBAAgB,GAAG,CAAC,MAAM;EAC9B,IAAI;IACF,QAAOC,MAAP,CAAc,CAACC,UAAU,CAACC,IAAX,CAAgB,EAAhB,CAAD,CAAd;;IACA,OAAO,KAAP;EACD,CAHD,CAGE,OAAOC,KAAP,EAAc;IACd,OAAO,IAAP;EACD;AACF,CAPwB,GAAzB;;AASA,OAAO,MAAMC,aAAa,GAAGL,gBAAgB,GACzC,CAACM,IAAD,EAA8BC,WAA9B,KACA,QAAON,MAAP,CAAcK,IAAI,CAACP,GAAL,CAAUS,EAAD,IAAQ,QAAOL,IAAP,CAAYK,EAAZ,CAAjB,CAAd,EAAiDD,WAAjD,CAFyC,GAIzC,QAAON,MAJJ;AAMP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASQ,aAAT,CAA0BC,GAA1B,EAAyDhB,MAAzD,EAAoF;EACzF,OAAOgB,GAAG,IAAIhB,MAAd;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASiB,aAAT,CAA0BC,IAA1B,EAAqCC,KAArC,EAAqE;EAC1E,OAAO,0BAAAA,KAAK,MAAL,CAAAA,KAAK,EAAUD,IAAV,CAAZ;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function (version: string, geVersion: string, ltVersion: string): boolean;
|
|
1
|
+
export default function semverSatisfies(version: string, geVersion: string, ltVersion: string): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default function (version, geVersion, ltVersion) {
|
|
1
|
+
export default function semverSatisfies(version, geVersion, ltVersion) {
|
|
2
2
|
const getComponents = v => v.split(/[-+]/)[0].split('.').map(i => +i);
|
|
3
3
|
|
|
4
4
|
const versionComponents = getComponents(version);
|
|
@@ -6,7 +6,7 @@ export default function (version, geVersion, ltVersion) {
|
|
|
6
6
|
const ltComponents = getComponents(ltVersion);
|
|
7
7
|
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;
|
|
8
8
|
|
|
9
|
-
const componentsToNumber = components => components.reverse().reduce((acc, n, idx) => acc + n *
|
|
9
|
+
const componentsToNumber = components => components.reverse().reduce((acc, n, idx) => acc + n * base ** idx, 0);
|
|
10
10
|
|
|
11
11
|
const vNumber = componentsToNumber(versionComponents);
|
|
12
12
|
const geNumber = componentsToNumber(geComponents);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver-satisfies.mjs","names":["version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","
|
|
1
|
+
{"version":3,"file":"semver-satisfies.mjs","names":["semverSatisfies","version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","vNumber","geNumber","ltNumber"],"sources":["../../src/utils/semver-satisfies.ts"],"sourcesContent":["export default function semverSatisfies(\n version: string,\n geVersion: string,\n ltVersion: string,\n): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map((i) => +i);\n\n const versionComponents = getComponents(version);\n const geComponents = getComponents(geVersion);\n const ltComponents = getComponents(ltVersion);\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * base ** idx, 0);\n\n const vNumber = componentsToNumber(versionComponents);\n const geNumber = componentsToNumber(geComponents);\n const ltNumber = componentsToNumber(ltComponents);\n return vNumber >= geNumber && vNumber < ltNumber;\n}\n"],"mappings":"AAAA,eAAe,SAASA,eAAT,CACbC,OADa,EAEbC,SAFa,EAGbC,SAHa,EAIJ;EACT,MAAMC,aAAa,GAAIC,CAAD,IAAyBA,CAAC,CAC7CC,KAD4C,CACtC,MADsC,EAC9B,CAD8B,EAC3BA,KAD2B,CACrB,GADqB,EAChBC,GADgB,CACXC,CAAD,IAAO,CAACA,CADI,CAA/C;;EAGA,MAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAD,CAAvC;EACA,MAAMS,YAAY,GAAGN,aAAa,CAACF,SAAD,CAAlC;EACA,MAAMS,YAAY,GAAGP,aAAa,CAACD,SAAD,CAAlC;EAEA,MAAMS,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,GAAGL,iBAAZ,EAA+B,GAAGC,YAAlC,EAAgD,GAAGC,YAAnD,IAAmE,CAAhF;;EACA,MAAMI,kBAAkB,GAAIC,UAAD,IAAkCA,UAAU,CAACC,OAAX,GAC1DC,MAD0D,CACnD,CAACC,GAAD,EAAMC,CAAN,EAASC,GAAT,KAAiBF,GAAG,GAAGC,CAAC,GAAGR,IAAI,IAAIS,GADgB,EACX,CADW,CAA7D;;EAGA,MAAMC,OAAO,GAAGP,kBAAkB,CAACN,iBAAD,CAAlC;EACA,MAAMc,QAAQ,GAAGR,kBAAkB,CAACL,YAAD,CAAnC;EACA,MAAMc,QAAQ,GAAGT,kBAAkB,CAACJ,YAAD,CAAnC;EACA,OAAOW,OAAO,IAAIC,QAAX,IAAuBD,OAAO,GAAGE,QAAxC;AACD"}
|
package/es/utils/string.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.mjs","names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"sources":["../../src/utils/string.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @param s - String to convert\n * @returns Converted string\n */\nexport function snakeToPascal
|
|
1
|
+
{"version":3,"file":"string.mjs","names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"sources":["../../src/utils/string.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @param s - String to convert\n * @returns Converted string\n */\nexport function snakeToPascal(s: string): string {\n return s.replace(/_./g, (match) => match[1].toUpperCase());\n}\n\n/**\n * Convert string from PascalCase to snake_case\n * @param s - String to convert\n * @returns Converted string\n */\nexport function pascalToSnake(s: string): string {\n return s.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);\n}\n\n/**\n * Check whether a string is valid hex.\n * @param str - String to validate.\n * @returns True if the string is valid hex, false otherwise.\n */\nexport function isHex(str: string): boolean {\n return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str);\n}\n\n/**\n * Check whether a string is valid base-64.\n * @param str - String to validate.\n * @returns True if the string is valid base-64, false otherwise.\n */\nexport function isBase64(str: string): boolean {\n if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false;\n const index = str.indexOf('=');\n return index === -1 || /={1,2}/.test(str.slice(index));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAT,CAAuBC,CAAvB,EAA0C;EAC/C,OAAOA,CAAC,CAACC,OAAF,CAAU,KAAV,EAAkBC,KAAD,IAAWA,KAAK,CAAC,CAAD,CAAL,CAASC,WAAT,EAA5B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAuBJ,CAAvB,EAA0C;EAC/C,OAAOA,CAAC,CAACC,OAAF,CAAU,QAAV,EAAqBC,KAAD,IAAY,IAAGA,KAAK,CAACG,WAAN,EAAoB,EAAvD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,CAAeC,GAAf,EAAqC;EAC1C,OAAOA,GAAG,CAACC,MAAJ,GAAa,CAAb,KAAmB,CAAnB,IAAwB,eAAeC,IAAf,CAAoBF,GAApB,CAA/B;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,QAAT,CAAkBH,GAAlB,EAAwC;EAC7C,IAAIA,GAAG,CAACC,MAAJ,GAAa,CAAb,GAAiB,CAAjB,IAAsB,gBAAgBC,IAAhB,CAAqBF,GAArB,CAA1B,EAAqD,OAAO,KAAP;EACrD,MAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAJ,CAAY,GAAZ,CAAd;EACA,OAAOD,KAAK,KAAK,CAAC,CAAX,IAAgB,SAASF,IAAT,CAAcF,GAAG,CAACM,KAAJ,CAAUF,KAAV,CAAd,CAAvB;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeternity/aepp-sdk",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.2",
|
|
4
4
|
"description": "SDK for the æternity blockchain",
|
|
5
5
|
"main": "dist/aepp-sdk.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
"build:dev": "webpack --mode=development && npm run build:es",
|
|
17
17
|
"docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.js",
|
|
18
18
|
"docs:api": "typedoc",
|
|
19
|
-
"
|
|
19
|
+
"commitlint": "commitlint --from develop",
|
|
20
|
+
"lint": "eslint . --ext .ts,.js,.mjs",
|
|
21
|
+
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
20
22
|
"test": "nyc mocha './test/unit/' './test/integration/'",
|
|
21
23
|
"test:integration": "nyc mocha './test/integration/'",
|
|
22
24
|
"test:unit": "nyc mocha './test/unit/'",
|
|
@@ -33,12 +35,19 @@
|
|
|
33
35
|
"SDK"
|
|
34
36
|
],
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@aeternity/aepp-calldata": "^1.
|
|
38
|
+
"@aeternity/aepp-calldata": "^1.2.0",
|
|
37
39
|
"@aeternity/argon2-browser": "^0.1.2",
|
|
38
40
|
"@aeternity/uuid": "^0.0.1",
|
|
39
|
-
"@azure/core-client": "
|
|
41
|
+
"@azure/core-client": "1.6.0",
|
|
40
42
|
"@azure/core-rest-pipeline": "^1.9.0",
|
|
41
|
-
"@babel/runtime-corejs3": "^7.18.
|
|
43
|
+
"@babel/runtime-corejs3": "^7.18.9",
|
|
44
|
+
"@types/aes-js": "^3.1.1",
|
|
45
|
+
"@types/argon2-browser": "^1.18.1",
|
|
46
|
+
"@types/json-bigint": "^1.0.1",
|
|
47
|
+
"@types/sha.js": "^2.4.0",
|
|
48
|
+
"@types/uuid": "^8.3.4",
|
|
49
|
+
"@types/webextension-polyfill": "^0.9.0",
|
|
50
|
+
"@types/websocket": "^1.0.5",
|
|
42
51
|
"aes-js": "^3.1.2",
|
|
43
52
|
"bignumber.js": "^9.0.2",
|
|
44
53
|
"bip32-path": "^0.4.2",
|
|
@@ -60,38 +69,31 @@
|
|
|
60
69
|
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
61
70
|
},
|
|
62
71
|
"devDependencies": {
|
|
63
|
-
"@babel/cli": "^7.
|
|
64
|
-
"@babel/core": "^7.18.
|
|
65
|
-
"@babel/node": "^7.
|
|
66
|
-
"@babel/plugin-transform-runtime": "^7.18.
|
|
67
|
-
"@babel/preset-env": "^7.18.
|
|
68
|
-
"@babel/preset-typescript": "^7.
|
|
69
|
-
"@babel/register": "^7.
|
|
70
|
-
"@commitlint/cli": "^17.0.
|
|
71
|
-
"@commitlint/config-conventional": "^17.0.
|
|
72
|
-
"@types/aes-js": "^3.1.1",
|
|
73
|
-
"@types/argon2-browser": "^1.18.1",
|
|
74
|
-
"@types/bn.js": "^5.1.0",
|
|
72
|
+
"@babel/cli": "^7.18.9",
|
|
73
|
+
"@babel/core": "^7.18.9",
|
|
74
|
+
"@babel/node": "^7.18.9",
|
|
75
|
+
"@babel/plugin-transform-runtime": "^7.18.9",
|
|
76
|
+
"@babel/preset-env": "^7.18.9",
|
|
77
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
78
|
+
"@babel/register": "^7.18.9",
|
|
79
|
+
"@commitlint/cli": "^17.0.3",
|
|
80
|
+
"@commitlint/config-conventional": "^17.0.3",
|
|
75
81
|
"@types/chai": "^4.3.1",
|
|
76
82
|
"@types/chai-as-promised": "^7.1.5",
|
|
77
|
-
"@types/json-bigint": "^1.0.1",
|
|
78
83
|
"@types/mocha": "^9.1.1",
|
|
79
|
-
"@types/
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@types/uuid": "^8.3.4",
|
|
83
|
-
"@types/webextension-polyfill": "^0.9.0",
|
|
84
|
-
"@types/websocket": "^1.0.5",
|
|
85
|
-
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
86
|
-
"@typescript-eslint/parser": "^5.27.1",
|
|
84
|
+
"@types/sinon": "^10.0.13",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
86
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
87
87
|
"babel-loader": "^8.2.5",
|
|
88
88
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
89
89
|
"babel-plugin-import-globals": "^2.0.0",
|
|
90
90
|
"babel-plugin-transform-default-named-imports": "^1.2.2",
|
|
91
91
|
"chai": "^4.3.6",
|
|
92
92
|
"chai-as-promised": "^7.1.1",
|
|
93
|
-
"
|
|
94
|
-
"eslint
|
|
93
|
+
"codecov": "^3.8.3",
|
|
94
|
+
"eslint": "^8.20.0",
|
|
95
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
96
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
95
97
|
"eslint-plugin-rulesdir": "^0.2.1",
|
|
96
98
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
97
99
|
"mocha": "^10.0.0",
|
|
@@ -99,13 +101,13 @@
|
|
|
99
101
|
"sinon": "^14.0.0",
|
|
100
102
|
"source-map": "^0.7.4",
|
|
101
103
|
"standard-version": "^9.5.0",
|
|
102
|
-
"ts-node": "^10.
|
|
103
|
-
"typedoc": "^0.
|
|
104
|
-
"typedoc-plugin-missing-exports": "^0.
|
|
105
|
-
"typescript": "^4.7.
|
|
106
|
-
"webpack": "^5.
|
|
104
|
+
"ts-node": "^10.9.1",
|
|
105
|
+
"typedoc": "^0.23.9",
|
|
106
|
+
"typedoc-plugin-missing-exports": "^0.23.0",
|
|
107
|
+
"typescript": "^4.7.4",
|
|
108
|
+
"webpack": "^5.74.0",
|
|
107
109
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
108
|
-
"webpack-cli": "^4.
|
|
110
|
+
"webpack-cli": "^4.10.0"
|
|
109
111
|
},
|
|
110
112
|
"files": [
|
|
111
113
|
"dist",
|
package/src/AeSdk.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import AeSdkBase, { Account } from './AeSdkBase'
|
|
2
|
-
import AccountBase from './account/Base'
|
|
3
|
-
import { decode,
|
|
4
|
-
import { UnavailableAccountError } from './utils/errors'
|
|
1
|
+
import AeSdkBase, { Account } from './AeSdkBase';
|
|
2
|
+
import AccountBase from './account/Base';
|
|
3
|
+
import { decode, Encoded } from './utils/encoder';
|
|
4
|
+
import { UnavailableAccountError } from './utils/errors';
|
|
5
5
|
|
|
6
6
|
export default class AeSdk extends AeSdkBase {
|
|
7
|
-
accounts: { [key:
|
|
8
|
-
selectedAddress?: EncodedData<'ak'>
|
|
7
|
+
accounts: { [key: Encoded.AccountAddress]: AccountBase } = {};
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
selectedAddress?: Encoded.AccountAddress;
|
|
10
|
+
|
|
11
|
+
_resolveAccount(
|
|
12
|
+
account: Account | Encoded.AccountAddress = this.selectedAddress,
|
|
13
|
+
): AccountBase {
|
|
11
14
|
if (typeof account === 'string') {
|
|
12
|
-
const address = account as
|
|
13
|
-
decode(address)
|
|
14
|
-
if (this.accounts[address] == null) throw new UnavailableAccountError(account)
|
|
15
|
-
account = this.accounts[address]
|
|
15
|
+
const address = account as Encoded.AccountAddress;
|
|
16
|
+
decode(address);
|
|
17
|
+
if (this.accounts[address] == null) throw new UnavailableAccountError(account);
|
|
18
|
+
account = this.accounts[address];
|
|
16
19
|
}
|
|
17
|
-
return super._resolveAccount(account)
|
|
20
|
+
return super._resolveAccount(account);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Get accounts addresses
|
|
22
25
|
* @example addresses()
|
|
23
26
|
*/
|
|
24
|
-
addresses
|
|
25
|
-
return Object.keys(this.accounts) as
|
|
27
|
+
addresses(): Encoded.AccountAddress[] {
|
|
28
|
+
return Object.keys(this.accounts) as Encoded.AccountAddress[];
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -32,10 +35,10 @@ export default class AeSdk extends AeSdkBase {
|
|
|
32
35
|
* @param options.select - Select account
|
|
33
36
|
* @example addAccount(account)
|
|
34
37
|
*/
|
|
35
|
-
async addAccount
|
|
36
|
-
const address = await account.address()
|
|
37
|
-
this.accounts[address] = account
|
|
38
|
-
if (select === true) this.selectAccount(address)
|
|
38
|
+
async addAccount(account: AccountBase, { select }: { select?: boolean } = {}): Promise<void> {
|
|
39
|
+
const address = await account.address();
|
|
40
|
+
this.accounts[address] = account;
|
|
41
|
+
if (select === true) this.selectAccount(address);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -43,13 +46,13 @@ export default class AeSdk extends AeSdkBase {
|
|
|
43
46
|
* @param address - Address of account to remove
|
|
44
47
|
* @example removeAccount(address)
|
|
45
48
|
*/
|
|
46
|
-
removeAccount
|
|
49
|
+
removeAccount(address: Encoded.AccountAddress): void {
|
|
47
50
|
if (this.accounts[address] == null) {
|
|
48
|
-
console.warn(`removeAccount: Account for ${address} not available`)
|
|
49
|
-
return
|
|
51
|
+
console.warn(`removeAccount: Account for ${address} not available`);
|
|
52
|
+
return;
|
|
50
53
|
}
|
|
51
|
-
delete this.accounts[address] // eslint-disable-line @typescript-eslint/no-dynamic-delete
|
|
52
|
-
if (this.selectedAddress === address) delete this.selectedAddress
|
|
54
|
+
delete this.accounts[address]; // eslint-disable-line @typescript-eslint/no-dynamic-delete
|
|
55
|
+
if (this.selectedAddress === address) delete this.selectedAddress;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/**
|
|
@@ -57,9 +60,9 @@ export default class AeSdk extends AeSdkBase {
|
|
|
57
60
|
* @param address - Address of account to select
|
|
58
61
|
* @example selectAccount('ak_xxxxxxxx')
|
|
59
62
|
*/
|
|
60
|
-
selectAccount
|
|
61
|
-
decode(address)
|
|
62
|
-
if (this.accounts[address] == null) throw new UnavailableAccountError(address)
|
|
63
|
-
this.selectedAddress = address
|
|
63
|
+
selectAccount(address: Encoded.AccountAddress): void {
|
|
64
|
+
decode(address);
|
|
65
|
+
if (this.accounts[address] == null) throw new UnavailableAccountError(address);
|
|
66
|
+
this.selectedAddress = address;
|
|
64
67
|
}
|
|
65
68
|
}
|