@aeternity/aepp-sdk 13.0.1 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/bin/aesophia_cli +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- 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 +28490 -17706
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +21 -3
- package/es/AeSdkBase.mjs +51 -3
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +9 -14
- package/es/AeSdkMethods.mjs +20 -49
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +1 -1
- package/es/AeSdkWallet.mjs +79 -23
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Middleware.d.ts +38 -0
- package/es/Middleware.mjs +90 -0
- package/es/Middleware.mjs.map +1 -0
- package/es/MiddlewareSubscriber.d.ts +30 -0
- package/es/MiddlewareSubscriber.mjs +198 -0
- package/es/MiddlewareSubscriber.mjs.map +1 -0
- package/es/Node.d.ts +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +57 -3
- package/es/account/Base.mjs +95 -1
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +4 -0
- package/es/account/Generalized.mjs +20 -0
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +4 -0
- package/es/account/Ledger.mjs +20 -0
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +12 -0
- package/es/account/Memory.mjs +52 -0
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +5 -6
- package/es/account/Rpc.mjs +53 -10
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +1 -1
- package/es/aens.mjs +1 -1
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -2
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +19 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +2 -8
- package/es/aepp-wallet-communication/schema.mjs +21 -33
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.mjs +15 -1
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/compiler/models/index.d.ts +1 -7
- package/es/apis/compiler/models/index.mjs.map +1 -1
- package/es/apis/compiler/models/mappers.d.ts +0 -1
- package/es/apis/compiler/models/mappers.mjs +0 -43
- package/es/apis/compiler/models/mappers.mjs.map +1 -1
- package/es/apis/middleware/index.d.ts +2 -0
- package/es/apis/middleware/index.mjs +3 -0
- package/es/apis/middleware/index.mjs.map +1 -0
- package/es/apis/middleware/middleware.d.ts +309 -0
- package/es/apis/middleware/middleware.mjs +1527 -0
- package/es/apis/middleware/middleware.mjs.map +1 -0
- package/es/apis/middleware/models/index.d.ts +1496 -0
- package/es/apis/middleware/models/index.mjs +580 -0
- package/es/apis/middleware/models/index.mjs.map +1 -0
- package/es/apis/middleware/models/mappers.d.ts +102 -0
- package/es/apis/middleware/models/mappers.mjs +3334 -0
- package/es/apis/middleware/models/mappers.mjs.map +1 -0
- package/es/apis/middleware/models/parameters.d.ts +43 -0
- package/es/apis/middleware/models/parameters.mjs +417 -0
- package/es/apis/middleware/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.d.ts +2 -1
- package/es/chain.mjs +5 -3
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +1 -1
- package/es/channel/Base.mjs +1 -4
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +2 -2
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.mjs +7 -5
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.mjs +2 -2
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +21 -0
- package/es/contract/compiler/Base.mjs.map +1 -1
- package/es/contract/compiler/Cli.d.ts +2 -0
- package/es/contract/compiler/Cli.mjs +24 -3
- package/es/contract/compiler/Cli.mjs.map +1 -1
- package/es/contract/compiler/Http.d.ts +2 -0
- package/es/contract/compiler/Http.mjs +22 -2
- package/es/contract/compiler/Http.mjs.map +1 -1
- package/es/contract/compiler/HttpNode.d.ts +1 -0
- package/es/contract/compiler/HttpNode.mjs +5 -0
- package/es/contract/compiler/HttpNode.mjs.map +1 -1
- package/es/contract/delegation-signature.d.ts +2 -1
- package/es/contract/delegation-signature.mjs +39 -8
- package/es/contract/delegation-signature.mjs.map +1 -1
- package/es/contract/ga.mjs.map +1 -1
- package/es/deprecated.d.ts +14 -0
- package/es/deprecated.mjs +22 -0
- package/es/deprecated.mjs.map +1 -0
- package/es/index-browser.d.ts +20 -14
- package/es/index-browser.mjs +19 -15
- package/es/index-browser.mjs.map +1 -1
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +2 -1
- package/es/spend.mjs +4 -2
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +0 -1
- package/es/tx/builder/constants.mjs +26 -24
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/es/tx/builder/field-types/coin-amount.mjs +2 -1
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
- package/es/tx/builder/field-types/deposit.d.ts +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/entry.mjs +2 -1
- package/es/tx/builder/field-types/entry.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/field.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +28 -150
- package/es/tx/builder/field-types/index.mjs +28 -56
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/map.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.mjs +3 -3
- package/es/tx/builder/field-types/mptree.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/string.mjs.map +1 -1
- package/es/tx/builder/field-types/ttl.mjs.map +1 -1
- package/es/tx/builder/field-types/u-int.mjs +1 -1
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/helpers.d.ts +8 -1
- package/es/tx/builder/helpers.mjs +53 -9
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +4 -2
- package/es/tx/builder/index.mjs +0 -1
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +9 -9
- package/es/tx/builder/schema.mjs +11 -10
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/execution-cost.mjs.map +1 -1
- package/es/tx/transaction-signer.mjs.map +1 -1
- package/es/tx/validator.mjs +6 -3
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/amount-formatter.mjs +7 -7
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +6 -8
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +1 -0
- package/es/utils/crypto.mjs +12 -2
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.mjs +3 -3
- package/es/utils/encoder-types.mjs.map +1 -1
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +2 -2
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/other.d.ts +1 -0
- package/es/utils/other.mjs +5 -0
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/es/utils/typed-data.d.ts +45 -0
- package/es/utils/typed-data.mjs +70 -0
- package/es/utils/typed-data.mjs.map +1 -0
- package/package.json +56 -37
- package/src/AeSdkBase.ts +66 -5
- package/src/AeSdkMethods.ts +31 -50
- package/src/AeSdkWallet.ts +63 -17
- package/src/Middleware.ts +141 -0
- package/src/MiddlewareSubscriber.ts +207 -0
- package/src/Node.ts +1 -1
- package/src/account/Base.ts +102 -4
- package/src/account/Generalized.ts +20 -0
- package/src/account/Ledger.ts +20 -0
- package/src/account/Memory.ts +68 -1
- package/src/account/Rpc.ts +54 -7
- package/src/aens.ts +1 -1
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +11 -3
- package/src/aepp-wallet-communication/rpc/types.ts +21 -0
- package/src/aepp-wallet-communication/schema.ts +3 -17
- package/src/aepp-wallet-communication/wallet-detector.ts +1 -2
- package/src/apis/compiler/compiler.ts +8 -1
- package/src/apis/compiler/models/index.ts +1 -8
- package/src/apis/compiler/models/mappers.ts +0 -36
- package/src/apis/middleware/index.ts +2 -0
- package/src/apis/middleware/middleware.ts +1807 -0
- package/src/apis/middleware/models/index.ts +1747 -0
- package/src/apis/middleware/models/mappers.ts +3370 -0
- package/src/apis/middleware/models/parameters.ts +463 -0
- package/src/chain.ts +4 -3
- package/src/channel/Base.ts +5 -5
- package/src/channel/internal.ts +2 -0
- package/src/contract/Contract.ts +2 -1
- package/src/contract/compiler/Base.ts +26 -0
- package/src/contract/compiler/Cli.ts +27 -3
- package/src/contract/compiler/Http.ts +21 -2
- package/src/contract/compiler/HttpNode.ts +6 -0
- package/src/contract/delegation-signature.ts +37 -11
- package/src/deprecated.ts +23 -0
- package/src/index-browser.ts +77 -15
- package/src/spend.ts +2 -2
- package/src/tx/builder/constants.ts +0 -1
- package/src/tx/builder/field-types/coin-amount.ts +2 -1
- package/src/tx/builder/field-types/entry.ts +1 -1
- package/src/tx/builder/field-types/index.ts +28 -58
- package/src/tx/builder/field-types/u-int.ts +1 -1
- package/src/tx/builder/helpers.ts +54 -9
- package/src/tx/builder/index.ts +6 -9
- package/src/tx/validator.ts +4 -2
- package/src/utils/autorest.ts +5 -10
- package/src/utils/crypto.ts +12 -2
- package/src/utils/errors.ts +2 -2
- package/src/utils/other.ts +5 -0
- package/src/utils/typed-data.ts +95 -0
- package/types-legacy/ts4.2/AeSdkBase.d.ts +21 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +9 -14
- package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.2/Middleware.d.ts +46 -0
- package/types-legacy/ts4.2/MiddlewareSubscriber.d.ts +30 -0
- package/types-legacy/ts4.2/Node.d.ts +1 -1
- package/types-legacy/ts4.2/account/Base.d.ts +57 -3
- package/types-legacy/ts4.2/account/Generalized.d.ts +4 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +4 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +12 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +5 -6
- package/types-legacy/ts4.2/aens.d.ts +1 -1
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +19 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -8
- package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +1 -1
- package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -7
- package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +0 -1
- package/types-legacy/ts4.2/apis/middleware/index.d.ts +2 -0
- package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +309 -0
- package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +1496 -0
- package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +102 -0
- package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +43 -0
- package/types-legacy/ts4.2/chain.d.ts +2 -1
- package/types-legacy/ts4.2/channel/Base.d.ts +1 -1
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +21 -0
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +2 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +2 -0
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +1 -0
- package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.2/deprecated.d.ts +14 -0
- package/types-legacy/ts4.2/index-browser.d.ts +20 -14
- package/types-legacy/ts4.2/spend.d.ts +2 -1
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +0 -1
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
- package/types-legacy/ts4.2/tx/builder/helpers.d.ts +8 -1
- package/types-legacy/ts4.2/tx/builder/index.d.ts +4 -2
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +9 -9
- package/types-legacy/ts4.2/utils/crypto.d.ts +1 -0
- package/types-legacy/ts4.2/utils/errors.d.ts +2 -2
- package/types-legacy/ts4.2/utils/other.d.ts +1 -0
- package/types-legacy/ts4.2/utils/typed-data.d.ts +60 -0
- package/types-legacy/ts4.5/AeSdkBase.d.ts +21 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +9 -14
- package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.5/Middleware.d.ts +46 -0
- package/types-legacy/ts4.5/MiddlewareSubscriber.d.ts +30 -0
- package/types-legacy/ts4.5/Node.d.ts +1 -1
- package/types-legacy/ts4.5/account/Base.d.ts +57 -3
- package/types-legacy/ts4.5/account/Generalized.d.ts +4 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +4 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +12 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +5 -6
- package/types-legacy/ts4.5/aens.d.ts +1 -1
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +19 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -8
- package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +1 -1
- package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -7
- package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +0 -1
- package/types-legacy/ts4.5/apis/middleware/index.d.ts +2 -0
- package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +309 -0
- package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +1496 -0
- package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +102 -0
- package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +43 -0
- package/types-legacy/ts4.5/chain.d.ts +2 -1
- package/types-legacy/ts4.5/channel/Base.d.ts +1 -1
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +21 -0
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +2 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +2 -0
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +1 -0
- package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.5/deprecated.d.ts +14 -0
- package/types-legacy/ts4.5/index-browser.d.ts +20 -14
- package/types-legacy/ts4.5/spend.d.ts +2 -1
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +0 -1
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
- package/types-legacy/ts4.5/tx/builder/helpers.d.ts +8 -1
- package/types-legacy/ts4.5/tx/builder/index.d.ts +4 -2
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +9 -9
- package/types-legacy/ts4.5/utils/crypto.d.ts +1 -0
- package/types-legacy/ts4.5/utils/errors.d.ts +2 -2
- package/types-legacy/ts4.5/utils/other.d.ts +1 -0
- package/types-legacy/ts4.5/utils/typed-data.d.ts +60 -0
|
@@ -18,6 +18,12 @@ export default class CompilerHttpNode extends HttpBrowser {
|
|
|
18
18
|
return this.compileBySourceCode(sourceCode, fileSystem);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
override async generateAci(path: string): Promise<Aci> {
|
|
22
|
+
const fileSystem = await getFileSystem(path);
|
|
23
|
+
const sourceCode = await readFile(path, 'utf8');
|
|
24
|
+
return this.generateAciBySourceCode(sourceCode, fileSystem);
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
override async validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean> {
|
|
22
28
|
const fileSystem = await getFileSystem(path);
|
|
23
29
|
const sourceCode = await readFile(path, 'utf8');
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { decode, Encoded } from '../utils/encoder';
|
|
2
|
+
import { ArgumentError } from '../utils/errors';
|
|
2
3
|
import { AensName } from '../tx/builder/constants';
|
|
3
4
|
import AccountBase from '../account/Base';
|
|
4
|
-
import {
|
|
5
|
-
import { isNameValid, produceNameId } from '../tx/builder/helpers';
|
|
5
|
+
import { isNameValid } from '../tx/builder/helpers';
|
|
6
6
|
import Node from '../Node';
|
|
7
7
|
|
|
8
|
+
function ensureOracleQuery(oq: string): asserts oq is Encoded.OracleQueryId {
|
|
9
|
+
if (!oq.startsWith('oq_')) throw new ArgumentError('oq', 'oracle query', oq);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Helper to generate a signature to delegate
|
|
10
14
|
* - pre-claim/claim/transfer/revoke of a name to a contract.
|
|
@@ -17,6 +21,7 @@ import Node from '../Node';
|
|
|
17
21
|
* @param options.onAccount - Account to use
|
|
18
22
|
* @param options.onNode - Node to use
|
|
19
23
|
* @returns Signature
|
|
24
|
+
* @deprecated use methods `sign*DelegationToContract` of Account instance instead
|
|
20
25
|
* @example
|
|
21
26
|
* ```js
|
|
22
27
|
* const aeSdk = new AeSdk({ ... })
|
|
@@ -42,15 +47,36 @@ import Node from '../Node';
|
|
|
42
47
|
export default async function createDelegationSignature(
|
|
43
48
|
contractAddress: Encoded.ContractAddress,
|
|
44
49
|
ids: Array<Encoded.Any | AensName>,
|
|
45
|
-
|
|
50
|
+
{ onAccount, omitAddress, ...options }: {
|
|
51
|
+
omitAddress?: boolean;
|
|
52
|
+
onAccount: AccountBase;
|
|
53
|
+
onNode: Node;
|
|
54
|
+
},
|
|
46
55
|
): Promise<Uint8Array> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (ids.length > 1) throw new ArgumentError('ids', 'shorter than 2', ids);
|
|
57
|
+
const networkId = await options.onNode.getNetworkId();
|
|
58
|
+
if (ids.length === 0) {
|
|
59
|
+
if (omitAddress === true) {
|
|
60
|
+
throw new ArgumentError('omitAddress', 'equal false', omitAddress);
|
|
61
|
+
}
|
|
62
|
+
return decode(await onAccount.signDelegationToContract(contractAddress, { networkId }));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const [payload] = ids;
|
|
66
|
+
if (isNameValid(payload)) {
|
|
67
|
+
if (omitAddress === true) {
|
|
68
|
+
throw new ArgumentError('omitAddress', 'equal false', omitAddress);
|
|
69
|
+
}
|
|
70
|
+
return decode(
|
|
71
|
+
await onAccount.signNameDelegationToContract(contractAddress, payload, { networkId }),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ensureOracleQuery(payload);
|
|
76
|
+
if (omitAddress !== true) {
|
|
77
|
+
throw new ArgumentError('omitAddress', 'equal true', omitAddress);
|
|
78
|
+
}
|
|
79
|
+
return decode(
|
|
80
|
+
await onAccount.signOracleQueryDelegationToContract(contractAddress, payload, { networkId }),
|
|
55
81
|
);
|
|
56
82
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RpcError } from './aepp-wallet-communication/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @category exception
|
|
5
|
+
* @deprecated this exception is not thrown anymore
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
8
|
+
export class RpcBroadcastError extends RpcError {
|
|
9
|
+
static override code = 3;
|
|
10
|
+
|
|
11
|
+
override code = 3;
|
|
12
|
+
|
|
13
|
+
constructor(data?: any) {
|
|
14
|
+
super('Broadcast failed');
|
|
15
|
+
this.data = data;
|
|
16
|
+
this.name = 'RpcBroadcastError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated use isAuctionName instead
|
|
22
|
+
*/
|
|
23
|
+
export const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
|
package/src/index-browser.ts
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export {
|
|
2
|
+
_getPollInterval, InvalidTxError, getHeight, poll, awaitHeight, waitForTxConfirm, sendTransaction,
|
|
3
|
+
getAccount, getBalance, getCurrentGeneration, getGeneration, getMicroBlockTransactions,
|
|
4
|
+
getKeyBlock, getMicroBlockHeader, txDryRun, getContractByteCode, getContract, getName,
|
|
5
|
+
resolveName,
|
|
6
|
+
} from './chain';
|
|
7
|
+
export {
|
|
8
|
+
getAddressFromPriv, isAddressValid, genSalt, encodeUnsigned, hash, encodeContractAddress,
|
|
9
|
+
generateKeyPairFromSecret, generateKeyPair, sign, verify, messageToHash, signMessage,
|
|
10
|
+
verifyMessage, isValidKeypair,
|
|
11
|
+
} from './utils/crypto';
|
|
12
|
+
export { recover, dump } from './utils/keystore';
|
|
13
|
+
export type { Keystore } from './utils/keystore';
|
|
14
|
+
export { toBytes } from './utils/bytes';
|
|
6
15
|
export {
|
|
7
16
|
buildTx, buildTxAsync, buildTxHash, unpackTx, buildContractIdByContractTx,
|
|
8
17
|
} from './tx/builder';
|
|
9
|
-
export
|
|
10
|
-
|
|
18
|
+
export {
|
|
19
|
+
buildContractId, oracleQueryId, produceNameId, commitmentHash, readInt, isNameValid, ensureName,
|
|
20
|
+
getDefaultPointerKey, getMinimumNameFee, computeBidFee, computeAuctionEndBlock, isAuctionName,
|
|
21
|
+
} from './tx/builder/helpers';
|
|
22
|
+
export {
|
|
23
|
+
MAX_AUTH_FUN_GAS, NAME_TTL, NAME_MAX_TTL, NAME_MAX_CLIENT_TTL, CLIENT_TTL, MIN_GAS_PRICE,
|
|
24
|
+
NAME_FEE_MULTIPLIER, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUT_BLOCKS, NAME_MAX_LENGTH_FEE,
|
|
25
|
+
NAME_BID_RANGES, ConsensusProtocolVersion, VmVersion, AbiVersion, Tag,
|
|
26
|
+
} from './tx/builder/constants';
|
|
27
|
+
export type { Int, AensName } from './tx/builder/constants';
|
|
11
28
|
// TODO: move to constants
|
|
12
29
|
export {
|
|
13
30
|
ORACLE_TTL_TYPES, ORACLE_TTL, QUERY_TTL, RESPONSE_TTL, DRY_RUN_ACCOUNT, CallReturnType,
|
|
@@ -16,17 +33,30 @@ export {
|
|
|
16
33
|
getExecutionCost, getExecutionCostBySignedTx, getExecutionCostUsingNode,
|
|
17
34
|
} from './tx/execution-cost';
|
|
18
35
|
export { default as getTransactionSignerAddress } from './tx/transaction-signer';
|
|
19
|
-
export
|
|
20
|
-
|
|
36
|
+
export {
|
|
37
|
+
AE_AMOUNT_FORMATS, formatAmount, toAe, toAettos, prefixedAmount,
|
|
38
|
+
} from './utils/amount-formatter';
|
|
39
|
+
export {
|
|
40
|
+
DerivationError, deriveChild, derivePathFromKey, getMasterKeyFromSeed, derivePathFromSeed,
|
|
41
|
+
getKeyPair, generateSaveHDWalletFromSeed, getSaveHDWalletAccounts, getHdWalletAccountFromSeed,
|
|
42
|
+
} from './utils/hd-wallet';
|
|
21
43
|
export {
|
|
22
44
|
encode, decode, Encoding, Encoded,
|
|
23
45
|
} from './utils/encoder';
|
|
24
|
-
export
|
|
46
|
+
export {
|
|
47
|
+
encodeFateValue, decodeFateValue, hashTypedData, hashDomain, hashJson,
|
|
48
|
+
} from './utils/typed-data';
|
|
49
|
+
export {
|
|
50
|
+
aensRevoke, aensUpdate, aensTransfer, aensQuery, aensClaim, aensPreclaim, aensBid,
|
|
51
|
+
} from './aens';
|
|
25
52
|
export { default as Contract } from './contract/Contract';
|
|
26
53
|
export type { ContractMethodsBase } from './contract/Contract';
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
54
|
+
export {
|
|
55
|
+
pollForQueries, pollForQueryResponse, getQueryObject, postQueryToOracle, extendOracleTtl,
|
|
56
|
+
respondToQuery, getOracleObject, registerOracle,
|
|
57
|
+
} from './oracle';
|
|
58
|
+
export { spend, transferFunds, payForTransaction } from './spend';
|
|
59
|
+
export { createGeneralizedAccount, buildAuthTxHash, buildAuthTxHashByGaMetaTx } from './contract/ga';
|
|
30
60
|
|
|
31
61
|
export { default as AeSdkMethods } from './AeSdkMethods';
|
|
32
62
|
export { default as AeSdkBase } from './AeSdkBase';
|
|
@@ -43,10 +73,42 @@ export { default as AccountLedgerFactory } from './account/LedgerFactory';
|
|
|
43
73
|
export { default as CompilerBase } from './contract/compiler/Base';
|
|
44
74
|
export { default as CompilerHttp } from './contract/compiler/Http';
|
|
45
75
|
export { default as Channel } from './channel/Contract';
|
|
76
|
+
export {
|
|
77
|
+
default as _MiddlewareSubscriber,
|
|
78
|
+
MiddlewareSubscriberError as _MiddlewareSubscriberError,
|
|
79
|
+
MiddlewareSubscriberDisconnected as _MiddlewareSubscriberDisconnected,
|
|
80
|
+
} from './MiddlewareSubscriber';
|
|
81
|
+
export { default as _Middleware } from './Middleware';
|
|
46
82
|
|
|
47
83
|
export { default as connectionProxy } from './aepp-wallet-communication/connection-proxy';
|
|
48
|
-
export
|
|
84
|
+
export {
|
|
85
|
+
MESSAGE_DIRECTION, WALLET_TYPE, SUBSCRIPTION_TYPES, METHODS, RPC_STATUS, RpcError,
|
|
86
|
+
RpcInvalidTransactionError, RpcRejectedByUserError, RpcUnsupportedProtocolError,
|
|
87
|
+
RpcConnectionDenyError, RpcNotAuthorizeError, RpcPermissionDenyError, RpcInternalError,
|
|
88
|
+
RpcMethodNotFoundError,
|
|
89
|
+
} from './aepp-wallet-communication/schema';
|
|
49
90
|
export { default as walletDetector } from './aepp-wallet-communication/wallet-detector';
|
|
50
91
|
export { default as BrowserRuntimeConnection } from './aepp-wallet-communication/connection/BrowserRuntime';
|
|
51
92
|
export { default as BrowserWindowMessageConnection } from './aepp-wallet-communication/connection/BrowserWindowMessage';
|
|
52
|
-
export
|
|
93
|
+
export {
|
|
94
|
+
BaseError, AccountError, AensError, AeppError, ChannelError, CompilerError, ContractError,
|
|
95
|
+
CryptographyError, NodeError, TransactionError, WalletError, ArgumentError, IllegalArgumentError,
|
|
96
|
+
ArgumentCountMismatchError, InsufficientBalanceError, MissingParamError, NoSerializerFoundError,
|
|
97
|
+
RequestTimedOutError, TxTimedOutError, TypeError, UnsupportedPlatformError,
|
|
98
|
+
UnsupportedProtocolError, NotImplementedError, UnsupportedVersionError, InternalError,
|
|
99
|
+
UnexpectedTsError, UnavailableAccountError, AensPointerContextError, InsufficientNameFeeError,
|
|
100
|
+
InvalidAensNameError, InvalidRpcMessageError, MissingCallbackError, UnAuthorizedAccountError,
|
|
101
|
+
UnknownRpcClientError, UnsubscribedAccountError, ChannelCallError, ChannelConnectionError,
|
|
102
|
+
ChannelPingTimedOutError, UnexpectedChannelMessageError, ChannelIncomingMessageError,
|
|
103
|
+
UnknownChannelStateError, InvalidAuthDataError, BytecodeMismatchError, DuplicateContractError,
|
|
104
|
+
InactiveContractError, InvalidMethodInvocationError, MissingContractAddressError,
|
|
105
|
+
MissingContractDefError, MissingFunctionNameError, NodeInvocationError,
|
|
106
|
+
NoSuchContractFunctionError, NotPayableFunctionError, MissingEventDefinitionError,
|
|
107
|
+
AmbiguousEventDefinitionError, InvalidChecksumError, InvalidPasswordError,
|
|
108
|
+
MerkleTreeHashMismatchError, MissingNodeInTreeError, UnknownNodeLengthError,
|
|
109
|
+
UnknownPathNibbleError, DuplicateNodeError, NodeNotFoundError, DecodeError, PayloadLengthError,
|
|
110
|
+
DryRunError, IllegalBidFeeError, InvalidSignatureError, PrefixNotFoundError, SchemaNotFoundError,
|
|
111
|
+
TagNotFoundError, TxNotInChainError, AlreadyConnectedError, NoWalletConnectedError,
|
|
112
|
+
RpcConnectionError,
|
|
113
|
+
} from './utils/errors';
|
|
114
|
+
export { RpcBroadcastError, NAME_BID_MAX_LENGTH } from './deprecated';
|
package/src/spend.ts
CHANGED
|
@@ -60,11 +60,11 @@ interface SpendOptions extends SpendOptionsType {}
|
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export async function transferFunds(
|
|
63
|
-
fraction: number | string,
|
|
63
|
+
fraction: number | string, // TODO: accept only number
|
|
64
64
|
recipientIdOrName: AensName | Encoded.AccountAddress,
|
|
65
65
|
options: TransferFundsOptions,
|
|
66
66
|
): ReturnType<typeof sendTransaction> {
|
|
67
|
-
if (fraction < 0 || fraction > 1) {
|
|
67
|
+
if (+fraction < 0 || +fraction > 1) {
|
|
68
68
|
throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);
|
|
69
69
|
}
|
|
70
70
|
const recipientId = await resolveName<Encoding.AccountAddress>(
|
|
@@ -20,7 +20,6 @@ export const NAME_FEE_BID_INCREMENT = 0.05; // # the increment is in percentage
|
|
|
20
20
|
export const NAME_BID_TIMEOUT_BLOCKS = 480; // # ~1 day
|
|
21
21
|
// # this is the max length for a domain that requires a base fee to be paid
|
|
22
22
|
export const NAME_MAX_LENGTH_FEE = 31;
|
|
23
|
-
export const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
|
|
24
23
|
// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
|
|
25
24
|
// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
|
|
26
25
|
// # bid ranges:
|
|
@@ -5,7 +5,8 @@ import { AE_AMOUNT_FORMATS, formatAmount } from '../../../utils/amount-formatter
|
|
|
5
5
|
export default {
|
|
6
6
|
...uInt,
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
serializeAettos(value: string | undefined, params: {}): string {
|
|
9
10
|
return value ?? '0';
|
|
10
11
|
},
|
|
11
12
|
|
|
@@ -29,7 +29,7 @@ export default function genEntryField<T extends Tag = Tag>(tag?: T): {
|
|
|
29
29
|
|
|
30
30
|
deserialize(buf, { unpackTx }) {
|
|
31
31
|
const tx = unpackTx(encode(buf, Encoding.Transaction));
|
|
32
|
-
if (tag != null && tx.tag !== tag) throw new ArgumentError('Tag', tag, tx.tag);
|
|
32
|
+
if (tag != null && tx.tag !== tag) throw new ArgumentError('Tag', Tag[tag], Tag[tx.tag]);
|
|
33
33
|
return tx;
|
|
34
34
|
},
|
|
35
35
|
};
|
|
@@ -1,61 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
// TODO: remove after fixing https://github.com/Gerrit0/typedoc-plugin-missing-exports/issues/15
|
|
31
|
-
const abiVersion = _abiVersion;
|
|
32
|
-
const address = _address;
|
|
33
|
-
const array = _array;
|
|
34
|
-
const boolean = _boolean;
|
|
35
|
-
const coinAmount = _coinAmount;
|
|
36
|
-
const ctVersion = _ctVersion;
|
|
37
|
-
const deposit = _deposit;
|
|
38
|
-
const encoded = _encoded;
|
|
39
|
-
const entry = _entry;
|
|
40
|
-
const enumeration = _enumeration;
|
|
41
|
-
const fee = _fee;
|
|
42
|
-
const field = _field;
|
|
43
|
-
const gasLimit = _gasLimit;
|
|
44
|
-
const gasPrice = _gasPrice;
|
|
45
|
-
const map = _map;
|
|
46
|
-
const mptree = _mptree;
|
|
47
|
-
const name = _name;
|
|
48
|
-
const nameFee = _nameFee;
|
|
49
|
-
const nameId = _nameId;
|
|
50
|
-
const nonce = _nonce;
|
|
51
|
-
const pointers = _pointers;
|
|
52
|
-
const raw = _raw;
|
|
53
|
-
const shortUInt = _shortUInt;
|
|
54
|
-
const shortUIntConst = _shortUIntConst;
|
|
55
|
-
const string = _string;
|
|
56
|
-
const ttl = _ttl;
|
|
57
|
-
const uInt = _uInt;
|
|
58
|
-
const wrapped = _wrapped;
|
|
1
|
+
import abiVersion from './abi-version';
|
|
2
|
+
import address from './address';
|
|
3
|
+
import array from './array';
|
|
4
|
+
import boolean from './boolean';
|
|
5
|
+
import coinAmount from './coin-amount';
|
|
6
|
+
import ctVersion from './ct-version';
|
|
7
|
+
import deposit from './deposit';
|
|
8
|
+
import encoded from './encoded';
|
|
9
|
+
import entry from './entry';
|
|
10
|
+
import enumeration from './enumeration';
|
|
11
|
+
import fee from './fee';
|
|
12
|
+
import field from './field';
|
|
13
|
+
import gasLimit from './gas-limit';
|
|
14
|
+
import gasPrice from './gas-price';
|
|
15
|
+
import map from './map';
|
|
16
|
+
import mptree from './mptree';
|
|
17
|
+
import name from './name';
|
|
18
|
+
import nameFee from './name-fee';
|
|
19
|
+
import nameId from './name-id';
|
|
20
|
+
import nonce from './nonce';
|
|
21
|
+
import pointers from './pointers';
|
|
22
|
+
import raw from './raw';
|
|
23
|
+
import shortUInt from './short-u-int';
|
|
24
|
+
import shortUIntConst from './short-u-int-const';
|
|
25
|
+
import string from './string';
|
|
26
|
+
import ttl from './ttl';
|
|
27
|
+
import uInt from './u-int';
|
|
28
|
+
import wrapped from './wrapped';
|
|
59
29
|
|
|
60
30
|
export type BinaryData = Buffer | Buffer[] | Buffer[][]
|
|
61
31
|
| Array<[Buffer, Array<[Buffer, Buffer[]]>]>;
|
|
@@ -5,7 +5,7 @@ import { toBytes } from '../../../utils/bytes';
|
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
serialize(value: Int): Buffer {
|
|
8
|
-
if (value < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
|
|
8
|
+
if (+value < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
|
|
9
9
|
return toBytes(value, true);
|
|
10
10
|
},
|
|
11
11
|
|
|
@@ -59,6 +59,39 @@ export function oracleQueryId(
|
|
|
59
59
|
return encode(b2bHash, Encoding.OracleQueryId);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const AENS_SUFFIX = '.chain';
|
|
63
|
+
|
|
64
|
+
export function nameToPunycode(maybeName: string): AensName {
|
|
65
|
+
const [name, suffix, ...other] = maybeName.split('.');
|
|
66
|
+
if (other.length !== 0) throw new ArgumentError('aens name', 'including only one dot', maybeName);
|
|
67
|
+
if (suffix !== AENS_SUFFIX.slice(1)) {
|
|
68
|
+
throw new ArgumentError('aens name', `suffixed with ${AENS_SUFFIX}`, maybeName);
|
|
69
|
+
}
|
|
70
|
+
if (/\p{Emoji_Presentation}/u.test(name)) {
|
|
71
|
+
throw new ArgumentError('aens name', 'not containing emoji', maybeName);
|
|
72
|
+
}
|
|
73
|
+
let punycode;
|
|
74
|
+
try {
|
|
75
|
+
const u = new URL(`http://${name}.${suffix}`);
|
|
76
|
+
if (u.username + u.password + u.port + u.search + u.hash !== '' || u.pathname !== '/') {
|
|
77
|
+
throw new ArgumentError('aens name', 'valid', maybeName);
|
|
78
|
+
}
|
|
79
|
+
punycode = u.host;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof TypeError && error.message.includes('Invalid URL')) {
|
|
82
|
+
throw new ArgumentError('aens name', 'valid', maybeName);
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (!/^[a-z0-9.-]+$/i.test(punycode)) {
|
|
87
|
+
throw new ArgumentError('aens name', 'without illegal chars', maybeName);
|
|
88
|
+
}
|
|
89
|
+
if (punycode.length > 63 + AENS_SUFFIX.length) {
|
|
90
|
+
throw new ArgumentError('aens name', 'not too long', maybeName);
|
|
91
|
+
}
|
|
92
|
+
return punycode as AensName;
|
|
93
|
+
}
|
|
94
|
+
|
|
62
95
|
/**
|
|
63
96
|
* Encode an AENS name
|
|
64
97
|
* @category AENS
|
|
@@ -66,7 +99,7 @@ export function oracleQueryId(
|
|
|
66
99
|
* @returns `nm_` prefixed encoded AENS name
|
|
67
100
|
*/
|
|
68
101
|
export function produceNameId(name: AensName): Encoded.Name {
|
|
69
|
-
return encode(hash(name
|
|
102
|
+
return encode(hash(nameToPunycode(name)), Encoding.Name);
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
/**
|
|
@@ -83,7 +116,7 @@ export function commitmentHash(
|
|
|
83
116
|
): Encoded.Commitment {
|
|
84
117
|
return encode(
|
|
85
118
|
hash(concatBuffers([
|
|
86
|
-
Buffer.from(name
|
|
119
|
+
Buffer.from(nameToPunycode(name)),
|
|
87
120
|
Buffer.from(salt.toString(16).padStart(64, '0'), 'hex'),
|
|
88
121
|
])),
|
|
89
122
|
Encoding.Commitment,
|
|
@@ -100,16 +133,28 @@ export function readInt(buf: Buffer = Buffer.from([])): string {
|
|
|
100
133
|
return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);
|
|
101
134
|
}
|
|
102
135
|
|
|
103
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Ensure that name is valid AENS name, would throw an exception otherwise
|
|
138
|
+
* @category AENS
|
|
139
|
+
* @param name - AENS name
|
|
140
|
+
*/
|
|
141
|
+
export function ensureName(maybeName: string): asserts maybeName is AensName {
|
|
142
|
+
nameToPunycode(maybeName);
|
|
143
|
+
}
|
|
104
144
|
|
|
105
145
|
/**
|
|
106
146
|
* Is AENS name valid
|
|
107
147
|
* @category AENS
|
|
108
148
|
* @param name - AENS name
|
|
109
149
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
150
|
+
// TODO: consider renaming to isName
|
|
151
|
+
export function isNameValid(maybeName: string): maybeName is AensName {
|
|
152
|
+
try {
|
|
153
|
+
ensureName(maybeName);
|
|
154
|
+
return true;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
113
158
|
}
|
|
114
159
|
|
|
115
160
|
const encodingToPointerKey = [
|
|
@@ -145,7 +190,7 @@ export function getDefaultPointerKey(
|
|
|
145
190
|
* @returns the minimum fee for the AENS name auction
|
|
146
191
|
*/
|
|
147
192
|
export function getMinimumNameFee(name: AensName): BigNumber {
|
|
148
|
-
const nameLength = name.length - AENS_SUFFIX.length;
|
|
193
|
+
const nameLength = nameToPunycode(name).length - AENS_SUFFIX.length;
|
|
149
194
|
return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];
|
|
150
195
|
}
|
|
151
196
|
|
|
@@ -181,7 +226,7 @@ export function computeBidFee(
|
|
|
181
226
|
* @returns Auction end height
|
|
182
227
|
*/
|
|
183
228
|
export function computeAuctionEndBlock(name: AensName, claimHeight: number): number {
|
|
184
|
-
const length = name.length - AENS_SUFFIX.length;
|
|
229
|
+
const length = nameToPunycode(name).length - AENS_SUFFIX.length;
|
|
185
230
|
const h = (length <= 4 ? 62 * NAME_BID_TIMEOUT_BLOCKS : null)
|
|
186
231
|
?? (length <= 8 ? 31 * NAME_BID_TIMEOUT_BLOCKS : null)
|
|
187
232
|
?? (length <= 12 ? NAME_BID_TIMEOUT_BLOCKS : null)
|
|
@@ -194,5 +239,5 @@ export function computeAuctionEndBlock(name: AensName, claimHeight: number): num
|
|
|
194
239
|
* @category AENS
|
|
195
240
|
*/
|
|
196
241
|
export function isAuctionName(name: AensName): boolean {
|
|
197
|
-
return name.length < 13 + AENS_SUFFIX.length;
|
|
242
|
+
return nameToPunycode(name).length < 13 + AENS_SUFFIX.length;
|
|
198
243
|
}
|
package/src/tx/builder/index.ts
CHANGED
|
@@ -23,6 +23,9 @@ export function getSchema(tag: Tag, version?: number): Array<[string, Field]> {
|
|
|
23
23
|
return Object.entries(schema);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
type TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees
|
|
27
|
+
| Encoding.CallStateTree;
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* Build transaction hash
|
|
28
31
|
* @category transaction builder
|
|
@@ -31,15 +34,9 @@ export function getSchema(tag: Tag, version?: number): Array<[string, Field]> {
|
|
|
31
34
|
* @param options.prefix - Prefix of transaction
|
|
32
35
|
* @returns object Base64Check transaction hash with 'tx_' prefix
|
|
33
36
|
*/
|
|
34
|
-
export function buildTx<
|
|
35
|
-
E extends Encoding = Encoding.Transaction,
|
|
36
|
-
>(
|
|
37
|
+
export function buildTx<E extends TxEncoding = Encoding.Transaction>(
|
|
37
38
|
params: TxParams,
|
|
38
|
-
{
|
|
39
|
-
prefix,
|
|
40
|
-
}: {
|
|
41
|
-
prefix?: E;
|
|
42
|
-
} = {},
|
|
39
|
+
{ prefix }: { prefix?: E } = {},
|
|
43
40
|
): Encoded.Generic<E> {
|
|
44
41
|
const schema = getSchema(params.tag, params.version);
|
|
45
42
|
|
|
@@ -92,7 +89,7 @@ export async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Trans
|
|
|
92
89
|
* @returns Object with transaction param's
|
|
93
90
|
*/
|
|
94
91
|
export function unpackTx<TxType extends Tag>(
|
|
95
|
-
encodedTx: Encoded.
|
|
92
|
+
encodedTx: Encoded.Generic<TxEncoding>,
|
|
96
93
|
txType?: TxType,
|
|
97
94
|
): TxUnpacked & { tag: TxType } {
|
|
98
95
|
const binary = rlpDecode(decode(encodedTx));
|
package/src/tx/validator.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RestError } from '@azure/core-rest-pipeline';
|
|
1
2
|
import { hash, verify } from '../utils/crypto';
|
|
2
3
|
import { TxUnpacked } from './builder/schema.generated';
|
|
3
4
|
import { CtVersion, ProtocolToVmAbi } from './builder/field-types/ct-version';
|
|
@@ -143,6 +144,7 @@ validators.push(
|
|
|
143
144
|
return [{ message, key: 'InvalidAccountType', checkedKeys: ['tag'] }];
|
|
144
145
|
},
|
|
145
146
|
// TODO: revert nonce check
|
|
147
|
+
// TODO: ensure nonce valid when paying for own tx
|
|
146
148
|
(tx, { consensusProtocolVersion }) => {
|
|
147
149
|
const oracleCall = Tag.Oracle === tx.tag || Tag.OracleRegisterTx === tx.tag;
|
|
148
150
|
const contractCreate = Tag.ContractCreateTx === tx.tag || Tag.GaAttachTx === tx.tag;
|
|
@@ -183,9 +185,9 @@ validators.push(
|
|
|
183
185
|
checkedKeys: ['contractId'],
|
|
184
186
|
}];
|
|
185
187
|
} catch (error) {
|
|
186
|
-
if (error.response?.
|
|
188
|
+
if (!(error instanceof RestError) || error.response?.bodyAsText == null) throw error;
|
|
187
189
|
return [{
|
|
188
|
-
message: error.response.
|
|
190
|
+
message: JSON.parse(error.response.bodyAsText).reason, // TODO: use parsedBody instead
|
|
189
191
|
key: 'ContractNotFound',
|
|
190
192
|
checkedKeys: ['contractId'],
|
|
191
193
|
}];
|
package/src/utils/autorest.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pi
|
|
|
2
2
|
import { AdditionalPolicyConfig } from '@azure/core-client';
|
|
3
3
|
import { pause } from './other';
|
|
4
4
|
import semverSatisfies from './semver-satisfies';
|
|
5
|
-
import {
|
|
5
|
+
import { UnsupportedVersionError } from './errors';
|
|
6
6
|
|
|
7
7
|
export const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {
|
|
8
8
|
const requestQueues = new Map<string, Promise<unknown>>();
|
|
@@ -126,22 +126,17 @@ export const genRetryOnFailurePolicy = (
|
|
|
126
126
|
const intervalSum = intervals.reduce((a, b) => a + b);
|
|
127
127
|
const intervalsInMs = intervals.map((el) => (el / intervalSum) * retryOverallDelay);
|
|
128
128
|
|
|
129
|
-
let error
|
|
129
|
+
let error = new RestError('Not expected to be thrown');
|
|
130
130
|
for (let attempt = 0; attempt <= retryCount; attempt += 1) {
|
|
131
|
-
if (
|
|
132
|
-
if (
|
|
133
|
-
!(error instanceof RestError)
|
|
134
|
-
|| statusesToNotRetry.includes(error.response?.status ?? 0)
|
|
135
|
-
) throw error;
|
|
136
|
-
await pause(intervalsInMs[attempt - 1]);
|
|
137
|
-
}
|
|
131
|
+
if (attempt !== 0) await pause(intervalsInMs[attempt - 1]);
|
|
138
132
|
try {
|
|
139
133
|
return await next(request);
|
|
140
134
|
} catch (e) {
|
|
135
|
+
if (!(e instanceof RestError)) throw e;
|
|
136
|
+
if (statusesToNotRetry.includes(e.response?.status ?? 0)) throw e;
|
|
141
137
|
error = e;
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
|
-
if (error == null) throw new UnexpectedTsError();
|
|
145
140
|
throw error;
|
|
146
141
|
},
|
|
147
142
|
},
|
package/src/utils/crypto.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { concatBuffers } from './other';
|
|
|
8
8
|
import {
|
|
9
9
|
decode, encode, Encoded, Encoding,
|
|
10
10
|
} from './encoder';
|
|
11
|
+
import { ArgumentError } from './errors';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Generate address from secret key
|
|
@@ -32,6 +33,10 @@ export function isAddressValid(
|
|
|
32
33
|
): boolean {
|
|
33
34
|
try {
|
|
34
35
|
decode(address as Encoded.Generic<typeof prefix>);
|
|
36
|
+
const actualPrefix = address.split('_')[0];
|
|
37
|
+
if (actualPrefix !== prefix) {
|
|
38
|
+
throw new ArgumentError('Encoded string type', prefix, actualPrefix);
|
|
39
|
+
}
|
|
35
40
|
return true;
|
|
36
41
|
} catch (e) {
|
|
37
42
|
return false;
|
|
@@ -152,10 +157,13 @@ export function verify(
|
|
|
152
157
|
return nacl.sign.detached.verify(data, signature, decode(address));
|
|
153
158
|
}
|
|
154
159
|
|
|
160
|
+
const messagePrefix = Buffer.from('aeternity Signed Message:\n', 'utf8');
|
|
161
|
+
export const messagePrefixLength = varuintEncode(messagePrefix.length);
|
|
162
|
+
|
|
163
|
+
// TODO: consider rename to hashMessage
|
|
155
164
|
export function messageToHash(message: string): Buffer {
|
|
156
|
-
const p = Buffer.from('aeternity Signed Message:\n', 'utf8');
|
|
157
165
|
const msg = Buffer.from(message, 'utf8');
|
|
158
|
-
return hash(concatBuffers([
|
|
166
|
+
return hash(concatBuffers([messagePrefixLength, messagePrefix, varuintEncode(msg.length), msg]));
|
|
159
167
|
}
|
|
160
168
|
|
|
161
169
|
export function signMessage(message: string, privateKey: string | Buffer): Uint8Array {
|
|
@@ -169,6 +177,8 @@ export function signMessage(message: string, privateKey: string | Buffer): Uint8
|
|
|
169
177
|
* @param address - Address to verify against
|
|
170
178
|
* @returns is data was signed by address
|
|
171
179
|
*/
|
|
180
|
+
// TODO: deprecate in favour of `verify(messageToHash(message), ...`, also the name is confusing
|
|
181
|
+
// it should contain "signature"
|
|
172
182
|
export function verifyMessage(
|
|
173
183
|
message: string,
|
|
174
184
|
signature: Uint8Array,
|
package/src/utils/errors.ts
CHANGED
|
@@ -401,11 +401,11 @@ export class UnexpectedChannelMessageError extends ChannelError {
|
|
|
401
401
|
* @category exception
|
|
402
402
|
*/
|
|
403
403
|
export class ChannelIncomingMessageError extends ChannelError {
|
|
404
|
-
handlerError:
|
|
404
|
+
handlerError: Error;
|
|
405
405
|
|
|
406
406
|
incomingMessage: { [key: string]: any };
|
|
407
407
|
|
|
408
|
-
constructor(handlerError:
|
|
408
|
+
constructor(handlerError: Error, incomingMessage: { [key: string]: any }) {
|
|
409
409
|
super(handlerError.message);
|
|
410
410
|
this.handlerError = handlerError;
|
|
411
411
|
this.incomingMessage = incomingMessage;
|
package/src/utils/other.ts
CHANGED
|
@@ -57,3 +57,8 @@ export function isAccountNotFoundError(error: Error): boolean {
|
|
|
57
57
|
export type UnionToIntersection<Union> =
|
|
58
58
|
(Union extends any ? (k: Union) => void : never) extends ((k: infer Intersection) => void)
|
|
59
59
|
? Intersection : never;
|
|
60
|
+
|
|
61
|
+
export function ensureError(error: unknown): asserts error is Error {
|
|
62
|
+
if (error instanceof Error) return;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|