@aeternity/aepp-sdk 13.0.1 → 13.1.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 +26702 -16514
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkBase.d.ts +11 -3
- package/es/AeSdkBase.mjs +24 -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.mjs +28 -5
- 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 +14 -2
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +1 -0
- package/es/account/Generalized.mjs +5 -0
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +1 -0
- package/es/account/Ledger.mjs +5 -0
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/Memory.d.ts +2 -0
- package/es/account/Memory.mjs +18 -0
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +1 -6
- package/es/account/Rpc.mjs +24 -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/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 +10 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +1 -8
- package/es/aepp-wallet-communication/schema.mjs +1 -14
- 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 +364 -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/chain.d.ts +2 -1
- package/es/chain.mjs +4 -2
- 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/internal.mjs +2 -0
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.mjs +1 -1
- 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/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/tx/builder/constants.d.ts +0 -1
- package/es/tx/builder/constants.mjs +0 -1
- package/es/tx/builder/constants.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/deposit.d.ts +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/index.d.ts +2 -2
- 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/validator.mjs +6 -3
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/autorest.mjs +6 -8
- package/es/utils/autorest.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/errors.d.ts +2 -2
- package/es/utils/errors.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/typed-data.d.ts +45 -0
- package/es/utils/typed-data.mjs +71 -0
- package/es/utils/typed-data.mjs.map +1 -0
- package/package.json +23 -4
- package/src/AeSdkBase.ts +30 -5
- package/src/AeSdkMethods.ts +31 -50
- package/src/AeSdkWallet.ts +27 -5
- package/src/Middleware.ts +141 -0
- package/src/MiddlewareSubscriber.ts +207 -0
- package/src/Node.ts +1 -1
- package/src/account/Base.ts +20 -3
- package/src/account/Generalized.ts +5 -0
- package/src/account/Ledger.ts +5 -0
- package/src/account/Memory.ts +15 -0
- package/src/account/Rpc.ts +19 -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 +11 -0
- package/src/aepp-wallet-communication/schema.ts +2 -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 +3 -2
- package/src/channel/Base.ts +5 -5
- package/src/channel/internal.ts +2 -0
- package/src/contract/Contract.ts +1 -0
- 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/deprecated.ts +23 -0
- package/src/index-browser.ts +77 -15
- 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/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 +11 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +9 -14
- 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 +14 -2
- package/types-legacy/ts4.2/account/Generalized.d.ts +1 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +1 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +2 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +1 -6
- package/types-legacy/ts4.2/aens.d.ts +1 -1
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +10 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +1 -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/deprecated.d.ts +14 -0
- package/types-legacy/ts4.2/index-browser.d.ts +20 -14
- 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 +2 -2
- 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 +11 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +9 -14
- 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 +14 -2
- package/types-legacy/ts4.5/account/Generalized.d.ts +1 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +1 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +2 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +1 -6
- package/types-legacy/ts4.5/aens.d.ts +1 -1
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +10 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +1 -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/deprecated.d.ts +14 -0
- package/types-legacy/ts4.5/index-browser.d.ts +20 -14
- 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 +2 -2
- 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
|
@@ -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';
|
|
@@ -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
|
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// js extension is required for mjs build
|
|
2
|
+
// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
|
|
3
|
+
// eslint-disable-next-line import/extensions
|
|
4
|
+
import ContractByteArrayEncoder from '@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js';
|
|
5
|
+
// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
|
|
6
|
+
// eslint-disable-next-line import/extensions
|
|
7
|
+
import AciTypeResolver from '@aeternity/aepp-calldata/src/AciTypeResolver.js';
|
|
8
|
+
import canonicalize from 'canonicalize';
|
|
9
|
+
import { Encoded, decode } from './encoder';
|
|
10
|
+
import { hash, messagePrefixLength } from './crypto';
|
|
11
|
+
import { concatBuffers } from './other';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hashes arbitrary object, can be used to inline the aci hash to contract source code
|
|
15
|
+
*/
|
|
16
|
+
export function hashJson(data: unknown): Buffer {
|
|
17
|
+
return hash(canonicalize(data) ?? '');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215
|
|
21
|
+
// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129
|
|
22
|
+
export type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'
|
|
23
|
+
| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'
|
|
24
|
+
| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'
|
|
25
|
+
| { 'Set.set': readonly [AciValue] }
|
|
26
|
+
| { bytes: number }
|
|
27
|
+
| { list: readonly [AciValue] }
|
|
28
|
+
| { map: readonly [AciValue, AciValue] }
|
|
29
|
+
| { tuple: readonly AciValue[] }
|
|
30
|
+
| { record: ReadonlyArray<{ name: string; type: AciValue }> }
|
|
31
|
+
| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }
|
|
32
|
+
| { option: readonly [AciValue] }
|
|
33
|
+
| { oracle: readonly [AciValue, AciValue] }
|
|
34
|
+
| { oracle_query: readonly [AciValue, AciValue] };
|
|
35
|
+
|
|
36
|
+
export interface Domain {
|
|
37
|
+
name?: string;
|
|
38
|
+
version?: number;
|
|
39
|
+
networkId?: string;
|
|
40
|
+
contractAddress?: Encoded.ContractAddress;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
|
|
44
|
+
export function encodeFateValue(
|
|
45
|
+
value: unknown,
|
|
46
|
+
aci: AciValue,
|
|
47
|
+
): Encoded.ContractBytearray {
|
|
48
|
+
const contractByteArrayEncoder = new ContractByteArrayEncoder();
|
|
49
|
+
const aciTypeResolver = new AciTypeResolver([]);
|
|
50
|
+
aciTypeResolver.isCustomType = () => false;
|
|
51
|
+
return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
|
|
55
|
+
export function decodeFateValue(
|
|
56
|
+
value: Encoded.ContractBytearray,
|
|
57
|
+
aci: AciValue,
|
|
58
|
+
): Encoded.ContractBytearray {
|
|
59
|
+
const contractByteArrayEncoder = new ContractByteArrayEncoder();
|
|
60
|
+
const aciTypeResolver = new AciTypeResolver([]);
|
|
61
|
+
aciTypeResolver.isCustomType = () => false;
|
|
62
|
+
return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Hashes domain object, can be used to inline domain hash to contract source code
|
|
67
|
+
*/
|
|
68
|
+
export function hashDomain(domain: Domain): Buffer {
|
|
69
|
+
const domainAci = {
|
|
70
|
+
record: [{
|
|
71
|
+
name: 'name',
|
|
72
|
+
type: { option: ['string'] },
|
|
73
|
+
}, {
|
|
74
|
+
name: 'version',
|
|
75
|
+
type: { option: ['int'] },
|
|
76
|
+
}, {
|
|
77
|
+
name: 'networkId',
|
|
78
|
+
type: { option: ['string'] },
|
|
79
|
+
}, {
|
|
80
|
+
name: 'contractAddress',
|
|
81
|
+
type: { option: ['contract_pubkey'] },
|
|
82
|
+
}],
|
|
83
|
+
} as const;
|
|
84
|
+
return hash(decode(encodeFateValue(domain, domainAci)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function hashTypedData(
|
|
88
|
+
data: Encoded.ContractBytearray,
|
|
89
|
+
aci: AciValue,
|
|
90
|
+
domain: Domain,
|
|
91
|
+
): Buffer {
|
|
92
|
+
return hash(concatBuffers([
|
|
93
|
+
messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),
|
|
94
|
+
]));
|
|
95
|
+
}
|
|
@@ -2,7 +2,7 @@ import Node from './Node';
|
|
|
2
2
|
import AccountBase from './account/Base';
|
|
3
3
|
import { Encoded } from './utils/encoder';
|
|
4
4
|
import CompilerBase from './contract/compiler/Base';
|
|
5
|
-
import AeSdkMethods, { OnAccount } from './AeSdkMethods';
|
|
5
|
+
import AeSdkMethods, { OnAccount, AeSdkMethodsOptions } from './AeSdkMethods';
|
|
6
6
|
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & {
|
|
7
7
|
name: string;
|
|
8
8
|
};
|
|
@@ -19,7 +19,7 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
19
19
|
* @param options - Options
|
|
20
20
|
* @param options.nodes - Array of nodes
|
|
21
21
|
*/
|
|
22
|
-
constructor({ nodes, ...options }?:
|
|
22
|
+
constructor({ nodes, ...options }?: AeSdkMethodsOptions & {
|
|
23
23
|
nodes?: Array<{
|
|
24
24
|
name: string;
|
|
25
25
|
instance: Node;
|
|
@@ -72,6 +72,11 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
72
72
|
*/
|
|
73
73
|
getNodesInPool(): Promise<NodeInfo[]>;
|
|
74
74
|
addresses(): Encoded.AccountAddress[];
|
|
75
|
+
/**
|
|
76
|
+
* Resolves an account
|
|
77
|
+
* @param account - ak-address, instance of AccountBase, or keypair
|
|
78
|
+
*/
|
|
79
|
+
_resolveAccount(account?: OnAccount): AccountBase;
|
|
75
80
|
get address(): Encoded.AccountAddress;
|
|
76
81
|
sign(data: string | Uint8Array, { onAccount, ...options }?: {
|
|
77
82
|
onAccount?: OnAccount;
|
|
@@ -82,7 +87,10 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
82
87
|
signMessage(message: string, { onAccount, ...options }?: {
|
|
83
88
|
onAccount?: OnAccount;
|
|
84
89
|
} & Parameters<AccountBase['signMessage']>[1]): Promise<Uint8Array>;
|
|
85
|
-
|
|
90
|
+
signTypedData(data: Encoded.ContractBytearray, aci: Parameters<AccountBase['signTypedData']>[1], { onAccount, ...options }?: {
|
|
91
|
+
onAccount?: OnAccount;
|
|
92
|
+
} & Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
|
|
93
|
+
_getOptions(callOptions?: AeSdkMethodsOptions): {
|
|
86
94
|
onNode: Node;
|
|
87
95
|
onAccount: AccountBase;
|
|
88
96
|
onCompiler: CompilerBase;
|
|
@@ -10,8 +10,9 @@ import Node from './Node';
|
|
|
10
10
|
import { TxParamsAsync } from './tx/builder/schema.generated';
|
|
11
11
|
import AccountBase from './account/Base';
|
|
12
12
|
import { Encoded } from './utils/encoder';
|
|
13
|
+
import CompilerBase from './contract/compiler/Base';
|
|
13
14
|
export type OnAccount = Encoded.AccountAddress | AccountBase | undefined;
|
|
14
|
-
export declare function getValueOrErrorProxy<Value extends object>(valueCb: () => Value): Value
|
|
15
|
+
export declare function getValueOrErrorProxy<Value extends object | undefined>(valueCb: () => Value): NonNullable<Value>;
|
|
15
16
|
declare const methods: {
|
|
16
17
|
readonly createGeneralizedAccount: typeof contractGaMethods.createGeneralizedAccount;
|
|
17
18
|
readonly buildAuthTxHash: typeof contractGaMethods.buildAuthTxHash;
|
|
@@ -69,11 +70,7 @@ type GetMethodsOptions<Methods extends {
|
|
|
69
70
|
[Name in keyof Methods]: Methods[Name] extends (...args: infer Args) => any ? Args[Decrement<Args['length']>] : never;
|
|
70
71
|
};
|
|
71
72
|
type MethodsOptions = GetMethodsOptions<typeof methods>;
|
|
72
|
-
interface AeSdkMethodsOptions extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
|
|
73
|
-
nodes?: Array<{
|
|
74
|
-
name: string;
|
|
75
|
-
instance: Node;
|
|
76
|
-
}>;
|
|
73
|
+
export interface AeSdkMethodsOptions extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
|
|
77
74
|
}
|
|
78
75
|
/**
|
|
79
76
|
* AeSdkMethods is the composition of:
|
|
@@ -94,13 +91,10 @@ declare class AeSdkMethods {
|
|
|
94
91
|
* @param options - Options
|
|
95
92
|
*/
|
|
96
93
|
constructor(options?: AeSdkMethodsOptions);
|
|
97
|
-
|
|
98
|
-
* Resolves an account
|
|
99
|
-
* @param account - ak-address, instance of AccountBase, or keypair
|
|
100
|
-
*/
|
|
101
|
-
_resolveAccount(account?: OnAccount): AccountBase;
|
|
102
|
-
_getOptions(): AeSdkMethodsOptions & {
|
|
94
|
+
_getOptions(callOptions?: AeSdkMethodsOptions): AeSdkMethodsOptions & {
|
|
103
95
|
onAccount: AccountBase;
|
|
96
|
+
onCompiler: CompilerBase;
|
|
97
|
+
onNode: Node;
|
|
104
98
|
};
|
|
105
99
|
buildTx(options: TxParamsAsync): Promise<Encoded.Transaction>;
|
|
106
100
|
initializeContract<Methods extends ContractMethodsBase>(options?: Omit<Parameters<typeof Contract.initialize>[0], 'onNode'> & {
|
|
@@ -135,5 +129,6 @@ type TransformMethods<Methods extends {
|
|
|
135
129
|
};
|
|
136
130
|
interface AeSdkMethodsTransformed extends TransformMethods<typeof methods> {
|
|
137
131
|
}
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
type AeSdkMethodsTyped = AeSdkMethods & AeSdkMethodsTransformed;
|
|
133
|
+
declare const AeSdkMethodsTyped: new (options?: AeSdkMethodsOptions) => AeSdkMethodsTyped;
|
|
134
|
+
export default AeSdkMethodsTyped;
|