@aeternity/aepp-sdk 10.0.0 → 12.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/LICENSE +1 -1
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +69 -0
- package/es/AeSdkAepp.mjs +175 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +212 -0
- package/es/AeSdkBase.mjs +310 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +103 -0
- package/es/AeSdkWallet.mjs +322 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +44 -0
- package/es/Node.mjs +141 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +65 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +25 -0
- package/es/account/Memory.mjs +81 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +79 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +209 -0
- package/es/aens.mjs +332 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +118 -0
- package/es/aepp-wallet-communication/schema.mjs +214 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1061 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4164 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +220 -0
- package/es/chain.mjs +524 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/{handlers.js → handlers.mjs} +163 -130
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +978 -0
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +328 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/Compiler.d.ts +17 -0
- package/es/contract/Compiler.mjs +67 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +125 -0
- package/es/contract/aci.mjs +496 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/ga.d.ts +68 -0
- package/es/contract/ga.mjs +190 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +68 -0
- package/es/contract/methods.mjs +101 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/index.d.ts +32 -0
- package/es/index.mjs +49 -0
- package/es/index.mjs.map +1 -0
- package/es/oracle.d.ts +154 -0
- package/es/oracle.mjs +288 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +61 -0
- package/es/spend.mjs +122 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +41 -0
- package/es/tx/builder/constants.mjs +100 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +126 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +223 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +424 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +320 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +209 -0
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/min-fee.d.ts +20 -0
- package/es/tx/min-fee.mjs +148 -0
- package/es/tx/min-fee.mjs.map +1 -0
- package/es/tx/validator.d.ts +19 -0
- package/es/tx/validator.mjs +240 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +23 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/{bytes.js → bytes.mjs} +26 -22
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +221 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +102 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.d.ts +481 -0
- package/es/utils/errors.mjs +882 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +122 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +41 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +145 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/{mptree.js → mptree.mjs} +33 -25
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +28 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/string.d.ts +24 -0
- package/es/utils/{string.js → string.mjs} +9 -11
- package/es/utils/string.mjs.map +1 -0
- package/package.json +67 -64
- package/src/AeSdk.ts +65 -0
- package/src/AeSdkAepp.ts +167 -0
- package/src/AeSdkBase.ts +320 -0
- package/src/AeSdkWallet.ts +332 -0
- package/src/Node.ts +167 -0
- package/src/account/Base.ts +114 -0
- package/src/account/Memory.ts +83 -0
- package/src/account/Rpc.ts +67 -0
- package/src/aens.ts +391 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
- package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +181 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10046 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1253 -0
- package/src/apis/node/models/mappers.ts +4278 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +444 -0
- package/src/channel/{handlers.js → handlers.ts} +238 -143
- package/src/channel/index.ts +991 -0
- package/src/channel/internal.ts +345 -0
- package/src/contract/Compiler.ts +66 -0
- package/src/contract/aci.ts +529 -0
- package/src/contract/ga.ts +178 -0
- package/src/contract/methods.ts +118 -0
- package/src/index.ts +51 -0
- package/src/oracle.ts +342 -0
- package/src/spend.ts +152 -0
- package/src/tx/builder/constants.ts +96 -0
- package/src/tx/builder/field-types.ts +111 -0
- package/src/tx/builder/helpers.ts +253 -0
- package/src/tx/builder/index.ts +394 -0
- package/src/tx/builder/schema.ts +771 -0
- package/src/tx/index.ts +199 -0
- package/src/tx/min-fee.ts +136 -0
- package/src/tx/validator.ts +226 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +3 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +29 -41
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -19
- package/src/utils/bytes.ts +15 -16
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +98 -0
- package/src/utils/errors.ts +817 -0
- package/src/utils/hd-wallet.ts +134 -0
- package/src/utils/json-big.ts +26 -0
- package/src/utils/keystore.ts +179 -0
- package/src/utils/mptree.ts +26 -20
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/CHANGELOG.md +0 -1603
- package/es/account/base.js +0 -169
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -84
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -178
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -408
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js +0 -45
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -312
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -206
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -322
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js +0 -45
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js +0 -50
- package/es/ae/wallet.js.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -24
- package/es/chain/index.js +0 -256
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -394
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js +0 -980
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -266
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -361
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -244
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -170
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -162
- package/es/contract/index.js.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -187
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -132
- package/es/node.js.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/builder/helpers.js +0 -305
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -595
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -814
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js +0 -300
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -276
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -937
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -208
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/typings/blakejs/index.d.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -103
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -67
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -28
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -304
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -112
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -45
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -228
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -43
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -132
- package/es/utils/swagger.js.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -78
- package/src/account/multiple.js +0 -154
- package/src/ae/aens.js +0 -366
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -285
- package/src/ae/index.js +0 -167
- package/src/ae/oracle.js +0 -296
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -250
- package/src/chain/node.js +0 -293
- package/src/channel/index.js +0 -898
- package/src/channel/internal.js +0 -231
- package/src/contract/aci/index.js +0 -317
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/compiler.js +0 -195
- package/src/contract/ga/helpers.js +0 -17
- package/src/contract/ga/index.js +0 -147
- package/src/contract/index.js +0 -163
- package/src/index.js +0 -90
- package/src/node-pool/index.js +0 -171
- package/src/node.js +0 -118
- package/src/tx/builder/helpers.js +0 -325
- package/src/tx/builder/index.js +0 -460
- package/src/tx/builder/schema.js +0 -1211
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -186
- package/src/tx/tx.js +0 -622
- package/src/tx/validator.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
- package/src/utils/aepp-wallet-communication/helpers.js +0 -70
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
- package/src/utils/async-init.js +0 -41
- package/src/utils/crypto.js +0 -312
- package/src/utils/hd-wallet.js +0 -115
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -223
- package/src/utils/swagger.js +0 -133
package/src/utils/crypto.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright 2018 aeternity developers
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
* copyright notice and this permission notice appear in all copies.
|
|
8
|
-
*
|
|
9
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Crypto module
|
|
20
|
-
* @module @aeternity/aepp-sdk/es/utils/crypto
|
|
21
|
-
* @example import { Crypto } from '@aeternity/aepp-sdk'
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import bs58check from 'bs58check'
|
|
25
|
-
import nacl from 'tweetnacl'
|
|
26
|
-
import aesjs from 'aes-js'
|
|
27
|
-
import shajs from 'sha.js'
|
|
28
|
-
|
|
29
|
-
import { str2buf, toBytes } from './bytes'
|
|
30
|
-
import { decode } from '../tx/builder/helpers'
|
|
31
|
-
import { hash } from './crypto-ts'
|
|
32
|
-
|
|
33
|
-
export * from './crypto-ts'
|
|
34
|
-
|
|
35
|
-
const Ecb = aesjs.ModeOfOperation.ecb
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Generate address from secret key
|
|
39
|
-
* @rtype (secret: String) => tx: Promise[String]
|
|
40
|
-
* @param {String} secret - Private key
|
|
41
|
-
* @return {String} Public key
|
|
42
|
-
*/
|
|
43
|
-
export function getAddressFromPriv (secret) {
|
|
44
|
-
const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))
|
|
45
|
-
const publicBuffer = Buffer.from(keys.publicKey)
|
|
46
|
-
return `ak_${encodeBase58Check(publicBuffer)}`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if address is valid
|
|
51
|
-
* @rtype (input: String) => valid: Boolean
|
|
52
|
-
* @param {String} address - Address
|
|
53
|
-
* @param {String} prefix Transaction prefix. Default: 'ak'
|
|
54
|
-
* @return {Boolean} valid
|
|
55
|
-
*/
|
|
56
|
-
export function isAddressValid (address, prefix = 'ak') {
|
|
57
|
-
if (typeof address !== 'string') return false
|
|
58
|
-
try {
|
|
59
|
-
return decode(address, prefix).length === 32
|
|
60
|
-
} catch (e) {
|
|
61
|
-
return false
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Parse decimal address and return base58Check encoded address with prefix 'ak'
|
|
67
|
-
* @rtype (input: String) => address: String
|
|
68
|
-
* @param {String} decimalAddress - Address
|
|
69
|
-
* @return {String} address
|
|
70
|
-
*/
|
|
71
|
-
export function addressFromDecimal (decimalAddress) {
|
|
72
|
-
return aeEncodeKey(toBytes(decimalAddress, true))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Calculate SHA256 hash of `input`
|
|
77
|
-
* @rtype (input: String) => hash: String
|
|
78
|
-
* @param {String} input - Data to hash
|
|
79
|
-
* @return {String} Hash
|
|
80
|
-
*/
|
|
81
|
-
export function sha256hash (input) {
|
|
82
|
-
return shajs('sha256').update(input).digest()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Generate a random salt (positive integer)
|
|
87
|
-
* @rtype () => salt: Number
|
|
88
|
-
* @return {Number} random salt
|
|
89
|
-
*/
|
|
90
|
-
export function salt () {
|
|
91
|
-
return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Base64check encode given `input`
|
|
96
|
-
* @rtype (input: String|buffer) => Buffer
|
|
97
|
-
* @param {String} input - Data to encode
|
|
98
|
-
* @return {Buffer} Base64check encoded data
|
|
99
|
-
*/
|
|
100
|
-
export function encodeBase64Check (input) {
|
|
101
|
-
const buffer = Buffer.from(input)
|
|
102
|
-
const checksum = checkSumFn(input)
|
|
103
|
-
const payloadWithChecksum = Buffer.concat([buffer, checksum], buffer.length + 4)
|
|
104
|
-
return payloadWithChecksum.toString('base64')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function checkSumFn (payload) {
|
|
108
|
-
return sha256hash(sha256hash(payload)).slice(0, 4)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function decodeRaw (buffer) {
|
|
112
|
-
const payload = buffer.slice(0, -4)
|
|
113
|
-
const checksum = buffer.slice(-4)
|
|
114
|
-
const newChecksum = checkSumFn(payload)
|
|
115
|
-
|
|
116
|
-
if (!checksum.equals(newChecksum)) return
|
|
117
|
-
|
|
118
|
-
return payload
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Base64check decode given `str`
|
|
123
|
-
* @rtype (str: String) => Buffer
|
|
124
|
-
* @param {String} str - Data to decode
|
|
125
|
-
* @return {Buffer} Base64check decoded data
|
|
126
|
-
*/
|
|
127
|
-
export function decodeBase64Check (str) {
|
|
128
|
-
const buffer = Buffer.from(str, 'base64')
|
|
129
|
-
const payload = decodeRaw(buffer)
|
|
130
|
-
if (!payload) throw new Error('Invalid checksum')
|
|
131
|
-
return Buffer.from(payload)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Base58 encode given `input`
|
|
136
|
-
* @rtype (input: String) => String
|
|
137
|
-
* @param {String|Buffer} input - Data to encode
|
|
138
|
-
* @return {String} Base58 encoded data
|
|
139
|
-
*/
|
|
140
|
-
export function encodeBase58Check (input) {
|
|
141
|
-
return bs58check.encode(Buffer.from(input))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Base58 decode given `str`
|
|
146
|
-
* @rtype (str: String) => Buffer
|
|
147
|
-
* @param {String} str - Data to decode
|
|
148
|
-
* @return {Buffer} Base58 decoded data
|
|
149
|
-
*/
|
|
150
|
-
export function decodeBase58Check (str) {
|
|
151
|
-
return bs58check.decode(str)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Converts a positive integer to the smallest possible
|
|
156
|
-
* representation in a binary digit representation
|
|
157
|
-
* @rtype (value: Number) => Buffer
|
|
158
|
-
* @param {Number} value - Value to encode
|
|
159
|
-
* @return {Buffer} - Encoded data
|
|
160
|
-
*/
|
|
161
|
-
export function encodeUnsigned (value) {
|
|
162
|
-
const binary = Buffer.allocUnsafe(4)
|
|
163
|
-
binary.writeUInt32BE(value)
|
|
164
|
-
return binary.slice(binary.findIndex(i => i !== 0))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Todo Duplicated in tx builder. remove
|
|
168
|
-
/**
|
|
169
|
-
* Compute contract address
|
|
170
|
-
* @rtype (owner: String, nonce: Number) => String
|
|
171
|
-
* @param {String} owner - Address of contract owner
|
|
172
|
-
* @param {Number} nonce - Round when contract was created
|
|
173
|
-
* @return {String} - Contract address
|
|
174
|
-
*/
|
|
175
|
-
export function encodeContractAddress (owner, nonce) {
|
|
176
|
-
const publicKey = decode(owner, 'ak')
|
|
177
|
-
const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])
|
|
178
|
-
return `ct_${encodeBase58Check(hash(binary))}`
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// KEY-PAIR HELPERS
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Generate keyPair from secret key
|
|
185
|
-
* @rtype (secret: Uint8Array) => KeyPair
|
|
186
|
-
* @param {Uint8Array} secret - secret key
|
|
187
|
-
* @return {Object} - Object with Private(privateKey) and Public(publicKey) keys
|
|
188
|
-
*/
|
|
189
|
-
export function generateKeyPairFromSecret (secret) {
|
|
190
|
-
return nacl.sign.keyPair.fromSecretKey(secret)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Generate a random ED25519 keypair
|
|
195
|
-
* @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
|
|
196
|
-
* @param {Boolean} raw - Whether to return raw (binary) keys
|
|
197
|
-
* @return {Object} Key pair
|
|
198
|
-
*/
|
|
199
|
-
export function generateKeyPair (raw = false) {
|
|
200
|
-
// <node>/apps/aens/test/aens_test_utils.erl
|
|
201
|
-
const keyPair = nacl.sign.keyPair()
|
|
202
|
-
|
|
203
|
-
const publicBuffer = Buffer.from(keyPair.publicKey)
|
|
204
|
-
const secretBuffer = Buffer.from(keyPair.secretKey)
|
|
205
|
-
|
|
206
|
-
if (raw) {
|
|
207
|
-
return {
|
|
208
|
-
publicKey: publicBuffer,
|
|
209
|
-
secretKey: secretBuffer
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
return {
|
|
213
|
-
publicKey: `ak_${encodeBase58Check(publicBuffer)}`,
|
|
214
|
-
secretKey: secretBuffer.toString('hex')
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Encrypt given data using `password`
|
|
221
|
-
* @rtype (password: String, binaryData: Buffer) => Uint8Array
|
|
222
|
-
* @param {String} password - Password to encrypt with
|
|
223
|
-
* @param {Buffer} binaryData - Data to encrypt
|
|
224
|
-
* @return {Uint8Array} Encrypted data
|
|
225
|
-
*/
|
|
226
|
-
export function encryptKey (password, binaryData) {
|
|
227
|
-
const hashedPasswordBytes = sha256hash(password)
|
|
228
|
-
const aesEcb = new Ecb(hashedPasswordBytes)
|
|
229
|
-
return aesEcb.encrypt(binaryData)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Decrypt given data using `password`
|
|
234
|
-
* @rtype (password: String, encrypted: String) => Uint8Array
|
|
235
|
-
* @param {String} password - Password to decrypt with
|
|
236
|
-
* @param {String} encrypted - Data to decrypt
|
|
237
|
-
* @return {Buffer} Decrypted data
|
|
238
|
-
*/
|
|
239
|
-
export function decryptKey (password, encrypted) {
|
|
240
|
-
const encryptedBytes = Buffer.from(encrypted)
|
|
241
|
-
const hashedPasswordBytes = sha256hash(password)
|
|
242
|
-
const aesEcb = new Ecb(hashedPasswordBytes)
|
|
243
|
-
return Buffer.from(aesEcb.decrypt(encryptedBytes))
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// SIGNATURES
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Generate signature
|
|
250
|
-
* @rtype (data: String|Buffer, privateKey: Buffer) => Buffer
|
|
251
|
-
* @param {String|Buffer} data - Data to sign
|
|
252
|
-
* @param {String|Buffer} privateKey - Key to sign with
|
|
253
|
-
* @return {Buffer|Uint8Array} Signature
|
|
254
|
-
*/
|
|
255
|
-
export function sign (data, privateKey) {
|
|
256
|
-
return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Verify that signature was signed by public key
|
|
261
|
-
* @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean
|
|
262
|
-
* @param {String|Buffer} str - Data to verify
|
|
263
|
-
* @param {Buffer} signature - Signature to verify
|
|
264
|
-
* @param {Buffer} publicKey - Key to verify against
|
|
265
|
-
* @return {Boolean} Valid?
|
|
266
|
-
*/
|
|
267
|
-
export function verify (str, signature, publicKey) {
|
|
268
|
-
return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function messageToHash (message) {
|
|
272
|
-
const p = Buffer.from('aeternity Signed Message:\n', 'utf8')
|
|
273
|
-
const msg = Buffer.from(message, 'utf8')
|
|
274
|
-
if (msg.length >= 0xFD) throw new Error('message too long')
|
|
275
|
-
return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function signMessage (message, privateKey) {
|
|
279
|
-
return sign(messageToHash(message), privateKey)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function verifyMessage (str, signature, publicKey) {
|
|
283
|
-
return verify(messageToHash(str), signature, publicKey)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* æternity readable public keys are the base58-encoded public key, prepended
|
|
288
|
-
* with 'ak_'
|
|
289
|
-
* @rtype (binaryKey: Buffer) => String
|
|
290
|
-
* @param {Buffer} binaryKey - Key to encode
|
|
291
|
-
* @return {String} Encoded key
|
|
292
|
-
*/
|
|
293
|
-
export function aeEncodeKey (binaryKey) {
|
|
294
|
-
const publicKeyBuffer = Buffer.from(binaryKey, 'hex')
|
|
295
|
-
const pubKeyAddress = encodeBase58Check(publicKeyBuffer)
|
|
296
|
-
return `ak_${pubKeyAddress}`
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Check key pair for validity
|
|
301
|
-
*
|
|
302
|
-
* Sign a message, and then verifying that signature
|
|
303
|
-
* @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean
|
|
304
|
-
* @param {Buffer} privateKey - Private key to verify
|
|
305
|
-
* @param {Buffer} publicKey - Public key to verify
|
|
306
|
-
* @return {Boolean} Valid?
|
|
307
|
-
*/
|
|
308
|
-
export function isValidKeypair (privateKey, publicKey) {
|
|
309
|
-
const message = Buffer.from('TheMessage')
|
|
310
|
-
const signature = sign(message, privateKey)
|
|
311
|
-
return verify(message, signature, publicKey)
|
|
312
|
-
}
|
package/src/utils/hd-wallet.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import nacl from 'tweetnacl'
|
|
2
|
-
import { full as hmac } from 'tweetnacl-auth'
|
|
3
|
-
import { fromString } from 'bip32-path'
|
|
4
|
-
import { validateMnemonic, mnemonicToSeed, generateMnemonic as genMnemonic } from '@aeternity/bip39'
|
|
5
|
-
import { decryptKey, encodeBase58Check, encryptKey } from './crypto'
|
|
6
|
-
|
|
7
|
-
const ED25519_CURVE = Buffer.from('ed25519 seed')
|
|
8
|
-
const HARDENED_OFFSET = 0x80000000
|
|
9
|
-
|
|
10
|
-
const toHex = (buffer) => Buffer.from(buffer).toString('hex')
|
|
11
|
-
|
|
12
|
-
export function derivePathFromKey (path, key) {
|
|
13
|
-
const segments = path === '' ? [] : fromString(path).toPathArray()
|
|
14
|
-
segments.forEach((segment, i) => {
|
|
15
|
-
if (segment < HARDENED_OFFSET) {
|
|
16
|
-
throw new Error(`Segment #${i + 1} is not hardened`)
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return segments.reduce((parentKey, segment) => deriveChild(parentKey, segment), key)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function derivePathFromSeed (path, seed) {
|
|
24
|
-
if (!['m', 'm/'].includes(path.slice(0, 2))) {
|
|
25
|
-
throw new Error('Invalid path')
|
|
26
|
-
}
|
|
27
|
-
const masterKey = getMasterKeyFromSeed(seed)
|
|
28
|
-
return derivePathFromKey(path.slice(2), masterKey)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function formatAccount (keys) {
|
|
32
|
-
const { secretKey, publicKey } = keys
|
|
33
|
-
return {
|
|
34
|
-
secretKey: toHex(secretKey),
|
|
35
|
-
publicKey: `ak_${encodeBase58Check(publicKey)}`
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function getKeyPair (secretKey) {
|
|
40
|
-
return nacl.sign.keyPair.fromSeed(secretKey)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function generateMnemonic () {
|
|
44
|
-
return genMnemonic()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getMasterKeyFromSeed (seed) {
|
|
48
|
-
const I = hmac(seed, ED25519_CURVE)
|
|
49
|
-
const IL = I.slice(0, 32)
|
|
50
|
-
const IR = I.slice(32)
|
|
51
|
-
return {
|
|
52
|
-
secretKey: IL,
|
|
53
|
-
chainCode: IR
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function deriveChild ({ secretKey, chainCode }, index) {
|
|
58
|
-
if (index < HARDENED_OFFSET) {
|
|
59
|
-
throw new Error(`Child index #${index} is not supported`)
|
|
60
|
-
}
|
|
61
|
-
const indexBuffer = Buffer.allocUnsafe(4)
|
|
62
|
-
indexBuffer.writeUInt32BE(index, 0)
|
|
63
|
-
|
|
64
|
-
const data = Buffer.concat([Buffer.alloc(1, 0), Buffer.from(secretKey), Buffer.from(indexBuffer)])
|
|
65
|
-
|
|
66
|
-
const I = hmac(data, chainCode)
|
|
67
|
-
const IL = I.slice(0, 32)
|
|
68
|
-
const IR = I.slice(32)
|
|
69
|
-
return {
|
|
70
|
-
secretKey: IL,
|
|
71
|
-
chainCode: IR
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function generateSaveHDWallet (mnemonic, password) {
|
|
76
|
-
if (!validateMnemonic(mnemonic)) {
|
|
77
|
-
throw new Error('Invalid mnemonic')
|
|
78
|
-
}
|
|
79
|
-
const seed = mnemonicToSeed(mnemonic)
|
|
80
|
-
const walletKey = derivePathFromSeed('m/44h/457h', seed)
|
|
81
|
-
return {
|
|
82
|
-
secretKey: toHex(encryptKey(password, walletKey.secretKey)),
|
|
83
|
-
chainCode: toHex(encryptKey(password, walletKey.chainCode))
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function getSaveHDWalletAccounts (saveHDWallet, password, accountCount) {
|
|
88
|
-
const walletKey = {
|
|
89
|
-
secretKey: decryptKey(password, Buffer.from(saveHDWallet.secretKey, 'hex')),
|
|
90
|
-
chainCode: decryptKey(password, Buffer.from(saveHDWallet.chainCode, 'hex'))
|
|
91
|
-
}
|
|
92
|
-
return (new Array(accountCount)).fill()
|
|
93
|
-
.map((_, idx) =>
|
|
94
|
-
formatAccount(getKeyPair(derivePathFromKey(`${idx}h/0h/0h`, walletKey).secretKey)))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const getHdWalletAccountFromMnemonic = (mnemonic, accountIdx) => {
|
|
98
|
-
const seed = mnemonicToSeed(mnemonic)
|
|
99
|
-
const walletKey = derivePathFromSeed('m/44h/457h', seed)
|
|
100
|
-
const derived = derivePathFromKey(`${accountIdx}h/0h/0h`, walletKey)
|
|
101
|
-
const keyPair = getKeyPair(derived.secretKey)
|
|
102
|
-
return {
|
|
103
|
-
...formatAccount(keyPair),
|
|
104
|
-
idx: accountIdx
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default {
|
|
109
|
-
getHdWalletAccountFromMnemonic,
|
|
110
|
-
getSaveHDWalletAccounts,
|
|
111
|
-
generateSaveHDWallet,
|
|
112
|
-
generateMnemonic,
|
|
113
|
-
deriveChild,
|
|
114
|
-
getMasterKeyFromSeed
|
|
115
|
-
}
|
package/src/utils/json-big.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import JsonBig from '@aeternity/json-bigint'
|
|
2
|
-
import BigNumber from 'bignumber.js'
|
|
3
|
-
|
|
4
|
-
const jsonBig = JsonBig({ storeAsString: true })
|
|
5
|
-
|
|
6
|
-
const convertValuesToBigNumbers = value => {
|
|
7
|
-
if (typeof value === 'object' && value !== null && value.constructor === Object) {
|
|
8
|
-
return Object.entries(value)
|
|
9
|
-
.map(([key, value]) => [key, convertValuesToBigNumbers(value)])
|
|
10
|
-
.reduce((p, [k, v]) => ({ ...p, [k]: v }), {})
|
|
11
|
-
}
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return value.map(item => convertValuesToBigNumbers(item))
|
|
14
|
-
}
|
|
15
|
-
if (typeof value === 'string' && BigNumber(value).toString(10) === value) {
|
|
16
|
-
const bn = BigNumber(value)
|
|
17
|
-
bn.toJSON = () => bn.toString(10)
|
|
18
|
-
return bn
|
|
19
|
-
}
|
|
20
|
-
return value
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
stringify: (object, ...args) => jsonBig.stringify(convertValuesToBigNumbers(object), ...args),
|
|
25
|
-
parse: jsonBig.parse
|
|
26
|
-
}
|
package/src/utils/keystore.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import nacl from 'tweetnacl'
|
|
2
|
-
import { v4 as uuid } from 'uuid'
|
|
3
|
-
|
|
4
|
-
import { encodeBase58Check } from './crypto'
|
|
5
|
-
import { str2buf } from './bytes'
|
|
6
|
-
|
|
7
|
-
const _sodium = require('libsodium-wrappers-sumo')
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* KeyStore module
|
|
11
|
-
* @module @aeternity/aepp-sdk/es/utils/keystore
|
|
12
|
-
* @example import { Keystore } from '@aeternity/aepp-sdk'
|
|
13
|
-
* @example const { Keystore } = require('@aeternity/aepp-sdk')
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const DEFAULTS = {
|
|
17
|
-
crypto: {
|
|
18
|
-
secret_type: 'ed25519',
|
|
19
|
-
symmetric_alg: 'xsalsa20-poly1305',
|
|
20
|
-
kdf: 'argon2id',
|
|
21
|
-
kdf_params: {
|
|
22
|
-
memlimit_kib: 65536,
|
|
23
|
-
opslimit: 3,
|
|
24
|
-
parallelism: 1
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// DERIVED KEY PART
|
|
30
|
-
const DERIVED_KEY_FUNCTIONS = {
|
|
31
|
-
argon2id: deriveKeyUsingArgon2id
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function deriveKeyUsingArgon2id (password, salt, options) {
|
|
35
|
-
const { memlimit_kib: memoryCost, opslimit: timeCost } = options.kdf_params
|
|
36
|
-
// const isBrowser = !(typeof module !== 'undefined' && module.exports)
|
|
37
|
-
|
|
38
|
-
return _sodium.ready.then(async () => {
|
|
39
|
-
// tslint:disable-next-line:typedef
|
|
40
|
-
const sodium = _sodium
|
|
41
|
-
|
|
42
|
-
const result = sodium.crypto_pwhash(
|
|
43
|
-
32,
|
|
44
|
-
password,
|
|
45
|
-
salt,
|
|
46
|
-
timeCost,
|
|
47
|
-
memoryCost * 1024,
|
|
48
|
-
sodium.crypto_pwhash_ALG_ARGON2ID13
|
|
49
|
-
)
|
|
50
|
-
return Buffer.from(result)
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// CRYPTO PART
|
|
55
|
-
const CRYPTO_FUNCTIONS = {
|
|
56
|
-
'xsalsa20-poly1305': { encrypt: encryptXsalsa20Poly1305, decrypt: decryptXsalsa20Poly1305 }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function encryptXsalsa20Poly1305 ({ plaintext, key, nonce }) {
|
|
60
|
-
return nacl.secretbox(plaintext, nonce, key)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function decryptXsalsa20Poly1305 ({ ciphertext, key, nonce }) {
|
|
64
|
-
const res = nacl.secretbox.open(ciphertext, nonce, key)
|
|
65
|
-
if (!res) throw new Error('Invalid password or nonce')
|
|
66
|
-
return res
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Symmetric private key encryption using secret (derived) key.
|
|
71
|
-
* @param {buffer|string} plaintext Data to be encrypted.
|
|
72
|
-
* @param {buffer|string} key Secret key.
|
|
73
|
-
* @param {buffer|string} nonce Randomly generated nonce.
|
|
74
|
-
* @param {string=} algo Encryption algorithm (default: DEFAULTS.crypto.symmetric_alg).
|
|
75
|
-
* @return {buffer} Encrypted data.
|
|
76
|
-
*/
|
|
77
|
-
function encrypt (plaintext, key, nonce, algo = DEFAULTS.crypto.symmetric_alg) {
|
|
78
|
-
if (!CRYPTO_FUNCTIONS[algo]) throw new Error(algo + ' is not available')
|
|
79
|
-
return CRYPTO_FUNCTIONS[algo].encrypt({ plaintext, nonce, key })
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Symmetric private key decryption using secret (derived) key.
|
|
84
|
-
* @param {buffer|Uint8Array} ciphertext Data to be decrypted.
|
|
85
|
-
* @param {buffer|Uint8Array} key Secret key.
|
|
86
|
-
* @param {buffer|Uint8Array} nonce Nonce from key-object.
|
|
87
|
-
* @param {string=} algo Encryption algorithm.
|
|
88
|
-
* @return {buffer} Decrypted data.
|
|
89
|
-
*/
|
|
90
|
-
function decrypt (ciphertext, key, nonce, algo) {
|
|
91
|
-
if (!CRYPTO_FUNCTIONS[algo]) throw new Error(algo + ' is not available')
|
|
92
|
-
return CRYPTO_FUNCTIONS[algo].decrypt({ ciphertext, nonce, key })
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Derive secret key from password with key derivation function.
|
|
97
|
-
* @param {string} password User-supplied password.
|
|
98
|
-
* @param {buffer|Uint8Array} nonce Randomly generated nonce.
|
|
99
|
-
* @param {Object=} options Encryption parameters.
|
|
100
|
-
* @param {string=} options.kdf Key derivation function (default: DEFAULTS.crypto.kdf).
|
|
101
|
-
* @param {Object=} options.kdf_params KDF parameters (default: DEFAULTS.crypto.kdf_params).
|
|
102
|
-
* @return {buffer} Secret key derived from password.
|
|
103
|
-
*/
|
|
104
|
-
async function deriveKey (password, nonce, options = {
|
|
105
|
-
kdf_params: DEFAULTS.crypto.kdf_params,
|
|
106
|
-
kdf: DEFAULTS.crypto.kdf
|
|
107
|
-
}) {
|
|
108
|
-
if (typeof password === 'undefined' || password === null || !nonce) {
|
|
109
|
-
throw new Error('Must provide password and nonce to derive a key')
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!Object.prototype.hasOwnProperty.call(DERIVED_KEY_FUNCTIONS, options.kdf)) throw new Error('Unsupported kdf type')
|
|
113
|
-
|
|
114
|
-
return DERIVED_KEY_FUNCTIONS[options.kdf](password, nonce, options)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Assemble key data object in secret-storage format.
|
|
119
|
-
* @param {buffer} name Key name.
|
|
120
|
-
* @param {buffer} derivedKey Password-derived secret key.
|
|
121
|
-
* @param {buffer} privateKey Private key.
|
|
122
|
-
* @param {buffer} nonce Randomly generated 24byte nonce.
|
|
123
|
-
* @param {buffer} salt Randomly generated 16byte salt.
|
|
124
|
-
* @param {Object=} options Encryption parameters.
|
|
125
|
-
* @param {string=} options.kdf Key derivation function (default: argon2id).
|
|
126
|
-
* @param {string=} options.cipher Symmetric cipher (default: constants.cipher).
|
|
127
|
-
* @param {Object=} options.kdf_params KDF parameters (default: constants.<kdf>).
|
|
128
|
-
* @return {Object}
|
|
129
|
-
*/
|
|
130
|
-
function marshal (name, derivedKey, privateKey, nonce, salt, options = {}) {
|
|
131
|
-
const opt = Object.assign({}, DEFAULTS.crypto, options)
|
|
132
|
-
return Object.assign(
|
|
133
|
-
{ name, version: 1, public_key: getAddressFromPriv(privateKey), id: uuid() },
|
|
134
|
-
{
|
|
135
|
-
crypto: Object.assign(
|
|
136
|
-
{
|
|
137
|
-
secret_type: opt.secret_type,
|
|
138
|
-
symmetric_alg: opt.symmetric_alg,
|
|
139
|
-
ciphertext: Buffer.from(encrypt(Buffer.from(privateKey), derivedKey, nonce, opt.symmetric_alg)).toString('hex'),
|
|
140
|
-
cipher_params: { nonce: Buffer.from(nonce).toString('hex') }
|
|
141
|
-
},
|
|
142
|
-
{ kdf: opt.kdf, kdf_params: { ...opt.kdf_params, salt: Buffer.from(salt).toString('hex') } }
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function getAddressFromPriv (secret) {
|
|
149
|
-
const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))
|
|
150
|
-
const publicBuffer = Buffer.from(keys.publicKey)
|
|
151
|
-
return `ak_${encodeBase58Check(publicBuffer)}`
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Recover plaintext private key from secret-storage key object.
|
|
156
|
-
* @param {String} password Keystore object password.
|
|
157
|
-
* @param {Object} keyObject Keystore object.
|
|
158
|
-
* @return {Buffer} Plaintext private key.
|
|
159
|
-
*/
|
|
160
|
-
export async function recover (password, keyObject) {
|
|
161
|
-
validateKeyObj(keyObject)
|
|
162
|
-
const nonce = Uint8Array.from(str2buf(keyObject.crypto.cipher_params.nonce))
|
|
163
|
-
const salt = Uint8Array.from(str2buf(keyObject.crypto.kdf_params.salt))
|
|
164
|
-
const kdfParams = keyObject.crypto.kdf_params
|
|
165
|
-
const kdf = keyObject.crypto.kdf
|
|
166
|
-
|
|
167
|
-
const key = await decrypt(
|
|
168
|
-
Uint8Array.from(str2buf(keyObject.crypto.ciphertext)),
|
|
169
|
-
await deriveKey(password, salt, { kdf, kdf_params: kdfParams }),
|
|
170
|
-
nonce,
|
|
171
|
-
keyObject.crypto.symmetric_alg
|
|
172
|
-
)
|
|
173
|
-
if (!key) throw new Error('Invalid password')
|
|
174
|
-
|
|
175
|
-
if (Buffer.from(key).length === 64) return Buffer.from(key).toString('hex')
|
|
176
|
-
return Buffer.from(key).toString('utf-8')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Export private key to keystore secret-storage format.
|
|
181
|
-
* @param {String} name Key name.
|
|
182
|
-
* @param {String} password User-supplied password.
|
|
183
|
-
* @param {String} privateKey Private key.
|
|
184
|
-
* @param {Buffer} nonce Randomly generated 24byte nonce.
|
|
185
|
-
* @param {Buffer} salt Randomly generated 16byte salt.
|
|
186
|
-
* @param {Object=} options Encryption parameters.
|
|
187
|
-
* @param {String=} options.kdf Key derivation function (default: pbkdf2).
|
|
188
|
-
* @param {String=} options.cipher Symmetric cipher (default: constants.cipher).
|
|
189
|
-
* @param {Object=} options.kdfparams KDF parameters (default: constants.<kdf>).
|
|
190
|
-
* @return {Object}
|
|
191
|
-
*/
|
|
192
|
-
export async function dump (
|
|
193
|
-
name,
|
|
194
|
-
password,
|
|
195
|
-
privateKey,
|
|
196
|
-
nonce = nacl.randomBytes(24),
|
|
197
|
-
salt = nacl.randomBytes(16),
|
|
198
|
-
options = {}
|
|
199
|
-
) {
|
|
200
|
-
const opt = Object.assign({}, DEFAULTS.crypto, options)
|
|
201
|
-
return marshal(
|
|
202
|
-
name,
|
|
203
|
-
await deriveKey(password, salt, opt),
|
|
204
|
-
privateKey,
|
|
205
|
-
nonce,
|
|
206
|
-
salt,
|
|
207
|
-
opt
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function validateKeyObj (obj) {
|
|
212
|
-
const root = ['crypto', 'id', 'version', 'public_key']
|
|
213
|
-
const cryptoKeys = ['cipher_params', 'ciphertext', 'symmetric_alg', 'kdf', 'kdf_params']
|
|
214
|
-
|
|
215
|
-
const missingRootKeys = root.filter(key => !Object.prototype.hasOwnProperty.call(obj, key))
|
|
216
|
-
if (missingRootKeys.length) throw new Error(`Invalid key file format. Require properties: ${missingRootKeys}`)
|
|
217
|
-
|
|
218
|
-
const missingCryptoKeys = cryptoKeys
|
|
219
|
-
.filter(key => !Object.prototype.hasOwnProperty.call(obj.crypto, key))
|
|
220
|
-
if (missingCryptoKeys.length) throw new Error(`Invalid key file format. Require properties: ${missingCryptoKeys}`)
|
|
221
|
-
|
|
222
|
-
return true
|
|
223
|
-
}
|