@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
package/es/AeSdkAepp.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkAepp.mjs","names":["AeSdkBase","AccountRpc","decode","RPC_VERSION","RpcClient","METHODS","AlreadyConnectedError","NoWalletConnectedError","UnsubscribedAccountError","UnAuthorizedAccountError","RpcConnectionError","Node","AeSdkAepp","constructor","_ref","name","onAddressChange","onDisconnect","onNetworkChange","other","_resolveAccount","account","arguments","length","undefined","addresses","address","includes","_ensureConnected","rpcClient","_ensureAccountAccess","_accounts","current","Object","keys","connected","connectToWallet","connection","connectNode","disconnectParams","updateNetwork","params","_params$node","node","url","pool","delete","addNode","client","updateAddress","closeConnection","disconnect","readyToConnect","walletInfo","request","connect","version","disconnectWallet","notify","reason","askAddresses","subscribeAddress","type","value","result"],"sources":["../src/AeSdkAepp.ts"],"sourcesContent":["import AeSdkBase from './AeSdkBase';\nimport { OnAccount } from './AeSdkMethods';\nimport AccountBase from './account/Base';\nimport AccountRpc from './account/Rpc';\nimport { decode, Encoded } from './utils/encoder';\nimport {\n Accounts, RPC_VERSION, WalletInfo, Network, WalletApi, AeppApi, Node as NodeRpc,\n} from './aepp-wallet-communication/rpc/types';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema';\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n UnsubscribedAccountError,\n UnAuthorizedAccountError,\n RpcConnectionError,\n} from './utils/errors';\nimport Node from './Node';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\n\n/**\n * RPC handler for AEPP side\n * Contain functionality for wallet interaction and connect it to sdk\n * @category aepp wallet communication\n */\nexport default class AeSdkAepp extends AeSdkBase {\n name: string;\n\n onAddressChange: (a: Accounts) => void;\n\n onDisconnect: (p: any) => void;\n\n onNetworkChange: (a: Network) => void;\n\n rpcClient?: RpcClient<WalletApi, AeppApi>;\n\n _accounts?: Accounts;\n\n /**\n * @param options - Options\n * @param options.name - Aepp name\n * @param options.onAddressChange - Call-back function for update address event\n * @param options.onDisconnect - Call-back function for disconnect event\n * @param options.onNetworkChange - Call-back function for update network event\n */\n constructor({\n name,\n onAddressChange = () => {},\n onDisconnect = () => {},\n onNetworkChange = () => {},\n ...other\n }: {\n name: string;\n onAddressChange?: (a: Accounts) => void;\n onDisconnect?: (p: any) => void;\n onNetworkChange?: (a: Network) => void;\n } & ConstructorParameters<typeof AeSdkBase>[0]) {\n super(other);\n this.onAddressChange = onAddressChange;\n this.onDisconnect = onDisconnect;\n this.onNetworkChange = onNetworkChange;\n this.name = name;\n }\n\n override _resolveAccount(account: OnAccount = this.addresses()[0]): AccountBase {\n if (typeof account === 'string') {\n const address = account as Encoded.AccountAddress;\n decode(address);\n if (!this.addresses().includes(address)) throw new UnAuthorizedAccountError(address);\n this._ensureConnected();\n account = new AccountRpc(this.rpcClient, address);\n }\n if (account == null) this._ensureAccountAccess();\n return super._resolveAccount(account);\n }\n\n override addresses(): Encoded.AccountAddress[] {\n if (this._accounts == null) return [];\n const current = Object.keys(this._accounts.current)[0];\n return [\n ...current != null ? [current] : [], ...Object.keys(this._accounts.connected),\n ] as Encoded.AccountAddress[];\n }\n\n /**\n * Connect to wallet\n * @param connection - Wallet connection object\n * @param options - Options\n * @param options.connectNode - Request wallet to bind node\n * @param options.name - Node name\n * @param options.select - Select this node as current\n */\n async connectToWallet(\n connection: BrowserConnection,\n { connectNode = false, name = 'wallet-node' }: { connectNode?: boolean; name?: string } = {},\n ): Promise<WalletInfo & { node?: NodeRpc }> {\n if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet');\n let disconnectParams: any;\n\n const updateNetwork = (params: Network): void => {\n if (connectNode) {\n if (params.node?.url == null) throw new RpcConnectionError('Missing URLs of the Node');\n this.pool.delete(name);\n this.addNode(name, new Node(params.node.url), true);\n }\n this.onNetworkChange(params);\n };\n\n const client = new RpcClient<WalletApi, AeppApi>(\n connection,\n () => {\n delete this.rpcClient;\n delete this._accounts;\n this.onDisconnect(disconnectParams);\n },\n {\n [METHODS.updateAddress]: (params) => {\n this._accounts = params;\n this.onAddressChange(params);\n },\n [METHODS.updateNetwork]: updateNetwork,\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n client.connection.disconnect();\n },\n [METHODS.readyToConnect]: () => {},\n },\n );\n const walletInfo = await client\n .request(METHODS.connect, { name: this.name, version: RPC_VERSION, connectNode });\n updateNetwork(walletInfo);\n this.rpcClient = client;\n return walletInfo;\n }\n\n /**\n * Disconnect from wallet\n */\n disconnectWallet(): void {\n this._ensureConnected();\n this.rpcClient.notify(METHODS.closeConnection, { reason: 'bye' });\n this.rpcClient.connection.disconnect();\n }\n\n /**\n * Ask addresses from wallet\n * @returns Addresses from wallet\n */\n async askAddresses(): Promise<Encoded.AccountAddress[]> {\n this._ensureAccountAccess();\n return this.rpcClient.request(METHODS.address, undefined);\n }\n\n /**\n * Subscribe for addresses from wallet\n * @param type - Subscription type\n * @param value - Should be one of 'current' (the selected account), 'connected' (all)\n * @returns Accounts from wallet\n */\n async subscribeAddress(\n type: SUBSCRIPTION_TYPES,\n value: 'current' | 'connected',\n ): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>> {\n this._ensureConnected();\n const result = await this.rpcClient.request(METHODS.subscribeAddress, { type, value });\n this._accounts = result.address;\n return result;\n }\n\n _ensureConnected(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n if (this.rpcClient != null) return;\n throw new NoWalletConnectedError('You are not connected to Wallet');\n }\n\n _ensureAccountAccess(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n this._ensureConnected();\n if (this.addresses().length !== 0) return;\n throw new UnsubscribedAccountError();\n }\n}\n"],"mappings":"OAAOA,SAAS;AAAA,OAGTC,UAAU;AAAA,SACRC,MAAM;AAAA,SAEHC,WAAW;AAAA,OAEhBC,SAAS;AAAA,SACPC,OAAO;AAAA,SAEdC,qBAAqB,EACrBC,sBAAsB,EACtBC,wBAAwB,EACxBC,wBAAwB,EACxBC,kBAAkB;AAAA,OAEbC,IAAI;AAGX;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAS,SAASZ,SAAS,CAAC;EAa/C;AACF;AACA;AACA;AACA;AACA;AACA;EACEa,WAAWA,CAAAC,IAAA,EAWqC;IAAA,IAXpC;MACVC,IAAI;MACJC,eAAe,GAAGA,CAAA,KAAM,CAAC,CAAC;MAC1BC,YAAY,GAAGA,CAAA,KAAM,CAAC,CAAC;MACvBC,eAAe,GAAGA,CAAA,KAAM,CAAC,CAAC;MAC1B,GAAGC;IAMwC,CAAC,GAAAL,IAAA;IAC5C,KAAK,CAACK,KAAK,CAAC;IACZ,IAAI,CAACH,eAAe,GAAGA,eAAe;IACtC,IAAI,CAACC,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,eAAe,GAAGA,e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EAAE;IACvB,IAAI,IAAI,CAACH,SAAS,EAAE,CAACF,MAAM,KAAK,CAAC,EAAE;IACnC,MAAM,IAAIf,wBAAwB,EAAE;EACtC;AACF"}
|
|
1
|
+
{"version":3,"file":"AeSdkAepp.mjs","names":["AeSdkBase","AccountRpc","decode","RPC_VERSION","RpcClient","METHODS","AlreadyConnectedError","NoWalletConnectedError","UnsubscribedAccountError","UnAuthorizedAccountError","RpcConnectionError","Node","AeSdkAepp","constructor","_ref","name","onAddressChange","onDisconnect","onNetworkChange","other","_resolveAccount","account","arguments","length","undefined","addresses","address","includes","_ensureConnected","rpcClient","_ensureAccountAccess","_accounts","current","Object","keys","connected","connectToWallet","connection","connectNode","disconnectParams","updateNetwork","params","_params$node","node","url","pool","delete","addNode","client","updateAddress","closeConnection","disconnect","readyToConnect","walletInfo","request","connect","version","disconnectWallet","notify","reason","askAddresses","subscribeAddress","type","value","result"],"sources":["../src/AeSdkAepp.ts"],"sourcesContent":["import AeSdkBase from './AeSdkBase';\nimport { OnAccount } from './AeSdkMethods';\nimport AccountBase from './account/Base';\nimport AccountRpc from './account/Rpc';\nimport { decode, Encoded } from './utils/encoder';\nimport {\n Accounts, RPC_VERSION, WalletInfo, Network, WalletApi, AeppApi, Node as NodeRpc,\n} from './aepp-wallet-communication/rpc/types';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema';\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n UnsubscribedAccountError,\n UnAuthorizedAccountError,\n RpcConnectionError,\n} from './utils/errors';\nimport Node from './Node';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\n\n/**\n * RPC handler for AEPP side\n * Contain functionality for wallet interaction and connect it to sdk\n * @category aepp wallet communication\n */\nexport default class AeSdkAepp extends AeSdkBase {\n name: string;\n\n onAddressChange: (a: Accounts) => void;\n\n onDisconnect: (p: any) => void;\n\n onNetworkChange: (a: Network) => void;\n\n rpcClient?: RpcClient<WalletApi, AeppApi>;\n\n _accounts?: Accounts;\n\n /**\n * @param options - Options\n * @param options.name - Aepp name\n * @param options.onAddressChange - Call-back function for update address event\n * @param options.onDisconnect - Call-back function for disconnect event\n * @param options.onNetworkChange - Call-back function for update network event\n */\n constructor({\n name,\n onAddressChange = () => {},\n onDisconnect = () => {},\n onNetworkChange = () => {},\n ...other\n }: {\n name: string;\n onAddressChange?: (a: Accounts) => void;\n onDisconnect?: (p: any) => void;\n onNetworkChange?: (a: Network) => void;\n } & ConstructorParameters<typeof AeSdkBase>[0]) {\n super(other);\n this.onAddressChange = onAddressChange;\n this.onDisconnect = onDisconnect;\n this.onNetworkChange = onNetworkChange;\n this.name = name;\n }\n\n override _resolveAccount(account: OnAccount = this.addresses()[0]): AccountBase {\n if (typeof account === 'string') {\n const address = account as Encoded.AccountAddress;\n decode(address);\n if (!this.addresses().includes(address)) throw new UnAuthorizedAccountError(address);\n this._ensureConnected();\n account = new AccountRpc(this.rpcClient, address);\n }\n if (account == null) this._ensureAccountAccess();\n return super._resolveAccount(account);\n }\n\n override addresses(): Encoded.AccountAddress[] {\n if (this._accounts == null) return [];\n const current = Object.keys(this._accounts.current)[0];\n return [\n ...current != null ? [current] : [], ...Object.keys(this._accounts.connected),\n ] as Encoded.AccountAddress[];\n }\n\n /**\n * Connect to wallet\n * @param connection - Wallet connection object\n * @param options - Options\n * @param options.connectNode - Request wallet to bind node\n * @param options.name - Node name\n * @param options.select - Select this node as current\n */\n async connectToWallet(\n connection: BrowserConnection,\n { connectNode = false, name = 'wallet-node' }: { connectNode?: boolean; name?: string } = {},\n ): Promise<WalletInfo & { node?: NodeRpc }> {\n if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet');\n let disconnectParams: any;\n\n const updateNetwork = (params: Network): void => {\n if (connectNode) {\n if (params.node?.url == null) throw new RpcConnectionError('Missing URLs of the Node');\n this.pool.delete(name);\n this.addNode(name, new Node(params.node.url), true);\n }\n this.onNetworkChange(params);\n };\n\n const client = new RpcClient<WalletApi, AeppApi>(\n connection,\n () => {\n delete this.rpcClient;\n delete this._accounts;\n this.onDisconnect(disconnectParams);\n },\n {\n [METHODS.updateAddress]: (params) => {\n this._accounts = params;\n this.onAddressChange(params);\n },\n [METHODS.updateNetwork]: updateNetwork,\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n client.connection.disconnect();\n },\n [METHODS.readyToConnect]: () => {},\n },\n );\n const walletInfo = await client\n .request(METHODS.connect, { name: this.name, version: RPC_VERSION, connectNode });\n updateNetwork(walletInfo);\n this.rpcClient = client;\n return walletInfo;\n }\n\n /**\n * Disconnect from wallet\n */\n disconnectWallet(): void {\n this._ensureConnected();\n this.rpcClient.notify(METHODS.closeConnection, { reason: 'bye' });\n this.rpcClient.connection.disconnect();\n }\n\n /**\n * Ask addresses from wallet\n * @returns Addresses from wallet\n */\n async askAddresses(): Promise<Encoded.AccountAddress[]> {\n this._ensureAccountAccess();\n return this.rpcClient.request(METHODS.address, undefined);\n }\n\n /**\n * Subscribe for addresses from wallet\n * @param type - Subscription type\n * @param value - Should be one of 'current' (the selected account), 'connected' (all)\n * @returns Accounts from wallet\n */\n async subscribeAddress(\n type: SUBSCRIPTION_TYPES,\n value: 'current' | 'connected',\n ): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>> {\n this._ensureConnected();\n const result = await this.rpcClient.request(METHODS.subscribeAddress, { type, value });\n this._accounts = result.address;\n return result;\n }\n\n _ensureConnected(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n if (this.rpcClient != null) return;\n throw new NoWalletConnectedError('You are not connected to Wallet');\n }\n\n _ensureAccountAccess(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n this._ensureConnected();\n if (this.addresses().length !== 0) return;\n throw new UnsubscribedAccountError();\n }\n}\n"],"mappings":"OAAOA,SAAS;AAAA,OAGTC,UAAU;AAAA,SACRC,MAAM;AAAA,S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AAsC;IACtD,IAAI,CAAC9B,oBAAoB,CAAC,CAAC;IAC3B,OAAO,IAAI,CAACD,SAAS,CAACyB,OAAO,CAACjD,OAAO,CAACqB,OAAO,EAAEF,SAAS,CAAC;EAC3D;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMqC,gBAAgBA,CACpBC,IAAwB,EACxBC,KAA8B,EAC4B;IAC1D,IAAI,CAACnC,gBAAgB,CAAC,CAAC;IACvB,MAAMoC,MAAM,GAAG,MAAM,IAAI,CAACnC,SAAS,CAACyB,OAAO,CAACjD,OAAO,CAACwD,gBAAgB,EAAE;MAAEC,IAAI;MAAEC;IAAM,CAAC,CAAC;IACtF,IAAI,CAAChC,SAAS,GAAGiC,MAAM,CAACtC,OAAO;IAC/B,OAAOsC,MAAM;EACf;EAEApC,gBAAgBA,CAAA,EAAmF;IACjG,IAAI,IAAI,CAACC,SAAS,IAAI,IAAI,EAAE;IAC5B,MAAM,IAAItB,sBAAsB,CAAC,iCAAiC,CAAC;EACrE;EAEAuB,oBAAoBA,CAAA,EAAmF;IACrG,IAAI,CAACF,gBAAgB,CAAC,CAAC;IACvB,IAAI,IAAI,CAACH,SAAS,CAAC,CAAC,CAACF,MAAM,KAAK,CAAC,EAAE;IACnC,MAAM,IAAIf,wBAAwB,CAAC,CAAC;EACtC;AACF"}
|
package/es/AeSdkBase.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ 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
|
+
import { AensName } from './tx/builder/constants';
|
|
6
7
|
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & {
|
|
7
8
|
name: string;
|
|
8
9
|
};
|
|
@@ -19,7 +20,7 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
19
20
|
* @param options - Options
|
|
20
21
|
* @param options.nodes - Array of nodes
|
|
21
22
|
*/
|
|
22
|
-
constructor({ nodes, ...options }?:
|
|
23
|
+
constructor({ nodes, ...options }?: AeSdkMethodsOptions & {
|
|
23
24
|
nodes?: Array<{
|
|
24
25
|
name: string;
|
|
25
26
|
instance: Node;
|
|
@@ -72,6 +73,11 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
72
73
|
*/
|
|
73
74
|
getNodesInPool(): Promise<NodeInfo[]>;
|
|
74
75
|
addresses(): Encoded.AccountAddress[];
|
|
76
|
+
/**
|
|
77
|
+
* Resolves an account
|
|
78
|
+
* @param account - ak-address, instance of AccountBase, or keypair
|
|
79
|
+
*/
|
|
80
|
+
_resolveAccount(account?: OnAccount): AccountBase;
|
|
75
81
|
get address(): Encoded.AccountAddress;
|
|
76
82
|
sign(data: string | Uint8Array, { onAccount, ...options }?: {
|
|
77
83
|
onAccount?: OnAccount;
|
|
@@ -82,7 +88,19 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
82
88
|
signMessage(message: string, { onAccount, ...options }?: {
|
|
83
89
|
onAccount?: OnAccount;
|
|
84
90
|
} & Parameters<AccountBase['signMessage']>[1]): Promise<Uint8Array>;
|
|
85
|
-
|
|
91
|
+
signTypedData(data: Encoded.ContractBytearray, aci: Parameters<AccountBase['signTypedData']>[1], { onAccount, ...options }?: {
|
|
92
|
+
onAccount?: OnAccount;
|
|
93
|
+
} & Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
|
|
94
|
+
signDelegationToContract(contractAddress: Encoded.ContractAddress, { onAccount, ...options }?: {
|
|
95
|
+
onAccount?: OnAccount;
|
|
96
|
+
} & Parameters<AccountBase['signDelegationToContract']>[1]): Promise<Encoded.Signature>;
|
|
97
|
+
signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName, { onAccount, ...options }?: {
|
|
98
|
+
onAccount?: OnAccount;
|
|
99
|
+
} & Parameters<AccountBase['signNameDelegationToContract']>[2]): Promise<Encoded.Signature>;
|
|
100
|
+
signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId, { onAccount, ...options }?: {
|
|
101
|
+
onAccount?: OnAccount;
|
|
102
|
+
} & Parameters<AccountBase['signOracleQueryDelegationToContract']>[2]): Promise<Encoded.Signature>;
|
|
103
|
+
_getOptions(callOptions?: AeSdkMethodsOptions): {
|
|
86
104
|
onNode: Node;
|
|
87
105
|
onAccount: AccountBase;
|
|
88
106
|
onCompiler: CompilerBase;
|
package/es/AeSdkBase.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
|
-
import { CompilerError, DuplicateNodeError, NodeNotFoundError } from "./utils/errors.mjs";
|
|
2
|
+
import { CompilerError, DuplicateNodeError, NodeNotFoundError, NotImplementedError, TypeError } from "./utils/errors.mjs";
|
|
3
3
|
import AeSdkMethods, { getValueOrErrorProxy } from "./AeSdkMethods.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Basic AeSdk class implements:
|
|
@@ -121,6 +121,17 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
121
121
|
addresses() {
|
|
122
122
|
return [];
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Resolves an account
|
|
127
|
+
* @param account - ak-address, instance of AccountBase, or keypair
|
|
128
|
+
*/
|
|
129
|
+
_resolveAccount() {
|
|
130
|
+
let account = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._options.onAccount;
|
|
131
|
+
if (typeof account === 'string') throw new NotImplementedError('Address in AccountResolver');
|
|
132
|
+
if (typeof account === 'object') return account;
|
|
133
|
+
throw new TypeError('Account should be an address (ak-prefixed string), ' + `or instance of AccountBase, got ${String(account)} instead`);
|
|
134
|
+
}
|
|
124
135
|
get address() {
|
|
125
136
|
return this._resolveAccount().address;
|
|
126
137
|
}
|
|
@@ -149,11 +160,48 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
149
160
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
150
161
|
return this._resolveAccount(onAccount).signMessage(message, options);
|
|
151
162
|
}
|
|
163
|
+
async signTypedData(data, aci) {
|
|
164
|
+
let {
|
|
165
|
+
onAccount,
|
|
166
|
+
...options
|
|
167
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
168
|
+
return this._resolveAccount(onAccount).signTypedData(data, aci, options);
|
|
169
|
+
}
|
|
170
|
+
async signDelegationToContract(contractAddress) {
|
|
171
|
+
var _options$networkId;
|
|
172
|
+
let {
|
|
173
|
+
onAccount,
|
|
174
|
+
...options
|
|
175
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
176
|
+
(_options$networkId = options.networkId) !== null && _options$networkId !== void 0 ? _options$networkId : options.networkId = this.selectedNodeName !== null ? await this.api.getNetworkId() : undefined;
|
|
177
|
+
return this._resolveAccount(onAccount).signDelegationToContract(contractAddress, options);
|
|
178
|
+
}
|
|
179
|
+
async signNameDelegationToContract(contractAddress, name) {
|
|
180
|
+
var _options$networkId2;
|
|
181
|
+
let {
|
|
182
|
+
onAccount,
|
|
183
|
+
...options
|
|
184
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
185
|
+
(_options$networkId2 = options.networkId) !== null && _options$networkId2 !== void 0 ? _options$networkId2 : options.networkId = this.selectedNodeName !== null ? await this.api.getNetworkId() : undefined;
|
|
186
|
+
return this._resolveAccount(onAccount).signNameDelegationToContract(contractAddress, name, options);
|
|
187
|
+
}
|
|
188
|
+
async signOracleQueryDelegationToContract(contractAddress, oracleQueryId) {
|
|
189
|
+
var _options$networkId3;
|
|
190
|
+
let {
|
|
191
|
+
onAccount,
|
|
192
|
+
...options
|
|
193
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
194
|
+
(_options$networkId3 = options.networkId) !== null && _options$networkId3 !== void 0 ? _options$networkId3 : options.networkId = this.selectedNodeName !== null ? await this.api.getNetworkId() : undefined;
|
|
195
|
+
return this._resolveAccount(onAccount).signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
|
|
196
|
+
}
|
|
152
197
|
_getOptions() {
|
|
198
|
+
let callOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
153
199
|
return {
|
|
154
|
-
...
|
|
200
|
+
...this._options,
|
|
155
201
|
onNode: getValueOrErrorProxy(() => this.api),
|
|
156
|
-
onCompiler: getValueOrErrorProxy(() => this.compilerApi)
|
|
202
|
+
onCompiler: getValueOrErrorProxy(() => this.compilerApi),
|
|
203
|
+
...callOptions,
|
|
204
|
+
onAccount: getValueOrErrorProxy(() => this._resolveAccount(callOptions.onAccount))
|
|
157
205
|
};
|
|
158
206
|
}
|
|
159
207
|
}
|
package/es/AeSdkBase.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkBase.mjs","names":["CompilerError","DuplicateNodeError","NodeNotFoundError","AeSdkMethods","getValueOrErrorProxy","AeSdkBase","constructor","nodes","options","arguments","length","undefined","_defineProperty","Map","forEach","_ref","i","name","instance","addNode","compilerApi","_options","onCompiler","api","ensureNodeConnected","pool","get","selectedNodeName","node","select","has","set","selectNode","isNodeConnected","getNodeInfo","getNodesInPool","Promise","all","Array","from","entries","map","_ref2","addresses","address","_resolveAccount","sign","data","onAccount","signTransaction","tx","networkId","getNetworkId","signMessage","message","_getOptions","onNode"],"sources":["../src/AeSdkBase.ts"],"sourcesContent":["import Node from './Node';\nimport AccountBase from './account/Base';\nimport { CompilerError, DuplicateNodeError, NodeNotFoundError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport CompilerBase from './contract/compiler/Base';\nimport AeSdkMethods, { OnAccount, getValueOrErrorProxy } from './AeSdkMethods';\n\ntype NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };\n\n/**\n * Basic AeSdk class implements:\n * - node selector,\n * - integrated compiler support,\n * - wrappers of account methods mapped to the current account.\n */\nexport default class AeSdkBase extends AeSdkMethods {\n pool: Map<string, Node> = new Map();\n\n selectedNodeName?: string;\n\n /**\n * @param options - Options\n * @param options.nodes - Array of nodes\n */\n constructor(\n { nodes = [], ...options }: ConstructorParameters<typeof AeSdkMethods>[0] & {\n nodes?: Array<{ name: string; instance: Node }>;\n } = {},\n ) {\n super(options);\n\n nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0));\n }\n\n // TODO: consider dropping this getter, because:\n // compiler is not intended to be used separately any more (functionality limited to sdk needs)\n // and user creates its instance by himself\n get compilerApi(): CompilerBase {\n if (this._options.onCompiler == null) {\n throw new CompilerError('You can\\'t use Compiler API. Compiler is not ready!');\n }\n return this._options.onCompiler;\n }\n\n get api(): Node {\n this.ensureNodeConnected();\n return this.pool.get(this.selectedNodeName) as Node;\n }\n\n /**\n * Add Node\n * @param name - Node name\n * @param node - Node instance\n * @param select - Select this node as current\n * @example\n * ```js\n * // add and select new node with name 'testNode'\n * aeSdkBase.addNode('testNode', new Node({ url }), true)\n * ```\n */\n addNode(name: string, node: Node, select = false): void {\n if (this.pool.has(name)) throw new DuplicateNodeError(name);\n\n this.pool.set(name, node);\n if (select || this.selectedNodeName == null) {\n this.selectNode(name);\n }\n }\n\n /**\n * Select Node\n * @param name - Node name\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode(name: string): void {\n if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);\n this.selectedNodeName = name;\n }\n\n /**\n * Check if you have selected node\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected(): this is AeSdkBase & { selectedNodeName: string } {\n return this.selectedNodeName != null;\n }\n\n protected ensureNodeConnected(): asserts this is AeSdkBase & { selectedNodeName: string } {\n if (!this.isNodeConnected()) {\n throw new NodeNotFoundError('You can\\'t use Node API. Node is not connected or not defined!');\n }\n }\n\n /**\n * Get information about node\n * @example\n * ```js\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n * ```\n */\n async getNodeInfo(): Promise<NodeInfo> {\n this.ensureNodeConnected();\n return {\n name: this.selectedNodeName,\n ...await this.api.getNodeInfo(),\n };\n }\n\n /**\n * Get array of available nodes\n * @example\n * nodePool.getNodesInPool()\n */\n async getNodesInPool(): Promise<NodeInfo[]> {\n return Promise.all(\n Array.from(this.pool.entries()).map(async ([name, node]) => ({\n name,\n ...await node.getNodeInfo(),\n })),\n );\n }\n\n // eslint-disable-next-line class-methods-use-this\n addresses(): Encoded.AccountAddress[] {\n return [];\n }\n\n get address(): Encoded.AccountAddress {\n return this._resolveAccount().address;\n }\n\n async sign(\n data: string | Uint8Array,\n { onAccount, ...options }: { onAccount?: OnAccount } = {},\n ): Promise<Uint8Array> {\n return this._resolveAccount(onAccount).sign(data, options);\n }\n\n async signTransaction(\n tx: Encoded.Transaction,\n { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n const networkId = this.selectedNodeName !== null ? await this.api.getNetworkId() : undefined;\n return this._resolveAccount(onAccount).signTransaction(tx, { networkId, ...options });\n }\n\n async signMessage(\n message: string,\n { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signMessage']>[1] = {},\n ): Promise<Uint8Array> {\n return this._resolveAccount(onAccount).signMessage(message, options);\n }\n\n override _getOptions(): {\n onNode: Node;\n onAccount: AccountBase;\n onCompiler: CompilerBase;\n } {\n return {\n ...super._getOptions(),\n onNode: getValueOrErrorProxy(() => this.api),\n onCompiler: getValueOrErrorProxy(() => this.compilerApi),\n };\n }\n}\n"],"mappings":";SAESA,aAAa,EAAEC,kBAAkB,EAAEC,iBAAiB;AAAA,OAGtDC,YAAY,IAAeC,oBAAoB;AAItD;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAS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M,IAAI,CAACmB,GAAG,CAAC;MAC5CD,UAAU,EAAElB,oBAAoB,CAAC,MAAM,IAAI,CAACgB,WAAW;IACzD,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"AeSdkBase.mjs","names":["CompilerError","DuplicateNodeError","NodeNotFoundError","NotImplementedError","TypeError","AeSdkMethods","getValueOrErrorProxy","AeSdkBase","constructor","nodes","options","arguments","length","undefined","_defineProperty","Map","forEach","_ref","i","name","instance","addNode","compilerApi","_options","onCompiler","api","ensureNodeConnected","pool","get","selectedNodeName","node","select","has","set","selectNode","isNodeConnected","getNodeInfo","getNodesInPool","Promise","all","Array","from","entries","map","_ref2","addresses","_resolveAccount","account","onAccount","String","address","sign","data","signTransaction","tx","networkId","getNetworkId","signMessage","message","signTypedData","aci","signDelegationToContract","contractAddress","_options$networkId","signNameDelegationToContract","_options$networkId2","signOracleQueryDelegationToContract","oracleQueryId","_options$networkId3","_getOptions","callOptions","onNode"],"sources":["../src/AeSdkBase.ts"],"sourcesContent":["import Node from './Node';\nimport AccountBase from './account/Base';\nimport {\n CompilerError, DuplicateNodeError, NodeNotFoundError, NotImplementedError, TypeError,\n} from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport CompilerBase from './contract/compiler/Base';\nimport AeSdkMethods, { OnAccount, getValueOrErrorProxy, AeSdkMethodsOptions } from './AeSdkMethods';\nimport { AensName } from './tx/builder/constants';\n\ntype NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };\n\n/**\n * Basic AeSdk class implements:\n * - node selector,\n * - integrated compiler support,\n * - wrappers of account methods mapped to the current account.\n */\nexport default class AeSdkBase extends AeSdkMethods {\n pool: Map<string, Node> = new Map();\n\n selectedNodeName?: string;\n\n /**\n * @param options - Options\n * @param options.nodes - Array of nodes\n */\n constructor(\n { nodes = [], ...options }: AeSdkMethodsOptions & {\n nodes?: Array<{ name: string; instance: Node }>;\n } = {},\n ) {\n super(options);\n\n nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0));\n }\n\n // TODO: consider dropping this getter, because:\n // compiler is not intended to be used separately any more (functionality limited to sdk needs)\n // and user creates its instance by himself\n get compilerApi(): CompilerBase {\n if (this._options.onCompiler == null) {\n throw new CompilerError('You can\\'t use Compiler API. Compiler is not ready!');\n }\n return this._options.onCompiler;\n }\n\n get api(): Node {\n this.ensureNodeConnected();\n return this.pool.get(this.selectedNodeName) as Node;\n }\n\n /**\n * Add Node\n * @param name - Node name\n * @param node - Node instance\n * @param select - Select this node as current\n * @example\n * ```js\n * // add and select new node with name 'testNode'\n * aeSdkBase.addNode('testNode', new Node({ url }), true)\n * ```\n */\n addNode(name: string, node: Node, select = false): void {\n if (this.pool.has(name)) throw new DuplicateNodeError(name);\n\n this.pool.set(name, node);\n if (select || this.selectedNodeName == null) {\n this.selectNode(name);\n }\n }\n\n /**\n * Select Node\n * @param name - Node name\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode(name: string): void {\n if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);\n this.selectedNodeName = name;\n }\n\n /**\n * Check if you have selected node\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected(): this is AeSdkBase & { selectedNodeName: string } {\n return this.selectedNodeName != null;\n }\n\n protected ensureNodeConnected(): asserts this is AeSdkBase & { selectedNodeName: string } {\n if (!this.isNodeConnected()) {\n throw new NodeNotFoundError('You can\\'t use Node API. Node is not connected or not defined!');\n }\n }\n\n /**\n * Get information about node\n * @example\n * ```js\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n * ```\n */\n async getNodeInfo(): Promise<NodeInfo> {\n this.ensureNodeConnected();\n return {\n name: this.selectedNodeName,\n ...await this.api.getNodeInfo(),\n };\n }\n\n /**\n * Get array of available nodes\n * @example\n * nodePool.getNodesInPool()\n */\n async getNodesInPool(): Promise<NodeInfo[]> {\n return Promise.all(\n Array.from(this.pool.entries()).map(async ([name, node]) => ({\n name,\n ...await node.getNodeInfo(),\n })),\n );\n }\n\n // eslint-disable-next-line class-methods-use-this\n addresses(): Encoded.AccountAddress[] {\n return [];\n }\n\n /**\n * Resolves an account\n * @param account - ak-address, instance of AccountBase, or keypair\n */\n _resolveAccount(account: OnAccount = this._options.onAccount): AccountBase {\n if (typeof account === 'string') throw new NotImplementedError('Address in AccountResolver');\n if (typeof account === 'object') return account;\n throw new TypeError(\n 'Account should be an address (ak-prefixed string), '\n + `or instance of AccountBase, got ${String(account)} instead`,\n );\n }\n\n get address(): Encoded.AccountAddress {\n return this._resolveAccount().address;\n }\n\n async sign(\n data: string | Uint8Array,\n { onAccount, ...options }: { onAccount?: OnAccount } = {},\n ): Promise<Uint8Array> {\n return this._resolveAccount(onAccount).sign(data, options);\n }\n\n async signTransaction(\n tx: Encoded.Transaction,\n { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n const networkId = this.selectedNodeName !== null ? await this.api.getNetworkId() : undefined;\n return this._resolveAccount(onAccount).signTransaction(tx, { networkId, ...options });\n }\n\n async signMessage(\n message: string,\n { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signMessage']>[1] = {},\n ): Promise<Uint8Array> {\n return this._resolveAccount(onAccount).signMessage(message, options);\n }\n\n async signTypedData(\n data: Encoded.ContractBytearray,\n aci: Parameters<AccountBase['signTypedData']>[1],\n { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n return this._resolveAccount(onAccount).signTypedData(data, aci, options);\n }\n\n async signDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n { onAccount, ...options }: { onAccount?: OnAccount }\n & Parameters<AccountBase['signDelegationToContract']>[1] = {},\n ): Promise<Encoded.Signature> {\n options.networkId ??= this.selectedNodeName !== null\n ? await this.api.getNetworkId() : undefined;\n return this._resolveAccount(onAccount)\n .signDelegationToContract(contractAddress, options);\n }\n\n async signNameDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n { onAccount, ...options }: { onAccount?: OnAccount }\n & Parameters<AccountBase['signNameDelegationToContract']>[2] = {},\n ): Promise<Encoded.Signature> {\n options.networkId ??= this.selectedNodeName !== null\n ? await this.api.getNetworkId() : undefined;\n return this._resolveAccount(onAccount)\n .signNameDelegationToContract(contractAddress, name, options);\n }\n\n async signOracleQueryDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n { onAccount, ...options }: { onAccount?: OnAccount }\n & Parameters<AccountBase['signOracleQueryDelegationToContract']>[2] = {},\n ): Promise<Encoded.Signature> {\n options.networkId ??= this.selectedNodeName !== null\n ? await this.api.getNetworkId() : undefined;\n return this._resolveAccount(onAccount)\n .signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);\n }\n\n override _getOptions(callOptions: AeSdkMethodsOptions = {}): {\n onNode: Node;\n onAccount: AccountBase;\n onCompiler: CompilerBase;\n } {\n return {\n ...this._options,\n onNode: getValueOrErrorProxy(() => this.api),\n onCompiler: getValueOrErrorProxy(() => this.compilerApi),\n ...callOptions,\n onAccount: getValueOrErrorProxy(() => this._resolveAccount(callOptions.onAccount)),\n };\n }\n}\n"],"mappings":";SAGEA,aAAa,EAAEC,kBAAkB,EAAEC,iBAAiB,EAAEC,mBAAmB,EAAEC,SAAS;AAAA,OAI/EC,YAAY,IAAeC,oBAAoB;AAKtD;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAS,SAASF,YAAY,CAAC;EAKlD;AACF;AACA;AACA;EACEG,WAAWA,CAAA,EAIT;IAAA,IAHA;MAAEC,KAAK,GAAG,EAAE;MAAE,GAAGC;IAEjB,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAEN,KAAK,CAACD,OAAO,CAAC;IAACI,eAAA,eAbS,IAAIC,GAAG,CAAC,CAAC;IAejCN,KAAK,CA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CAAC;IACnF,CAAC;EACH;AACF"}
|
package/es/AeSdkMethods.d.ts
CHANGED
|
@@ -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;
|
|
@@ -61,11 +62,7 @@ type GetMethodsOptions<Methods extends {
|
|
|
61
62
|
[Name in keyof Methods]: Methods[Name] extends (...args: infer Args) => any ? Args[Decrement<Args['length']>] : never;
|
|
62
63
|
};
|
|
63
64
|
type MethodsOptions = GetMethodsOptions<typeof methods>;
|
|
64
|
-
interface AeSdkMethodsOptions extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
|
|
65
|
-
nodes?: Array<{
|
|
66
|
-
name: string;
|
|
67
|
-
instance: Node;
|
|
68
|
-
}>;
|
|
65
|
+
export interface AeSdkMethodsOptions extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
71
68
|
* AeSdkMethods is the composition of:
|
|
@@ -86,13 +83,10 @@ declare class AeSdkMethods {
|
|
|
86
83
|
* @param options - Options
|
|
87
84
|
*/
|
|
88
85
|
constructor(options?: AeSdkMethodsOptions);
|
|
89
|
-
|
|
90
|
-
* Resolves an account
|
|
91
|
-
* @param account - ak-address, instance of AccountBase, or keypair
|
|
92
|
-
*/
|
|
93
|
-
_resolveAccount(account?: OnAccount): AccountBase;
|
|
94
|
-
_getOptions(): AeSdkMethodsOptions & {
|
|
86
|
+
_getOptions(callOptions?: AeSdkMethodsOptions): AeSdkMethodsOptions & {
|
|
95
87
|
onAccount: AccountBase;
|
|
88
|
+
onCompiler: CompilerBase;
|
|
89
|
+
onNode: Node;
|
|
96
90
|
};
|
|
97
91
|
buildTx(options: TxParamsAsync): Promise<Encoded.Transaction>;
|
|
98
92
|
initializeContract<Methods extends ContractMethodsBase>(options?: Omit<Parameters<typeof Contract.initialize>[0], 'onNode'> & {
|
|
@@ -118,5 +112,6 @@ type TransformMethods<Methods extends {
|
|
|
118
112
|
};
|
|
119
113
|
interface AeSdkMethodsTransformed extends TransformMethods<typeof methods> {
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
type AeSdkMethodsTyped = AeSdkMethods & AeSdkMethodsTransformed;
|
|
116
|
+
declare const AeSdkMethodsTyped: new (options?: AeSdkMethodsOptions) => AeSdkMethodsTyped;
|
|
117
|
+
export default AeSdkMethodsTyped;
|
package/es/AeSdkMethods.mjs
CHANGED
|
@@ -8,21 +8,16 @@ import createDelegationSignature from "./contract/delegation-signature.mjs";
|
|
|
8
8
|
import * as contractGaMethods from "./contract/ga.mjs";
|
|
9
9
|
import { buildTxAsync } from "./tx/builder/index.mjs";
|
|
10
10
|
import { mapObject } from "./utils/other.mjs";
|
|
11
|
-
import { ArgumentError, NotImplementedError, TypeError } from "./utils/errors.mjs";
|
|
12
11
|
export function getValueOrErrorProxy(valueCb) {
|
|
13
|
-
return new Proxy({}, {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
get(t, property, receiver) {
|
|
18
|
-
const target = valueCb();
|
|
19
|
-
const value = Reflect.get(target, property, receiver);
|
|
20
|
-
return typeof value === 'function' ? value.bind(target) : value;
|
|
21
|
-
},
|
|
22
|
-
has(t, property) {
|
|
23
|
-
return Reflect.has(valueCb(), property);
|
|
12
|
+
return new Proxy({}, Object.fromEntries(['apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor', 'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf', 'get', 'has'].map(name => [name, function (t) {
|
|
13
|
+
const target = valueCb(); // to get a native exception in case it missed
|
|
14
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
15
|
+
args[_key - 1] = arguments[_key];
|
|
24
16
|
}
|
|
25
|
-
|
|
17
|
+
const res = Reflect[name](target, ...args);
|
|
18
|
+
return typeof res === 'function' && name === 'get' ? res.bind(target) // otherwise it fails with attempted to get private field on non-instance
|
|
19
|
+
: res;
|
|
20
|
+
}])));
|
|
26
21
|
}
|
|
27
22
|
const {
|
|
28
23
|
InvalidTxError: _2,
|
|
@@ -58,21 +53,14 @@ class AeSdkMethods {
|
|
|
58
53
|
_defineProperty(this, "_options", {});
|
|
59
54
|
Object.assign(this._options, options);
|
|
60
55
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Resolves an account
|
|
64
|
-
* @param account - ak-address, instance of AccountBase, or keypair
|
|
65
|
-
*/
|
|
66
|
-
// eslint-disable-next-line class-methods-use-this
|
|
67
|
-
_resolveAccount(account) {
|
|
68
|
-
if (typeof account === 'string') throw new NotImplementedError('Address in AccountResolver');
|
|
69
|
-
if (typeof account === 'object') return account;
|
|
70
|
-
throw new TypeError('Account should be an address (ak-prefixed string), ' + `or instance of AccountBase, got ${String(account)} instead`);
|
|
71
|
-
}
|
|
72
56
|
_getOptions() {
|
|
57
|
+
let callOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
73
58
|
return {
|
|
74
59
|
...this._options,
|
|
75
|
-
onAccount: getValueOrErrorProxy(() => this.
|
|
60
|
+
onAccount: getValueOrErrorProxy(() => this._options.onAccount),
|
|
61
|
+
onNode: getValueOrErrorProxy(() => this._options.onNode),
|
|
62
|
+
onCompiler: getValueOrErrorProxy(() => this._options.onCompiler),
|
|
63
|
+
...callOptions
|
|
76
64
|
};
|
|
77
65
|
}
|
|
78
66
|
async buildTx(options) {
|
|
@@ -82,39 +70,22 @@ class AeSdkMethods {
|
|
|
82
70
|
});
|
|
83
71
|
}
|
|
84
72
|
async initializeContract(options) {
|
|
85
|
-
|
|
86
|
-
onNode,
|
|
87
|
-
onCompiler,
|
|
88
|
-
...otherOptions
|
|
89
|
-
} = this._getOptions();
|
|
90
|
-
if (onCompiler == null || onNode == null) {
|
|
91
|
-
throw new ArgumentError('onCompiler, onNode', 'provided', null);
|
|
92
|
-
}
|
|
93
|
-
return Contract.initialize({
|
|
94
|
-
...otherOptions,
|
|
95
|
-
onNode,
|
|
96
|
-
onCompiler,
|
|
97
|
-
...options
|
|
98
|
-
});
|
|
73
|
+
return Contract.initialize(this._getOptions(options));
|
|
99
74
|
}
|
|
100
75
|
}
|
|
101
76
|
Object.assign(AeSdkMethods.prototype, mapObject(methods, _ref => {
|
|
102
77
|
let [name, handler] = _ref;
|
|
103
78
|
return [name, function methodWrapper() {
|
|
104
|
-
for (var
|
|
105
|
-
args[
|
|
79
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
80
|
+
args[_key2] = arguments[_key2];
|
|
106
81
|
}
|
|
107
82
|
args.length = handler.length;
|
|
108
83
|
const options = args[args.length - 1];
|
|
109
|
-
args[args.length - 1] =
|
|
110
|
-
...this._getOptions(),
|
|
111
|
-
...options,
|
|
112
|
-
...((options === null || options === void 0 ? void 0 : options.onAccount) != null && {
|
|
113
|
-
onAccount: this._resolveAccount(options.onAccount)
|
|
114
|
-
})
|
|
115
|
-
};
|
|
84
|
+
args[args.length - 1] = this._getOptions(options);
|
|
116
85
|
return handler(...args);
|
|
117
86
|
}];
|
|
118
87
|
}));
|
|
119
|
-
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
89
|
+
const AeSdkMethodsTyped = AeSdkMethods;
|
|
90
|
+
export default AeSdkMethodsTyped;
|
|
120
91
|
//# sourceMappingURL=AeSdkMethods.mjs.map
|
package/es/AeSdkMethods.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkMethods.mjs","names":["chainMethods","aensMethods","spendMethods","oracleMethods","Contract","createDelegationSignature","contractGaMethods","buildTxAsync","mapObject","
|
|
1
|
+
{"version":3,"file":"AeSdkMethods.mjs","names":["chainMethods","aensMethods","spendMethods","oracleMethods","Contract","createDelegationSignature","contractGaMethods","buildTxAsync","mapObject","getValueOrErrorProxy","valueCb","Proxy","Object","fromEntries","map","name","t","target","_len","arguments","length","args","Array","_key","res","Reflect","bind","InvalidTxError","_2","chainMethodsOther","methods","AeSdkMethods","constructor","options","undefined","_defineProperty","assign","_options","_getOptions","callOptions","onAccount","onNode","onCompiler","buildTx","initializeContract","initialize","prototype","_ref","handler","methodWrapper","_len2","_key2","AeSdkMethodsTyped"],"sources":["../src/AeSdkMethods.ts"],"sourcesContent":["import * as chainMethods from './chain';\nimport * as aensMethods from './aens';\nimport * as spendMethods from './spend';\nimport * as oracleMethods from './oracle';\nimport Contract, { ContractMethodsBase } from './contract/Contract';\nimport createDelegationSignature from './contract/delegation-signature';\nimport * as contractGaMethods from './contract/ga';\nimport { buildTxAsync } from './tx/builder';\nimport { mapObject, UnionToIntersection } from './utils/other';\nimport Node from './Node';\nimport { TxParamsAsync } from './tx/builder/schema.generated';\nimport AccountBase from './account/Base';\nimport { Encoded } from './utils/encoder';\nimport CompilerBase from './contract/compiler/Base';\n\nexport type OnAccount = Encoded.AccountAddress | AccountBase | undefined;\n\nexport function getValueOrErrorProxy<Value extends object | undefined>(\n valueCb: () => Value,\n): NonNullable<Value> {\n return new Proxy(\n {},\n Object.fromEntries(([\n 'apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor',\n 'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf',\n 'get', 'has',\n ] as const).map((name) => [name, (t: {}, ...args: unknown[]) => {\n const target = valueCb() as object; // to get a native exception in case it missed\n const res = (Reflect[name] as any)(target, ...args);\n return typeof res === 'function' && name === 'get'\n ? res.bind(target) // otherwise it fails with attempted to get private field on non-instance\n : res;\n }])),\n ) as NonNullable<Value>;\n}\n\nconst { InvalidTxError: _2, ...chainMethodsOther } = chainMethods;\n\nconst methods = {\n ...chainMethodsOther,\n ...aensMethods,\n ...spendMethods,\n ...oracleMethods,\n createDelegationSignature,\n ...contractGaMethods,\n} as const;\n\ntype Decrement<Number extends number> = [-1, 0, 1, 2, 3, 4, 5][Number];\ntype GetMethodsOptions <Methods extends { [key: string]: Function }> =\n {\n [Name in keyof Methods]:\n Methods[Name] extends (...args: infer Args) => any\n ? Args[Decrement<Args['length']>] : never\n };\ntype MethodsOptions = GetMethodsOptions<typeof methods>;\nexport interface AeSdkMethodsOptions\n extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {\n}\n\n/**\n * AeSdkMethods is the composition of:\n * - chain methods\n * - tx methods\n * - aens methods\n * - spend methods\n * - oracle methods\n * - contract methods\n * - contract ga methods\n *\n * While these methods can be used separately, this class provides a handy way to store\n * their context (current account, network, and compiler to use).\n */\nclass AeSdkMethods {\n _options: AeSdkMethodsOptions = {};\n\n /**\n * @param options - Options\n */\n constructor(options: AeSdkMethodsOptions = {}) {\n Object.assign(this._options, options);\n }\n\n _getOptions(\n callOptions: AeSdkMethodsOptions = {},\n ): AeSdkMethodsOptions & { onAccount: AccountBase; onCompiler: CompilerBase; onNode: Node } {\n return {\n ...this._options,\n onAccount: getValueOrErrorProxy(() => this._options.onAccount),\n onNode: getValueOrErrorProxy(() => this._options.onNode),\n onCompiler: getValueOrErrorProxy(() => this._options.onCompiler),\n ...callOptions,\n };\n }\n\n async buildTx(options: TxParamsAsync): Promise<Encoded.Transaction> {\n return buildTxAsync({ ...this._getOptions(), ...options });\n }\n\n async initializeContract<Methods extends ContractMethodsBase>(\n options?: Omit<Parameters<typeof Contract.initialize>[0], 'onNode'> & { onNode?: Node },\n ): Promise<Contract<Methods>> {\n return Contract.initialize<Methods>(this._getOptions(options as AeSdkMethodsOptions));\n }\n}\n\ntype RequiredKeys<T> = {\n [K in keyof T]-?: {} extends Pick<T, K> ? never : K\n}[keyof T];\n\ntype OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T;\n\ntype ReplaceOnAccount<Options> = Options extends { onAccount: any }\n ? Omit<Options, 'onAccount'> & { onAccount: OnAccount } : Options;\n\ntype MakeOptional<Options> = OptionalIfNotRequired<[\n Omit<Options, 'onNode' | 'onCompiler' | 'onAccount'> & Partial<ReplaceOnAccount<Options>>,\n]>;\n\ntype TransformMethods <Methods extends { [key: string]: Function }> =\n {\n [Name in keyof Methods]:\n Methods[Name] extends (...args: [...infer Args, infer Options]) => infer Ret\n ? (...args: [...Args, ...MakeOptional<Options>]) => Ret\n : never\n };\n\ninterface AeSdkMethodsTransformed extends TransformMethods<typeof methods> {}\n\nObject.assign(AeSdkMethods.prototype, mapObject<Function, Function>(\n methods,\n ([name, handler]) => [\n name,\n function methodWrapper(this: AeSdkMethods, ...args: any[]) {\n args.length = handler.length;\n const options = args[args.length - 1];\n args[args.length - 1] = this._getOptions(options);\n return handler(...args);\n },\n ],\n));\n\ntype AeSdkMethodsTyped = AeSdkMethods & AeSdkMethodsTransformed;\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nconst AeSdkMethodsTyped = AeSdkMethods as new (options?: AeSdkMethodsOptions) => AeSdkMethodsTyped;\nexport default AeSdkMethodsTyped;\n"],"mappings":";OAAO,KAAKA,YAAY;AAAA,OACjB,KAAKC,WAAW;AAAA,OAChB,KAAKC,YAAY;AAAA,OACjB,KAAKC,aAAa;AAAA,OAClBC,QAAQ;AAAA,OACRC,yBAAyB;AAAA,OACzB,KAAKC,iBAAiB;AAAA,SACpBC,YAAY;AAAA,SACZC,SAAS;AASlB,OA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AA,EAAbC,IAAI,OAAAC,KAAA,CAAA4B,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;MAAJ9B,IAAI,CAAA8B,KAAA,IAAAhC,SAAA,CAAAgC,KAAA;IAAA;IAChD9B,IAAI,CAACD,MAAM,GAAG4B,OAAO,CAAC5B,MAAM;IAC5B,MAAMa,OAAO,GAAGZ,IAAI,CAACA,IAAI,CAACD,MAAM,GAAG,CAAC,CAAC;IACrCC,IAAI,CAACA,IAAI,CAACD,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAACkB,WAAW,CAACL,OAAO,CAAC;IACjD,OAAOe,OAAO,CAAC,GAAG3B,IAAI,CAAC;EACzB,CAAC,CACF;AAAA,CACH,CAAC,CAAC;AAGF;AACA,MAAM+B,iBAAiB,GAAGrB,YAAwE;AAClG,eAAeqB,iBAAiB"}
|
package/es/AeSdkWallet.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
49
49
|
onDisconnect: OnDisconnect;
|
|
50
50
|
onAskAccounts: OnAskAccounts;
|
|
51
51
|
} & ConstructorParameters<typeof AeSdk>[0]);
|
|
52
|
+
_getAccountsForClient({ addressSubscription }: RpcClientsInfo): Accounts;
|
|
52
53
|
_pushAccountsToApps(): void;
|
|
53
54
|
selectAccount(address: Encoded.AccountAddress): void;
|
|
54
55
|
addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): void;
|
|
@@ -57,7 +58,6 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
57
58
|
};
|
|
58
59
|
selectNode(name: string): Promise<void>;
|
|
59
60
|
_getClient(clientId: string): RpcClientsInfo;
|
|
60
|
-
_isRpcClientSubscribed(clientId: string): boolean;
|
|
61
61
|
_isRpcClientConnected(clientId: string): boolean;
|
|
62
62
|
_disconnectRpcClient(clientId: string): void;
|
|
63
63
|
/**
|