@aeternity/aepp-sdk 11.0.1 → 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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
- 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 +90 -46
- 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.mjs +147 -112
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +898 -900
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +97 -51
- package/es/channel/internal.mjs.map +1 -1
- 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 +199 -180
- package/es/contract/aci.mjs.map +1 -1
- 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 +32 -40
- package/es/index.mjs.map +1 -1
- 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 +11 -19
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +62 -10
- package/es/tx/builder/field-types.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +71 -169
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +141 -323
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +173 -510
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +171 -265
- package/es/tx/index.mjs.map +1 -1
- 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 +64 -71
- package/es/tx/validator.mjs.map +1 -1
- 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.map +1 -1
- 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.mjs +28 -41
- package/es/utils/amount-formatter.mjs.map +1 -1
- 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 +10 -8
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/bytes.mjs +10 -14
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +60 -68
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +47 -51
- package/es/utils/encoder.mjs.map +1 -1
- package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
- package/es/utils/errors.mjs +318 -125
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +27 -16
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +10 -14
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +98 -193
- package/es/utils/keystore.mjs.map +1 -1
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/mptree.mjs +13 -14
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +21 -36
- package/es/utils/other.mjs.map +1 -1
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.d.ts +24 -0
- package/es/utils/string.mjs +8 -10
- package/es/utils/string.mjs.map +1 -1
- package/package.json +49 -39
- 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.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
- 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} +220 -128
- 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.js → constants.ts} +12 -16
- 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 -42
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -11
- package/src/utils/bytes.ts +12 -14
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +52 -55
- package/src/utils/errors.ts +268 -134
- 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 +14 -14
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/es/account/base.mjs +0 -179
- package/es/account/base.mjs.map +0 -1
- package/es/account/memory.mjs +0 -99
- package/es/account/memory.mjs.map +0 -1
- package/es/account/multiple.mjs +0 -179
- package/es/account/multiple.mjs.map +0 -1
- package/es/ae/aens.mjs +0 -404
- package/es/ae/aens.mjs.map +0 -1
- package/es/ae/aepp.mjs +0 -45
- package/es/ae/aepp.mjs.map +0 -1
- package/es/ae/contract.mjs +0 -159
- package/es/ae/contract.mjs.map +0 -1
- package/es/ae/index.mjs +0 -207
- package/es/ae/index.mjs.map +0 -1
- package/es/ae/oracle.mjs +0 -339
- package/es/ae/oracle.mjs.map +0 -1
- package/es/ae/universal.mjs +0 -45
- package/es/ae/universal.mjs.map +0 -1
- package/es/ae/wallet.mjs +0 -50
- package/es/ae/wallet.mjs.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -18
- package/es/chain/index.mjs +0 -272
- package/es/chain/index.mjs.map +0 -1
- package/es/chain/node.mjs +0 -442
- package/es/chain/node.mjs.map +0 -1
- package/es/contract/compiler.mjs +0 -115
- package/es/contract/compiler.mjs.map +0 -1
- package/es/contract/ga/helpers.mjs +0 -30
- package/es/contract/ga/helpers.mjs.map +0 -1
- package/es/contract/ga/index.mjs +0 -178
- package/es/contract/ga/index.mjs.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/encoder.d.ts +0 -26
- package/es/node-pool/index.mjs +0 -188
- package/es/node-pool/index.mjs.map +0 -1
- package/es/node.mjs +0 -133
- package/es/node.mjs.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/tx-object.mjs +0 -283
- package/es/tx/tx-object.mjs.map +0 -1
- package/es/tx/tx.mjs +0 -938
- package/es/tx/tx.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
- package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
- package/es/utils/async-init.mjs +0 -64
- package/es/utils/async-init.mjs.map +0 -1
- package/es/utils/crypto-ts.mjs.map +0 -1
- package/es/utils/swagger.mjs +0 -164
- package/es/utils/swagger.mjs.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -83
- package/src/account/multiple.js +0 -162
- package/src/ae/aens.js +0 -361
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -148
- package/src/ae/index.js +0 -168
- package/src/ae/oracle.js +0 -311
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -269
- package/src/chain/node.js +0 -320
- package/src/channel/index.js +0 -903
- package/src/channel/internal.js +0 -236
- package/src/contract/aci.js +0 -376
- package/src/contract/compiler.js +0 -100
- package/src/contract/ga/helpers.js +0 -19
- package/src/contract/ga/index.js +0 -150
- package/src/index.js +0 -89
- package/src/node-pool/index.js +0 -172
- package/src/node.js +0 -116
- package/src/tx/builder/field-types.js +0 -61
- package/src/tx/builder/helpers.js +0 -334
- package/src/tx/builder/index.js +0 -465
- package/src/tx/builder/schema.js +0 -1100
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -187
- package/src/tx/tx.js +0 -631
- package/src/tx/validator.js +0 -181
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
- package/src/utils/aepp-wallet-communication/helpers.js +0 -60
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
- package/src/utils/aepp-wallet-communication/schema.ts +0 -80
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
- package/src/utils/async-init.js +0 -45
- package/src/utils/crypto.js +0 -219
- package/src/utils/hd-wallet.js +0 -100
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -219
- package/src/utils/swagger.js +0 -156
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PipelinePolicy } from '@azure/core-rest-pipeline';
|
|
2
|
+
import { AdditionalPolicyConfig } from '@azure/core-client';
|
|
3
|
+
export declare const genRequestQueuesPolicy: () => AdditionalPolicyConfig;
|
|
4
|
+
export declare const genCombineGetRequestsPolicy: () => AdditionalPolicyConfig;
|
|
5
|
+
export declare const genErrorFormatterPolicy: (getMessage: (b: any) => string) => AdditionalPolicyConfig;
|
|
6
|
+
export declare const genVersionCheckPolicy: (name: string, ignorePath: string, versionPromise: Promise<string>, geVersion: string, ltVersion: string) => PipelinePolicy;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { RestError } from '@azure/core-rest-pipeline';
|
|
2
|
+
import { pause } from "./other.mjs";
|
|
3
|
+
import semverSatisfies from "./semver-satisfies.mjs";
|
|
4
|
+
import { UnsupportedVersionError } from "./errors.mjs";
|
|
5
|
+
export const genRequestQueuesPolicy = () => {
|
|
6
|
+
const requestQueues = new Map();
|
|
7
|
+
return {
|
|
8
|
+
policy: {
|
|
9
|
+
name: 'request-queues',
|
|
10
|
+
|
|
11
|
+
async sendRequest(request, next) {
|
|
12
|
+
var _requestQueues$get;
|
|
13
|
+
|
|
14
|
+
const key = request.headers.get('__queue');
|
|
15
|
+
request.headers.delete('__queue');
|
|
16
|
+
|
|
17
|
+
const getResponse = async () => await next(request);
|
|
18
|
+
|
|
19
|
+
if (key == null) return await getResponse();
|
|
20
|
+
const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse); // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
|
|
21
|
+
// gap to ensure that node won't reject the nonce
|
|
22
|
+
|
|
23
|
+
requestQueues.set(key, req.then(async () => await pause(750)));
|
|
24
|
+
return await req;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
},
|
|
28
|
+
position: 'perCall'
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const genCombineGetRequestsPolicy = () => {
|
|
32
|
+
const pendingGetRequests = new Map();
|
|
33
|
+
return {
|
|
34
|
+
policy: {
|
|
35
|
+
name: 'combine-requests',
|
|
36
|
+
|
|
37
|
+
async sendRequest(request, next) {
|
|
38
|
+
var _pendingGetRequests$g;
|
|
39
|
+
|
|
40
|
+
if (request.method !== 'GET') return await next(request);
|
|
41
|
+
const key = JSON.stringify([request.url, request.body]);
|
|
42
|
+
const response = (_pendingGetRequests$g = pendingGetRequests.get(key)) !== null && _pendingGetRequests$g !== void 0 ? _pendingGetRequests$g : next(request);
|
|
43
|
+
pendingGetRequests.set(key, response);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
return await response;
|
|
47
|
+
} finally {
|
|
48
|
+
pendingGetRequests.delete(key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
},
|
|
53
|
+
position: 'perCall'
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export const genErrorFormatterPolicy = getMessage => ({
|
|
57
|
+
policy: {
|
|
58
|
+
name: 'error-formatter',
|
|
59
|
+
|
|
60
|
+
async sendRequest(request, next) {
|
|
61
|
+
try {
|
|
62
|
+
return await next(request);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
var _error$response;
|
|
65
|
+
|
|
66
|
+
if (!(error instanceof RestError) || error.request == null) throw error;
|
|
67
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.bodyAsText) == null) throw error;
|
|
68
|
+
let body;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
body = JSON.parse(error.response.bodyAsText);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
|
|
77
|
+
const message = getMessage(body);
|
|
78
|
+
if (message !== '') error.message += `:${message}`;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
},
|
|
84
|
+
position: 'perCall'
|
|
85
|
+
});
|
|
86
|
+
export const genVersionCheckPolicy = (name, ignorePath, versionPromise, geVersion, ltVersion) => ({
|
|
87
|
+
name: 'version-check',
|
|
88
|
+
|
|
89
|
+
async sendRequest(request, next) {
|
|
90
|
+
if (new URL(request.url).pathname === ignorePath) return await next(request);
|
|
91
|
+
const args = [await versionPromise, geVersion, ltVersion];
|
|
92
|
+
if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
|
|
93
|
+
return await next(request);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=autorest.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autorest.mjs","names":["RestError","pause","semverSatisfies","UnsupportedVersionError","genRequestQueuesPolicy","requestQueues","Map","policy","name","sendRequest","request","next","key","headers","get","delete","getResponse","req","Promise","resolve","then","set","position","genCombineGetRequestsPolicy","pendingGetRequests","method","JSON","stringify","url","body","response","genErrorFormatterPolicy","getMessage","error","bodyAsText","parse","e","message","URL","pathname","slice","genVersionCheckPolicy","ignorePath","versionPromise","geVersion","ltVersion","args"],"sources":["../../src/utils/autorest.ts"],"sourcesContent":["import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline'\nimport { AdditionalPolicyConfig } from '@azure/core-client'\nimport { pause } from './other'\nimport semverSatisfies from './semver-satisfies'\nimport { UnsupportedVersionError } from './errors'\n\nexport const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {\n const requestQueues = new Map<string, Promise<unknown>>()\n\n return {\n policy: {\n name: 'request-queues',\n async sendRequest (request, next) {\n const key = request.headers.get('__queue')\n request.headers.delete('__queue')\n const getResponse = async (): Promise<PipelineResponse> => await next(request)\n if (key == null) return await getResponse()\n const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse)\n // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803\n // gap to ensure that node won't reject the nonce\n requestQueues.set(key, req.then(async () => await pause(750)))\n return await req\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {\n const pendingGetRequests = new Map<string, Promise<PipelineResponse>>()\n\n return {\n policy: {\n name: 'combine-requests',\n async sendRequest (request, next) {\n if (request.method !== 'GET') return await next(request)\n const key = JSON.stringify([request.url, request.body])\n const response = pendingGetRequests.get(key) ?? next(request)\n pendingGetRequests.set(key, response)\n try {\n return await response\n } finally {\n pendingGetRequests.delete(key)\n }\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genErrorFormatterPolicy = (\n getMessage: (b: any) => string\n): AdditionalPolicyConfig => ({\n policy: {\n name: 'error-formatter',\n async sendRequest (request, next) {\n try {\n return await next(request)\n } catch (error) {\n if (!(error instanceof RestError) || error.request == null) throw error\n if (error.response?.bodyAsText == null) throw error\n\n let body\n try {\n body = JSON.parse(error.response.bodyAsText)\n } catch (e) {\n throw error\n }\n error.message = `${new URL(error.request.url).pathname.slice(1)} error`\n const message = getMessage(body)\n if (message !== '') error.message += `:${message}`\n throw error\n }\n }\n },\n position: 'perCall'\n})\n\nexport const genVersionCheckPolicy = (\n name: string, ignorePath: string,\n versionPromise: Promise<string>, geVersion: string, ltVersion: string\n): PipelinePolicy => ({\n name: 'version-check',\n async sendRequest (request, next) {\n if (new URL(request.url).pathname === ignorePath) return await next(request)\n const args = [await versionPromise, geVersion, ltVersion] as const\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args)\n return await next(request)\n }\n})\n"],"mappings":"AAAA,SAASA,SAAT,QAA4D,2BAA5D;SAESC,K;OACFC,e;SACEC,uB;AAET,OAAO,MAAMC,sBAAsB,GAAG,MAA8B;EAClE,MAAMC,aAAa,GAAG,IAAIC,GAAJ,EAAtB;EAEA,OAAO;IACLC,MAAM,EAAE;MACNC,IAAI,EAAE,gBADA;;MAEN,MAAMC,WAAN,CAAmBC,OAAnB,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AqB,GAAG,CACnCjC,IADmC,EACrBkC,UADqB,EAEnCC,cAFmC,EAEFC,SAFE,EAEiBC,SAFjB,MAGf;EACpBrC,IAAI,EAAE,eADc;;EAEpB,MAAMC,WAAN,CAAmBC,OAAnB,EAA4BC,IAA5B,EAAkC;IAChC,IAAI,IAAI2B,GAAJ,CAAQ5B,OAAO,CAACkB,GAAhB,EAAqBW,QAArB,KAAkCG,UAAtC,EAAkD,OAAO,MAAM/B,IAAI,CAACD,OAAD,CAAjB;IAClD,MAAMoC,IAAI,GAAG,CAAC,MAAMH,cAAP,EAAuBC,SAAvB,EAAkCC,SAAlC,CAAb;IACA,IAAI,CAAC3C,eAAe,CAAC,GAAG4C,IAAJ,CAApB,EAA+B,MAAM,IAAI3C,uBAAJ,CAA4BK,IAA5B,EAAkC,GAAGsC,IAArC,CAAN;IAC/B,OAAO,MAAMnC,IAAI,CAACD,OAAD,CAAjB;EACD;;AAPmB,CAHe,CAA9B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Big Number Helpers
|
|
3
|
+
*/
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
/**
|
|
6
|
+
* Check if value is BigNumber, Number, BigInt or number string representation
|
|
7
|
+
* @param number - number to check
|
|
8
|
+
*/
|
|
9
|
+
export declare const isBigNumber: (number: string | number | bigint | BigNumber) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* BigNumber ceil operation
|
|
12
|
+
*/
|
|
13
|
+
export declare const ceil: (bigNumber: BigNumber) => BigNumber;
|
package/es/utils/bignumber.mjs
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Big Number Helpers
|
|
3
|
-
* @module @aeternity/aepp-sdk/es/utils/bignumber
|
|
4
|
-
* @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
|
|
5
5
|
*/
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
7
7
|
/**
|
|
8
|
-
* Check if value is BigNumber, Number or number string representation
|
|
9
|
-
* @param
|
|
10
|
-
* @return {Boolean}
|
|
8
|
+
* Check if value is BigNumber, Number, BigInt or number string representation
|
|
9
|
+
* @param number - number to check
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
|
-
export const isBigNumber = number =>
|
|
12
|
+
export const isBigNumber = number => {
|
|
13
|
+
var _context;
|
|
14
|
+
|
|
15
|
+
if (typeof number === 'bigint') return true;
|
|
16
|
+
return _includesInstanceProperty(_context = ['number', 'object', 'string']).call(_context, typeof number) && (!isNaN(number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
|
|
17
|
+
};
|
|
14
18
|
/**
|
|
15
19
|
* BigNumber ceil operation
|
|
16
|
-
* @param {BigNumber} bigNumber
|
|
17
|
-
* @return {BigNumber}
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
22
|
export const ceil = bigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"bignumber.mjs","names":["BigNumber","isBigNumber","number","isNaN","Number","isInteger","ceil","bigNumber","integerValue","ROUND_CEIL"],"sources":["../../src/utils/bignumber.ts"],"sourcesContent":["/**\n * Big Number Helpers\n */\nimport BigNumber from 'bignumber.js'\n\n/**\n * Check if value is BigNumber, Number, BigInt or number string representation\n * @param number - number to check\n */\nexport const isBigNumber = (number: string | number | bigint | BigNumber): boolean => {\n if (typeof number === 'bigint') return true\n return ['number', 'object', 'string'].includes(typeof number) &&\n (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))\n}\n\n/**\n * BigNumber ceil operation\n */\nexport const ceil = (bigNumber: BigNumber): BigNumber => bigNumber\n .integerValue(BigNumber.ROUND_CEIL)\n"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,MAAD,IAA2D;EAAA;;EACpF,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC,OAAO,IAAP;EAChC,OAAO,sCAAC,QAAD,EAAW,QAAX,EAAqB,QAArB,kBAAwC,OAAOA,MAA/C,MACJ,CAACC,KAAK,CAACD,MAAD,CAAN,IAA4BE,MAAM,CAACC,SAAP,CAAiBH,MAAjB,CAA5B,IAAwDF,SAAS,CAACC,WAAV,CAAsBC,MAAtB,CADpD,CAAP;AAED,CAJM;AAMP;AACA;AACA;;AACA,OAAO,MAAMI,IAAI,GAAIC,SAAD,IAAqCA,SAAS,CAC/DC,YADsD,CACzCR,SAAS,CAACS,UAD+B,CAAlD"}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
/**
|
|
4
|
-
* Bytes module
|
|
5
|
-
* @module @aeternity/aepp-sdk/es/utils/bytes
|
|
6
|
-
* @example import { Crypto } from '@aeternity/aepp-sdk'
|
|
7
|
-
*/
|
|
8
3
|
/**
|
|
9
4
|
* Convert bignumber to byte array
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
5
|
+
* @param x - bignumber instance
|
|
6
|
+
* @returns Buffer
|
|
12
7
|
*/
|
|
13
8
|
export declare function bigNumberToByteArray(x: BigNumber): Buffer;
|
|
14
9
|
/**
|
|
15
10
|
* Convert string, number, or BigNumber to byte array
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @
|
|
11
|
+
* @param val - value to convert
|
|
12
|
+
* @param big - enables force conversion to BigNumber
|
|
13
|
+
* @returns Buffer
|
|
19
14
|
*/
|
|
20
15
|
export declare function toBytes(val?: null | string | number | BigNumber, big?: boolean): Buffer;
|
|
21
16
|
/**
|
|
22
17
|
* Convert a string to a Buffer. If encoding is not specified, hex-encoding
|
|
23
18
|
* will be used if the input is valid hex. If the input is valid base64 but
|
|
24
19
|
* not valid hex, base64 will be used. Otherwise, utf8 will be used.
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @
|
|
20
|
+
* @param str - String to be converted.
|
|
21
|
+
* @param enc - Encoding of the input string.
|
|
22
|
+
* @returns Buffer containing the input data.
|
|
28
23
|
*/
|
|
29
24
|
export declare function str2buf(str: string, enc?: BufferEncoding): Buffer;
|
|
25
|
+
export declare const bytesToHex: (b: Uint8Array) => string;
|
|
26
|
+
export declare const hexToBytes: (s: string) => Uint8Array;
|
package/es/utils/bytes.mjs
CHANGED
|
@@ -22,16 +22,10 @@ const {
|
|
|
22
22
|
import BigNumber from 'bignumber.js';
|
|
23
23
|
import { NoSerializerFoundError, TypeError } from "./errors.mjs";
|
|
24
24
|
import { isBase64, isHex } from "./string.mjs";
|
|
25
|
-
/**
|
|
26
|
-
* Bytes module
|
|
27
|
-
* @module @aeternity/aepp-sdk/es/utils/bytes
|
|
28
|
-
* @example import { Crypto } from '@aeternity/aepp-sdk'
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
25
|
/**
|
|
32
26
|
* Convert bignumber to byte array
|
|
33
|
-
* @param
|
|
34
|
-
* @
|
|
27
|
+
* @param x - bignumber instance
|
|
28
|
+
* @returns Buffer
|
|
35
29
|
*/
|
|
36
30
|
|
|
37
31
|
export function bigNumberToByteArray(x) {
|
|
@@ -42,9 +36,9 @@ export function bigNumberToByteArray(x) {
|
|
|
42
36
|
}
|
|
43
37
|
/**
|
|
44
38
|
* Convert string, number, or BigNumber to byte array
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @
|
|
39
|
+
* @param val - value to convert
|
|
40
|
+
* @param big - enables force conversion to BigNumber
|
|
41
|
+
* @returns Buffer
|
|
48
42
|
*/
|
|
49
43
|
|
|
50
44
|
export function toBytes(val) {
|
|
@@ -69,9 +63,9 @@ export function toBytes(val) {
|
|
|
69
63
|
* Convert a string to a Buffer. If encoding is not specified, hex-encoding
|
|
70
64
|
* will be used if the input is valid hex. If the input is valid base64 but
|
|
71
65
|
* not valid hex, base64 will be used. Otherwise, utf8 will be used.
|
|
72
|
-
* @param
|
|
73
|
-
* @param
|
|
74
|
-
* @
|
|
66
|
+
* @param str - String to be converted.
|
|
67
|
+
* @param enc - Encoding of the input string.
|
|
68
|
+
* @returns Buffer containing the input data.
|
|
75
69
|
*/
|
|
76
70
|
|
|
77
71
|
export function str2buf(str, enc) {
|
|
@@ -79,4 +73,6 @@ export function str2buf(str, enc) {
|
|
|
79
73
|
|
|
80
74
|
return _Buffer.from(str, (_ref = enc !== null && enc !== void 0 ? enc : isHex(str) ? 'hex' : undefined) !== null && _ref !== void 0 ? _ref : isBase64(str) ? 'base64' : undefined);
|
|
81
75
|
}
|
|
76
|
+
export const bytesToHex = b => _Buffer.from(b).toString('hex');
|
|
77
|
+
export const hexToBytes = s => _Buffer.from(s, 'hex');
|
|
82
78
|
//# sourceMappingURL=bytes.mjs.map
|
package/es/utils/bytes.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"bytes.mjs","names":["BigNumber","NoSerializerFoundError","TypeError","isBase64","isHex","bigNumberToByteArray","x","isInteger","toFixed","hexString","toString","length","from","toBytes","val","big","undefined","Number","isBigNumber","str2buf","str","enc","bytesToHex","b","hexToBytes","s"],"sources":["../../src/utils/bytes.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 */\nimport BigNumber from 'bignumber.js'\nimport { NoSerializerFoundError, TypeError } from './errors'\nimport { isBase64, isHex } from './string'\n\n/**\n * Convert bignumber to byte array\n * @param x - bignumber instance\n * @returns Buffer\n */\nexport function bigNumberToByteArray (x: BigNumber): Buffer {\n if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)\n let hexString = x.toString(16)\n if (hexString.length % 2 === 1) hexString = '0' + hexString\n return Buffer.from(hexString, 'hex')\n}\n\n/**\n * Convert string, number, or BigNumber to byte array\n * @param val - value to convert\n * @param big - enables force conversion to BigNumber\n * @returns Buffer\n */\nexport function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {\n // Encode a value to bytes.\n // If the value is an int it will be encoded as bytes big endian\n // Raises ValueError if the input is not an int or string\n\n if (val === undefined || val === null) return Buffer.from([])\n if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {\n if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)\n return bigNumberToByteArray(val)\n }\n if (typeof val === 'string') {\n return Buffer.from(val)\n }\n throw new NoSerializerFoundError()\n}\n\n/**\n * Convert a string to a Buffer. If encoding is not specified, hex-encoding\n * will be used if the input is valid hex. If the input is valid base64 but\n * not valid hex, base64 will be used. Otherwise, utf8 will be used.\n * @param str - String to be converted.\n * @param enc - Encoding of the input string.\n * @returns Buffer containing the input data.\n */\nexport function str2buf (str: string, enc?: BufferEncoding): Buffer {\n return Buffer.from(\n str,\n enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)\n )\n}\n\nexport const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString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YE,GAAZ,CAAP;EACD;;EACD,MAAM,IAAIb,sBAAJ,EAAN;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,OAAT,CAAkBC,GAAlB,EAA+BC,GAA/B,EAA6D;EAAA;;EAClE,OAAO,QAAOT,IAAP,CACLQ,GADK,UAELC,GAFK,aAELA,GAFK,cAELA,GAFK,GAEGjB,KAAK,CAACgB,GAAD,CAAL,GAAa,KAAb,GAAqBJ,SAFxB,uCAEuCb,QAAQ,CAACiB,GAAD,CAAR,GAAgB,QAAhB,GAA2BJ,SAFlE,CAAP;AAID;AAED,OAAO,MAAMM,UAAU,GAAIC,CAAD,IAA2B,QAAOX,IAAP,CAAYW,CAAZ,EAAeb,QAAf,CAAwB,KAAxB,CAA9C;AAEP,OAAO,MAAMc,UAAU,GAAIC,CAAD,IAA2B,QAAOb,IAAP,CAAYa,CAAZ,EAAe,KAAf,CAA9C"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SignKeyPair } from 'tweetnacl';
|
|
3
|
+
import { Data } from 'blakejs';
|
|
4
|
+
import { sha256hash, EncodedData, EncodingType } from './encoder';
|
|
5
|
+
export { sha256hash };
|
|
6
|
+
/**
|
|
7
|
+
* Generate address from secret key
|
|
8
|
+
* @param secret - Private key
|
|
9
|
+
* @returns Public key encoded as address
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAddressFromPriv(secret: string | Uint8Array): EncodedData<'ak'>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if address is valid
|
|
14
|
+
* @param address - Address
|
|
15
|
+
* @param prefix - Transaction prefix. Default: 'ak'
|
|
16
|
+
* @returns is valid
|
|
17
|
+
*/
|
|
18
|
+
export declare function isAddressValid(address: string, prefix?: EncodingType): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Generate a random salt (positive integer)
|
|
21
|
+
* @returns random salt
|
|
22
|
+
*/
|
|
23
|
+
export declare function salt(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Converts a positive integer to the smallest possible
|
|
26
|
+
* representation in a binary digit representation
|
|
27
|
+
* @param value - Value to encode
|
|
28
|
+
* @returns Encoded number
|
|
29
|
+
*/
|
|
30
|
+
export declare function encodeUnsigned(value: number): Buffer;
|
|
31
|
+
/**
|
|
32
|
+
* Calculate 256bits Blake2b hash of `input`
|
|
33
|
+
* @param input - Data to hash
|
|
34
|
+
* @returns Hash
|
|
35
|
+
*/
|
|
36
|
+
export declare function hash(input: Data): Buffer;
|
|
37
|
+
/**
|
|
38
|
+
* Compute contract address
|
|
39
|
+
* @param owner - Address of contract owner
|
|
40
|
+
* @param nonce - Round when contract was created
|
|
41
|
+
* @returns Contract address
|
|
42
|
+
*/
|
|
43
|
+
export declare function encodeContractAddress(owner: EncodedData<'ak'>, nonce: number): EncodedData<'ct'>;
|
|
44
|
+
/**
|
|
45
|
+
* Generate keyPair from secret key
|
|
46
|
+
* @param secret - secret key
|
|
47
|
+
* @returns Object with Private(privateKey) and Public(publicKey) keys
|
|
48
|
+
*/
|
|
49
|
+
export declare function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair;
|
|
50
|
+
/**
|
|
51
|
+
* Generate a random ED25519 keypair
|
|
52
|
+
* @param raw - Whether to return raw (binary) keys
|
|
53
|
+
* @returns Key pair
|
|
54
|
+
*/
|
|
55
|
+
export declare function generateKeyPair(raw: true): {
|
|
56
|
+
publicKey: Buffer;
|
|
57
|
+
secretKey: Buffer;
|
|
58
|
+
};
|
|
59
|
+
export declare function generateKeyPair(raw?: false): {
|
|
60
|
+
publicKey: EncodedData<'ak'>;
|
|
61
|
+
secretKey: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Encrypt given data using `password`
|
|
65
|
+
* @param password - Password to encrypt with
|
|
66
|
+
* @param binaryData - Data to encrypt
|
|
67
|
+
* @returns Encrypted data
|
|
68
|
+
*/
|
|
69
|
+
export declare function encryptKey(password: string, binaryData: Uint8Array): Uint8Array;
|
|
70
|
+
/**
|
|
71
|
+
* Decrypt given data using `password`
|
|
72
|
+
* @param password - Password to decrypt with
|
|
73
|
+
* @param encrypted - Data to decrypt
|
|
74
|
+
* @returns Decrypted data
|
|
75
|
+
*/
|
|
76
|
+
export declare function decryptKey(password: string, encrypted: Uint8Array): Uint8Array;
|
|
77
|
+
/**
|
|
78
|
+
* Generate signature
|
|
79
|
+
* @param data - Data to sign
|
|
80
|
+
* @param privateKey - Key to sign with
|
|
81
|
+
* @returns Signature
|
|
82
|
+
*/
|
|
83
|
+
export declare function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array;
|
|
84
|
+
/**
|
|
85
|
+
* Verify that signature was signed by public key
|
|
86
|
+
* @param data - Data to verify
|
|
87
|
+
* @param signature - Signature to verify
|
|
88
|
+
* @param publicKey - Key to verify against
|
|
89
|
+
* @returns Valid?
|
|
90
|
+
*/
|
|
91
|
+
export declare function verify(data: Uint8Array, signature: Uint8Array, publicKey: string | Uint8Array): boolean;
|
|
92
|
+
export declare function messageToHash(message: string): Buffer;
|
|
93
|
+
export declare function signMessage(message: string, privateKey: string | Buffer): Uint8Array;
|
|
94
|
+
export declare function verifyMessage(str: string, signature: Uint8Array, publicKey: string | Uint8Array): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Check key pair for validity
|
|
97
|
+
*
|
|
98
|
+
* Sign a message, and then verifying that signature
|
|
99
|
+
* @param privateKey - Private key to verify
|
|
100
|
+
* @param publicKey - Public key to verify
|
|
101
|
+
* @returns Valid?
|
|
102
|
+
*/
|
|
103
|
+
export declare function isValidKeypair(privateKey: string | Uint8Array, publicKey: string | Uint8Array): boolean;
|
package/es/utils/crypto.mjs
CHANGED
|
@@ -19,48 +19,44 @@ const {
|
|
|
19
19
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
20
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Crypto module
|
|
25
|
-
* @module @aeternity/aepp-sdk/es/utils/crypto
|
|
26
|
-
* @example import { Crypto } from '@aeternity/aepp-sdk'
|
|
27
|
-
*/
|
|
28
22
|
import nacl from 'tweetnacl';
|
|
29
23
|
import aesjs from 'aes-js';
|
|
24
|
+
import _blakejs from 'blakejs';
|
|
25
|
+
const {
|
|
26
|
+
blake2b
|
|
27
|
+
} = _blakejs;
|
|
28
|
+
import _varuintBitcoin from 'varuint-bitcoin';
|
|
29
|
+
const {
|
|
30
|
+
encode: varuintEncode
|
|
31
|
+
} = _varuintBitcoin;
|
|
30
32
|
import { str2buf } from "./bytes.mjs";
|
|
33
|
+
import { concatBuffers } from "./other.mjs";
|
|
31
34
|
import { encode, decode, sha256hash } from "./encoder.mjs";
|
|
32
|
-
import { hash } from "./crypto-ts.mjs";
|
|
33
|
-
import { NotImplementedError } from "./errors.mjs";
|
|
34
|
-
export * from "./crypto-ts.mjs";
|
|
35
35
|
export { sha256hash };
|
|
36
36
|
const Ecb = aesjs.ModeOfOperation.ecb;
|
|
37
37
|
/**
|
|
38
38
|
* Generate address from secret key
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
* @return {String} Public key
|
|
39
|
+
* @param secret - Private key
|
|
40
|
+
* @returns Public key encoded as address
|
|
42
41
|
*/
|
|
43
42
|
|
|
44
43
|
export function getAddressFromPriv(secret) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return encode(publicBuffer, 'ak');
|
|
44
|
+
const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
|
|
45
|
+
const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
|
|
46
|
+
return encode(keys.publicKey, 'ak');
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* Check if address is valid
|
|
53
|
-
* @
|
|
54
|
-
* @param
|
|
55
|
-
* @
|
|
56
|
-
* @return {Boolean} valid
|
|
50
|
+
* @param address - Address
|
|
51
|
+
* @param prefix - Transaction prefix. Default: 'ak'
|
|
52
|
+
* @returns is valid
|
|
57
53
|
*/
|
|
58
54
|
|
|
59
55
|
export function isAddressValid(address) {
|
|
60
56
|
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ak';
|
|
61
57
|
|
|
62
58
|
try {
|
|
63
|
-
decode(address
|
|
59
|
+
decode(address);
|
|
64
60
|
return true;
|
|
65
61
|
} catch (e) {
|
|
66
62
|
return false;
|
|
@@ -68,8 +64,7 @@ export function isAddressValid(address) {
|
|
|
68
64
|
}
|
|
69
65
|
/**
|
|
70
66
|
* Generate a random salt (positive integer)
|
|
71
|
-
* @
|
|
72
|
-
* @return {Number} random salt
|
|
67
|
+
* @returns random salt
|
|
73
68
|
*/
|
|
74
69
|
|
|
75
70
|
export function salt() {
|
|
@@ -78,9 +73,8 @@ export function salt() {
|
|
|
78
73
|
/**
|
|
79
74
|
* Converts a positive integer to the smallest possible
|
|
80
75
|
* representation in a binary digit representation
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
83
|
-
* @return {Buffer} - Encoded data
|
|
76
|
+
* @param value - Value to encode
|
|
77
|
+
* @returns Encoded number
|
|
84
78
|
*/
|
|
85
79
|
|
|
86
80
|
export function encodeUnsigned(value) {
|
|
@@ -88,29 +82,34 @@ export function encodeUnsigned(value) {
|
|
|
88
82
|
|
|
89
83
|
binary.writeUInt32BE(value);
|
|
90
84
|
return binary.slice(binary.findIndex(i => i !== 0));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Calculate 256bits Blake2b hash of `input`
|
|
88
|
+
* @param input - Data to hash
|
|
89
|
+
* @returns Hash
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export function hash(input) {
|
|
93
|
+
return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
|
|
91
94
|
} // Todo Duplicated in tx builder. remove
|
|
92
95
|
|
|
93
96
|
/**
|
|
94
97
|
* Compute contract address
|
|
95
|
-
* @
|
|
96
|
-
* @param
|
|
97
|
-
* @
|
|
98
|
-
* @return {String} - Contract address
|
|
98
|
+
* @param owner - Address of contract owner
|
|
99
|
+
* @param nonce - Round when contract was created
|
|
100
|
+
* @returns Contract address
|
|
99
101
|
*/
|
|
100
102
|
|
|
101
103
|
export function encodeContractAddress(owner, nonce) {
|
|
102
|
-
const publicKey = decode(owner
|
|
103
|
-
|
|
104
|
-
const binary = _Buffer.concat([publicKey, encodeUnsigned(nonce)]);
|
|
105
|
-
|
|
104
|
+
const publicKey = decode(owner);
|
|
105
|
+
const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
|
|
106
106
|
return encode(hash(binary), 'ct');
|
|
107
107
|
} // KEY-PAIR HELPERS
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Generate keyPair from secret key
|
|
111
|
-
* @
|
|
112
|
-
* @
|
|
113
|
-
* @return {Object} - Object with Private(privateKey) and Public(publicKey) keys
|
|
111
|
+
* @param secret - secret key
|
|
112
|
+
* @returns Object with Private(privateKey) and Public(publicKey) keys
|
|
114
113
|
*/
|
|
115
114
|
|
|
116
115
|
export function generateKeyPairFromSecret(secret) {
|
|
@@ -118,14 +117,12 @@ export function generateKeyPairFromSecret(secret) {
|
|
|
118
117
|
}
|
|
119
118
|
/**
|
|
120
119
|
* Generate a random ED25519 keypair
|
|
121
|
-
* @
|
|
122
|
-
* @
|
|
123
|
-
* @return {Object} Key pair
|
|
120
|
+
* @param raw - Whether to return raw (binary) keys
|
|
121
|
+
* @returns Key pair
|
|
124
122
|
*/
|
|
125
123
|
|
|
126
124
|
export function generateKeyPair() {
|
|
127
125
|
let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
128
|
-
// <node>/apps/aens/test/aens_test_utils.erl
|
|
129
126
|
const keyPair = nacl.sign.keyPair();
|
|
130
127
|
|
|
131
128
|
const publicBuffer = _Buffer.from(keyPair.publicKey);
|
|
@@ -146,10 +143,9 @@ export function generateKeyPair() {
|
|
|
146
143
|
}
|
|
147
144
|
/**
|
|
148
145
|
* Encrypt given data using `password`
|
|
149
|
-
* @
|
|
150
|
-
* @param
|
|
151
|
-
* @
|
|
152
|
-
* @return {Uint8Array} Encrypted data
|
|
146
|
+
* @param password - Password to encrypt with
|
|
147
|
+
* @param binaryData - Data to encrypt
|
|
148
|
+
* @returns Encrypted data
|
|
153
149
|
*/
|
|
154
150
|
|
|
155
151
|
export function encryptKey(password, binaryData) {
|
|
@@ -159,10 +155,9 @@ export function encryptKey(password, binaryData) {
|
|
|
159
155
|
}
|
|
160
156
|
/**
|
|
161
157
|
* Decrypt given data using `password`
|
|
162
|
-
* @
|
|
163
|
-
* @param
|
|
164
|
-
* @
|
|
165
|
-
* @return {Buffer} Decrypted data
|
|
158
|
+
* @param password - Password to decrypt with
|
|
159
|
+
* @param encrypted - Data to decrypt
|
|
160
|
+
* @returns Decrypted data
|
|
166
161
|
*/
|
|
167
162
|
|
|
168
163
|
export function decryptKey(password, encrypted) {
|
|
@@ -170,15 +165,14 @@ export function decryptKey(password, encrypted) {
|
|
|
170
165
|
|
|
171
166
|
const hashedPasswordBytes = sha256hash(password);
|
|
172
167
|
const aesEcb = new Ecb(hashedPasswordBytes);
|
|
173
|
-
return
|
|
168
|
+
return aesEcb.decrypt(encryptedBytes);
|
|
174
169
|
} // SIGNATURES
|
|
175
170
|
|
|
176
171
|
/**
|
|
177
172
|
* Generate signature
|
|
178
|
-
* @
|
|
179
|
-
* @param
|
|
180
|
-
* @
|
|
181
|
-
* @return {Buffer|Uint8Array} Signature
|
|
173
|
+
* @param data - Data to sign
|
|
174
|
+
* @param privateKey - Key to sign with
|
|
175
|
+
* @returns Signature
|
|
182
176
|
*/
|
|
183
177
|
|
|
184
178
|
export function sign(data, privateKey) {
|
|
@@ -186,23 +180,22 @@ export function sign(data, privateKey) {
|
|
|
186
180
|
}
|
|
187
181
|
/**
|
|
188
182
|
* Verify that signature was signed by public key
|
|
189
|
-
* @
|
|
190
|
-
* @param
|
|
191
|
-
* @param
|
|
192
|
-
* @
|
|
193
|
-
* @return {Boolean} Valid?
|
|
183
|
+
* @param data - Data to verify
|
|
184
|
+
* @param signature - Signature to verify
|
|
185
|
+
* @param publicKey - Key to verify against
|
|
186
|
+
* @returns Valid?
|
|
194
187
|
*/
|
|
195
188
|
|
|
196
|
-
export function verify(
|
|
197
|
-
|
|
189
|
+
export function verify(data, signature, publicKey) {
|
|
190
|
+
const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
|
|
191
|
+
return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
|
|
198
192
|
}
|
|
199
193
|
export function messageToHash(message) {
|
|
200
194
|
const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
|
|
201
195
|
|
|
202
196
|
const msg = _Buffer.from(message, 'utf8');
|
|
203
197
|
|
|
204
|
-
|
|
205
|
-
return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
|
|
198
|
+
return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
|
|
206
199
|
}
|
|
207
200
|
export function signMessage(message, privateKey) {
|
|
208
201
|
return sign(messageToHash(message), privateKey);
|
|
@@ -214,10 +207,9 @@ export function verifyMessage(str, signature, publicKey) {
|
|
|
214
207
|
* Check key pair for validity
|
|
215
208
|
*
|
|
216
209
|
* Sign a message, and then verifying that signature
|
|
217
|
-
* @
|
|
218
|
-
* @param
|
|
219
|
-
* @
|
|
220
|
-
* @return {Boolean} Valid?
|
|
210
|
+
* @param privateKey - Private key to verify
|
|
211
|
+
* @param publicKey - Public key to verify
|
|
212
|
+
* @returns Valid?
|
|
221
213
|
*/
|
|
222
214
|
|
|
223
215
|
export function isValidKeypair(privateKey, publicKey) {
|