@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
package/es/AeSdkBase.d.ts
CHANGED
|
@@ -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;
|
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,21 @@ 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
|
+
}
|
|
152
170
|
_getOptions() {
|
|
171
|
+
let callOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
153
172
|
return {
|
|
154
|
-
...
|
|
173
|
+
...this._options,
|
|
155
174
|
onNode: getValueOrErrorProxy(() => this.api),
|
|
156
|
-
onCompiler: getValueOrErrorProxy(() => this.compilerApi)
|
|
175
|
+
onCompiler: getValueOrErrorProxy(() => this.compilerApi),
|
|
176
|
+
...callOptions,
|
|
177
|
+
onAccount: getValueOrErrorProxy(() => this._resolveAccount(callOptions.onAccount))
|
|
157
178
|
};
|
|
158
179
|
}
|
|
159
180
|
}
|
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,SAASF,YAAY,CAAC;EAKlD;AACF;AACA;AACA;EACEG,WAAWA,CAAA,EAIT;IAAA,IAHA;MAAEC,KAAK,GAAG,EAAE;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H;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","_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';\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 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;AAItD;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAS,SAASF,YAAY,CAAC;EAKlD;AACF;AACA;AACA;EACEG,WAAWA,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+C,WAAWA,CACfC,OAAe,EAEM;IAAA,IADrB;MAAEV,SAAS;MAAE,GAAGtC;IAA+E,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAErG,OAAO,IAAI,CAACmC,eAAe,CAACE,SAAS,CAAC,CAACS,WAAW,CAACC,OAAO,EAAEhD,OAAO,CAAC;EACtE;EAEA,MAAMiD,aAAaA,CACjBP,IAA+B,EAC/BQ,GAAgD,EAEpB;IAAA,IAD5B;MAAEZ,SAAS;MAAE,GAAGtC;IAAiF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAEvG,OAAO,IAAI,CAACmC,eAAe,CAACE,SAAS,CAAC,CAACW,aAAa,CAACP,IAAI,EAAEQ,GAAG,EAAElD,OAAO,CAAC;EAC1E;EAESmD,WAAWA,CAAA,EAIlB;IAAA,IAJmBC,WAAgC,GAAAnD,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAKxD,OAAO;MACL,GAAG,IAAI,CAACY,QAAQ;MAChBwC,MAAM,EAAEzD,oBAAoB,CAAC,MAAM,IAAI,CAACmB,GAAG,CAAC;MAC5CD,UAAU,EAAElB,oBAAoB,CAAC,MAAM,IAAI,CAACgB,WAAW,CAAC;MACxD,GAAGwC,WAAW;MACdd,SAAS,EAAE1C,oBAAoB,CAAC,MAAM,IAAI,CAACwC,eAAe,CAACgB,WAAW,CAACd,SAAS,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,OAAO,SAASC,oBAAoBA,CAClCC,OAAoB,EACA;EACpB,OAAO,IAAIC,KAAK,CACd,CAAC,CAAC,EACFC,MAAM,CAACC,WAAW,CAAE,CAClB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,0BAA0B,EACpF,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,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Z,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,EACF,CAAC;AAGF;AACA,MAAM+B,iBAAiB,GAAGrB,YAAwE;AAClG,eAAeqB,iBAAiB"}
|
package/es/AeSdkWallet.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { v4 as uuid } from '@aeternity/uuid';
|
|
|
7
7
|
import AeSdk from "./AeSdk.mjs";
|
|
8
8
|
import verifyTransaction from "./tx/validator.mjs";
|
|
9
9
|
import RpcClient from "./aepp-wallet-communication/rpc/RpcClient.mjs";
|
|
10
|
-
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES,
|
|
10
|
+
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, RpcInvalidTransactionError, RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError } from "./aepp-wallet-communication/schema.mjs";
|
|
11
11
|
import { InternalError, UnknownRpcClientError } from "./utils/errors.mjs";
|
|
12
12
|
import { RPC_VERSION } from "./aepp-wallet-communication/rpc/types.mjs";
|
|
13
13
|
import jsonBig from "./utils/json-big.mjs";
|
|
@@ -184,7 +184,8 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
184
184
|
let {
|
|
185
185
|
tx,
|
|
186
186
|
onAccount = this.address,
|
|
187
|
-
returnSigned
|
|
187
|
+
returnSigned,
|
|
188
|
+
innerTx
|
|
188
189
|
} = _ref4;
|
|
189
190
|
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
190
191
|
if (!this.addresses().includes(onAccount)) {
|
|
@@ -193,9 +194,10 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
193
194
|
const parameters = {
|
|
194
195
|
onAccount,
|
|
195
196
|
aeppOrigin: origin,
|
|
196
|
-
aeppRpcClientId: id
|
|
197
|
+
aeppRpcClientId: id,
|
|
198
|
+
innerTx
|
|
197
199
|
};
|
|
198
|
-
if (returnSigned) {
|
|
200
|
+
if (returnSigned || innerTx === true) {
|
|
199
201
|
return {
|
|
200
202
|
signedTransaction: await this.signTransaction(tx, parameters)
|
|
201
203
|
};
|
|
@@ -210,7 +212,7 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
210
212
|
} catch (error) {
|
|
211
213
|
const validation = await verifyTransaction(tx, this.api);
|
|
212
214
|
if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
|
|
213
|
-
throw
|
|
215
|
+
throw error;
|
|
214
216
|
}
|
|
215
217
|
},
|
|
216
218
|
[METHODS.signMessage]: async (_ref5, origin) => {
|
|
@@ -230,6 +232,27 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
230
232
|
return {
|
|
231
233
|
signature: _Buffer.from(await this.signMessage(message, parameters)).toString('hex')
|
|
232
234
|
};
|
|
235
|
+
},
|
|
236
|
+
[METHODS.signTypedData]: async (_ref6, origin) => {
|
|
237
|
+
let {
|
|
238
|
+
domain,
|
|
239
|
+
aci,
|
|
240
|
+
data,
|
|
241
|
+
onAccount = this.address
|
|
242
|
+
} = _ref6;
|
|
243
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
244
|
+
if (!this.addresses().includes(onAccount)) {
|
|
245
|
+
throw new RpcPermissionDenyError(onAccount);
|
|
246
|
+
}
|
|
247
|
+
const parameters = {
|
|
248
|
+
...domain,
|
|
249
|
+
onAccount,
|
|
250
|
+
aeppOrigin: origin,
|
|
251
|
+
aeppRpcClientId: id
|
|
252
|
+
};
|
|
253
|
+
return {
|
|
254
|
+
signature: await this.signTypedData(data, aci, parameters)
|
|
255
|
+
};
|
|
233
256
|
}
|
|
234
257
|
})
|
|
235
258
|
};
|
package/es/AeSdkWallet.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkWallet.mjs","names":["v4","uuid","AeSdk","verifyTransaction","RpcClient","METHODS","RPC_STATUS","SUBSCRIPTION_TYPES","RpcBroadcastError","RpcInvalidTransactionError","RpcNotAuthorizeError","RpcPermissionDenyError","RpcUnsupportedProtocolError","InternalError","UnknownRpcClientError","RPC_VERSION","jsonBig","AeSdkWallet","constructor","_ref","name","id","type","onConnection","onSubscription","onDisconnect","onAskAccounts","options","_defineProperty","Map","_type","_pushAccountsToApps","_clients","Array","from","keys","filter","clientId","_isRpcClientSubscribed","map","_getClient","rpc","forEach","client","notify","updateAddress","getAccounts","selectAccount","address","addAccount","account","_getNode","ensureNodeConnected","node","url","api","$host","selectedNodeName","selectNode","networkId","getNetworkId","_isRpcClientConnected","updateNetwork","connectNode","get","addressSubscription","size","CONNECTED","status","connection","isConnected","_disconnectRpcClient","disconnect","DISCONNECTED","Set","removeRpcClient","delete","addRpcClient","clientConnection","disconnectParams","WAITING_FOR_CONNECTION_REQUEST","closeConnection","params","connect","_ref2","origin","version","icons","getWalletInfo","subscribeAddress","_ref3","value","subscribe","add","unsubscribe","subscription","addresses","sign","_ref4","tx","onAccount","returnSigned","includes","parameters","aeppOrigin","aeppRpcClientId","signedTransaction","signTransaction","parse","stringify","transactionHash","sendTransaction","verify","error","validation","length","message","signMessage","_ref5","signature","_Buffer","toString","set","shareWalletInfo","readyToConnect","window","location","current","selectedAddress","connected","a","reduce","acc"],"sources":["../src/AeSdkWallet.ts"],"sourcesContent":["import { v4 as uuid } from '@aeternity/uuid';\nimport AeSdk from './AeSdk';\nimport verifyTransaction from './tx/validator';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport {\n METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,\n RpcBroadcastError, RpcInvalidTransactionError,\n RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,\n} from './aepp-wallet-communication/schema';\nimport { InternalError, UnknownRpcClientError } from './utils/errors';\nimport AccountBase from './account/Base';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\nimport {\n Accounts,\n AeppApi,\n Network,\n RPC_VERSION,\n WalletApi,\n WalletInfo,\n} from './aepp-wallet-communication/rpc/types';\nimport { Encoded } from './utils/encoder';\nimport jsonBig from './utils/json-big';\n\ntype RpcClientWallet = RpcClient<AeppApi, WalletApi>;\n\ntype OnConnection = (\n clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string\n) => void;\n\ntype OnSubscription = (\n clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string\n) => void;\n\ntype OnDisconnect = (\n clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]\n) => void;\n\ntype OnAskAccounts = (\n clientId: string, params: undefined, origin: string\n) => void;\n\ninterface RpcClientsInfo {\n id: string;\n status: RPC_STATUS;\n connectNode: boolean;\n addressSubscription: Set<'connected' | 'current'>;\n rpc: RpcClientWallet;\n}\n\n/**\n * Contain functionality for aepp interaction and managing multiple aepps\n * @category aepp wallet communication\n */\nexport default class AeSdkWallet extends AeSdk {\n id: string;\n\n _type: WALLET_TYPE;\n\n name: string;\n\n _clients = new Map<string, RpcClientsInfo>();\n\n onConnection: OnConnection;\n\n onSubscription: OnSubscription;\n\n onDisconnect: OnDisconnect;\n\n onAskAccounts: OnAskAccounts;\n\n /**\n * @param options - Options\n * @param options.name - Wallet name\n * @param options.id - Wallet id\n * @param options.type - Wallet type\n * @param options.onConnection - Call-back function for incoming AEPP connection\n * @param options.onSubscription - Call-back function for incoming AEPP account subscription\n * @param options.onAskAccounts - Call-back function for incoming AEPP get address request\n * @param options.onDisconnect - Call-back function for disconnect event\n */\n constructor({\n name,\n id,\n type,\n onConnection,\n onSubscription,\n onDisconnect,\n onAskAccounts,\n ...options\n }: {\n id: string;\n type: WALLET_TYPE;\n name: string;\n onConnection: OnConnection;\n onSubscription: OnSubscription;\n onDisconnect: OnDisconnect;\n onAskAccounts: OnAskAccounts;\n } & ConstructorParameters<typeof AeSdk>[0]) {\n super(options);\n this.onConnection = onConnection;\n this.onSubscription = onSubscription;\n this.onDisconnect = onDisconnect;\n this.onAskAccounts = onAskAccounts;\n this.name = name;\n this.id = id;\n this._type = type;\n }\n\n _pushAccountsToApps(): void {\n if (this._clients == null) return;\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientSubscribed(clientId))\n .map((clientId) => this._getClient(clientId).rpc)\n .forEach((client) => client.notify(METHODS.updateAddress, this.getAccounts()));\n }\n\n override selectAccount(address: Encoded.AccountAddress): void {\n super.selectAccount(address);\n this._pushAccountsToApps();\n }\n\n override addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): void {\n super.addAccount(account, options);\n this._pushAccountsToApps();\n }\n\n _getNode(): { node: Network['node'] } {\n this.ensureNodeConnected();\n return { node: { url: this.api.$host, name: this.selectedNodeName } };\n }\n\n override async selectNode(name: string): Promise<void> {\n super.selectNode(name);\n const networkId = await this.api.getNetworkId();\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientConnected(clientId))\n .map((clientId) => this._getClient(clientId))\n .forEach((client) => {\n client.rpc.notify(METHODS.updateNetwork, {\n networkId,\n ...client.connectNode && this._getNode(),\n });\n });\n }\n\n _getClient(clientId: string): RpcClientsInfo {\n const client = this._clients.get(clientId);\n if (client == null) throw new UnknownRpcClientError(clientId);\n return client;\n }\n\n _isRpcClientSubscribed(clientId: string): boolean {\n return this._isRpcClientConnected(clientId)\n && this._getClient(clientId).addressSubscription.size !== 0;\n }\n\n _isRpcClientConnected(clientId: string): boolean {\n return RPC_STATUS.CONNECTED === this._getClient(clientId).status\n && this._getClient(clientId).rpc.connection.isConnected();\n }\n\n _disconnectRpcClient(clientId: string): void {\n const client = this._getClient(clientId);\n client.rpc.connection.disconnect();\n client.status = RPC_STATUS.DISCONNECTED;\n client.addressSubscription = new Set();\n }\n\n /**\n * Remove specific RpcClient by ID\n * @param id - Client ID\n */\n removeRpcClient(id: string): void {\n this._disconnectRpcClient(id);\n this._clients.delete(id);\n }\n\n /**\n * Add new client by AEPP connection\n * @param clientConnection - AEPP connection object\n * @returns Client ID\n */\n addRpcClient(clientConnection: BrowserConnection): string {\n // @TODO detect if aepp has some history based on origin????\n // if yes use this instance for connection\n const id = uuid();\n let disconnectParams: any;\n const client: RpcClientsInfo = {\n id,\n status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,\n addressSubscription: new Set(),\n connectNode: false,\n rpc: new RpcClient<AeppApi, WalletApi>(\n clientConnection,\n () => {\n this._clients.delete(id);\n this.onDisconnect(id, disconnectParams); // also related info\n },\n {\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n this._disconnectRpcClient(id);\n },\n // Store client info and prepare two fn for each client `connect` and `denyConnection`\n // which automatically prepare and send response for that client\n [METHODS.connect]: async ({\n name, version, icons, connectNode,\n }, origin) => {\n if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();\n\n await this.onConnection(id, { name, icons, connectNode }, origin);\n client.status = RPC_STATUS.CONNECTED;\n client.connectNode = connectNode;\n return {\n ...await this.getWalletInfo(),\n ...connectNode && this._getNode(),\n };\n },\n [METHODS.subscribeAddress]: async ({ type, value }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n\n await this.onSubscription(id, { type, value }, origin);\n\n switch (type) {\n case SUBSCRIPTION_TYPES.subscribe:\n client.addressSubscription.add(value);\n break;\n case SUBSCRIPTION_TYPES.unsubscribe:\n client.addressSubscription.delete(value);\n break;\n default:\n throw new InternalError(`Unknown subscription type: ${type}`);\n }\n\n return {\n subscription: Array.from(client.addressSubscription),\n address: this.getAccounts(),\n };\n },\n [METHODS.address]: async (params, origin) => {\n if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError();\n await this.onAskAccounts(id, params, origin);\n return this.addresses();\n },\n [METHODS.sign]: async ({ tx, onAccount = this.address, returnSigned }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n if (returnSigned) {\n return { signedTransaction: await this.signTransaction(tx, parameters) };\n }\n try {\n return jsonBig.parse(jsonBig.stringify({\n transactionHash: await this.sendTransaction(tx, { ...parameters, verify: false }),\n }));\n } catch (error) {\n const validation = await verifyTransaction(tx, this.api);\n if (validation.length > 0) throw new RpcInvalidTransactionError(validation);\n throw new RpcBroadcastError(error.message);\n }\n },\n [METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n return {\n signature: Buffer.from(await this.signMessage(message, parameters)).toString('hex'),\n };\n },\n },\n ),\n };\n this._clients.set(id, client);\n return id;\n }\n\n /**\n * Send shareWalletInfo message to notify AEPP about wallet\n * @param clientId - ID of RPC client send message to\n */\n async shareWalletInfo(clientId: string): Promise<void> {\n this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo());\n }\n\n /**\n * Get Wallet info object\n * @returns Object with wallet information\n */\n async getWalletInfo(): Promise<WalletInfo> {\n return {\n id: this.id,\n name: this.name,\n networkId: await this.api.getNetworkId(),\n origin: window.location.origin,\n type: this._type,\n };\n }\n\n /**\n * Get Wallet accounts\n * @returns Object with accounts information (\\{ connected: Object, current: Object \\})\n */\n getAccounts(): Accounts {\n return {\n current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},\n connected: this.addresses()\n .filter((a) => a !== this.selectedAddress)\n .reduce((acc, a) => ({ ...acc, [a]: {} }), {}),\n };\n }\n}\n"],"mappings":";;;;;AAAA,SAASA,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAAC,OACtCC,KAAK;AAAA,OACLC,iBAAiB;AAAA,OACjB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AAE,CAAC,CAAC;IACjD,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"AeSdkWallet.mjs","names":["v4","uuid","AeSdk","verifyTransaction","RpcClient","METHODS","RPC_STATUS","SUBSCRIPTION_TYPES","RpcInvalidTransactionError","RpcNotAuthorizeError","RpcPermissionDenyError","RpcUnsupportedProtocolError","InternalError","UnknownRpcClientError","RPC_VERSION","jsonBig","AeSdkWallet","constructor","_ref","name","id","type","onConnection","onSubscription","onDisconnect","onAskAccounts","options","_defineProperty","Map","_type","_pushAccountsToApps","_clients","Array","from","keys","filter","clientId","_isRpcClientSubscribed","map","_getClient","rpc","forEach","client","notify","updateAddress","getAccounts","selectAccount","address","addAccount","account","_getNode","ensureNodeConnected","node","url","api","$host","selectedNodeName","selectNode","networkId","getNetworkId","_isRpcClientConnected","updateNetwork","connectNode","get","addressSubscription","size","CONNECTED","status","connection","isConnected","_disconnectRpcClient","disconnect","DISCONNECTED","Set","removeRpcClient","delete","addRpcClient","clientConnection","disconnectParams","WAITING_FOR_CONNECTION_REQUEST","closeConnection","params","connect","_ref2","origin","version","icons","getWalletInfo","subscribeAddress","_ref3","value","subscribe","add","unsubscribe","subscription","addresses","sign","_ref4","tx","onAccount","returnSigned","innerTx","includes","parameters","aeppOrigin","aeppRpcClientId","signedTransaction","signTransaction","parse","stringify","transactionHash","sendTransaction","verify","error","validation","length","signMessage","_ref5","message","signature","_Buffer","toString","signTypedData","_ref6","domain","aci","data","set","shareWalletInfo","readyToConnect","window","location","current","selectedAddress","connected","a","reduce","acc"],"sources":["../src/AeSdkWallet.ts"],"sourcesContent":["import { v4 as uuid } from '@aeternity/uuid';\nimport AeSdk from './AeSdk';\nimport verifyTransaction from './tx/validator';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport {\n METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,\n RpcInvalidTransactionError,\n RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,\n} from './aepp-wallet-communication/schema';\nimport { InternalError, UnknownRpcClientError } from './utils/errors';\nimport AccountBase from './account/Base';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\nimport {\n Accounts,\n AeppApi,\n Network,\n RPC_VERSION,\n WalletApi,\n WalletInfo,\n} from './aepp-wallet-communication/rpc/types';\nimport { Encoded } from './utils/encoder';\nimport jsonBig from './utils/json-big';\n\ntype RpcClientWallet = RpcClient<AeppApi, WalletApi>;\n\ntype OnConnection = (\n clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string\n) => void;\n\ntype OnSubscription = (\n clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string\n) => void;\n\ntype OnDisconnect = (\n clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]\n) => void;\n\ntype OnAskAccounts = (\n clientId: string, params: undefined, origin: string\n) => void;\n\ninterface RpcClientsInfo {\n id: string;\n status: RPC_STATUS;\n connectNode: boolean;\n addressSubscription: Set<'connected' | 'current'>;\n rpc: RpcClientWallet;\n}\n\n/**\n * Contain functionality for aepp interaction and managing multiple aepps\n * @category aepp wallet communication\n */\nexport default class AeSdkWallet extends AeSdk {\n id: string;\n\n _type: WALLET_TYPE;\n\n name: string;\n\n _clients = new Map<string, RpcClientsInfo>();\n\n onConnection: OnConnection;\n\n onSubscription: OnSubscription;\n\n onDisconnect: OnDisconnect;\n\n onAskAccounts: OnAskAccounts;\n\n /**\n * @param options - Options\n * @param options.name - Wallet name\n * @param options.id - Wallet id\n * @param options.type - Wallet type\n * @param options.onConnection - Call-back function for incoming AEPP connection\n * @param options.onSubscription - Call-back function for incoming AEPP account subscription\n * @param options.onAskAccounts - Call-back function for incoming AEPP get address request\n * @param options.onDisconnect - Call-back function for disconnect event\n */\n constructor({\n name,\n id,\n type,\n onConnection,\n onSubscription,\n onDisconnect,\n onAskAccounts,\n ...options\n }: {\n id: string;\n type: WALLET_TYPE;\n name: string;\n onConnection: OnConnection;\n onSubscription: OnSubscription;\n onDisconnect: OnDisconnect;\n onAskAccounts: OnAskAccounts;\n } & ConstructorParameters<typeof AeSdk>[0]) {\n super(options);\n this.onConnection = onConnection;\n this.onSubscription = onSubscription;\n this.onDisconnect = onDisconnect;\n this.onAskAccounts = onAskAccounts;\n this.name = name;\n this.id = id;\n this._type = type;\n }\n\n _pushAccountsToApps(): void {\n if (this._clients == null) return;\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientSubscribed(clientId))\n .map((clientId) => this._getClient(clientId).rpc)\n .forEach((client) => client.notify(METHODS.updateAddress, this.getAccounts()));\n }\n\n override selectAccount(address: Encoded.AccountAddress): void {\n super.selectAccount(address);\n this._pushAccountsToApps();\n }\n\n override addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): void {\n super.addAccount(account, options);\n this._pushAccountsToApps();\n }\n\n _getNode(): { node: Network['node'] } {\n this.ensureNodeConnected();\n return { node: { url: this.api.$host, name: this.selectedNodeName } };\n }\n\n override async selectNode(name: string): Promise<void> {\n super.selectNode(name);\n const networkId = await this.api.getNetworkId();\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientConnected(clientId))\n .map((clientId) => this._getClient(clientId))\n .forEach((client) => {\n client.rpc.notify(METHODS.updateNetwork, {\n networkId,\n ...client.connectNode && this._getNode(),\n });\n });\n }\n\n _getClient(clientId: string): RpcClientsInfo {\n const client = this._clients.get(clientId);\n if (client == null) throw new UnknownRpcClientError(clientId);\n return client;\n }\n\n _isRpcClientSubscribed(clientId: string): boolean {\n return this._isRpcClientConnected(clientId)\n && this._getClient(clientId).addressSubscription.size !== 0;\n }\n\n _isRpcClientConnected(clientId: string): boolean {\n return RPC_STATUS.CONNECTED === this._getClient(clientId).status\n && this._getClient(clientId).rpc.connection.isConnected();\n }\n\n _disconnectRpcClient(clientId: string): void {\n const client = this._getClient(clientId);\n client.rpc.connection.disconnect();\n client.status = RPC_STATUS.DISCONNECTED;\n client.addressSubscription = new Set();\n }\n\n /**\n * Remove specific RpcClient by ID\n * @param id - Client ID\n */\n removeRpcClient(id: string): void {\n this._disconnectRpcClient(id);\n this._clients.delete(id);\n }\n\n /**\n * Add new client by AEPP connection\n * @param clientConnection - AEPP connection object\n * @returns Client ID\n */\n addRpcClient(clientConnection: BrowserConnection): string {\n // @TODO detect if aepp has some history based on origin????\n // if yes use this instance for connection\n const id = uuid();\n let disconnectParams: any;\n const client: RpcClientsInfo = {\n id,\n status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,\n addressSubscription: new Set(),\n connectNode: false,\n rpc: new RpcClient<AeppApi, WalletApi>(\n clientConnection,\n () => {\n this._clients.delete(id);\n this.onDisconnect(id, disconnectParams); // also related info\n },\n {\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n this._disconnectRpcClient(id);\n },\n // Store client info and prepare two fn for each client `connect` and `denyConnection`\n // which automatically prepare and send response for that client\n [METHODS.connect]: async ({\n name, version, icons, connectNode,\n }, origin) => {\n if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();\n\n await this.onConnection(id, { name, icons, connectNode }, origin);\n client.status = RPC_STATUS.CONNECTED;\n client.connectNode = connectNode;\n return {\n ...await this.getWalletInfo(),\n ...connectNode && this._getNode(),\n };\n },\n [METHODS.subscribeAddress]: async ({ type, value }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n\n await this.onSubscription(id, { type, value }, origin);\n\n switch (type) {\n case SUBSCRIPTION_TYPES.subscribe:\n client.addressSubscription.add(value);\n break;\n case SUBSCRIPTION_TYPES.unsubscribe:\n client.addressSubscription.delete(value);\n break;\n default:\n throw new InternalError(`Unknown subscription type: ${type}`);\n }\n\n return {\n subscription: Array.from(client.addressSubscription),\n address: this.getAccounts(),\n };\n },\n [METHODS.address]: async (params, origin) => {\n if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError();\n await this.onAskAccounts(id, params, origin);\n return this.addresses();\n },\n [METHODS.sign]: async (\n {\n tx, onAccount = this.address, returnSigned, innerTx,\n },\n origin,\n ) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = {\n onAccount, aeppOrigin: origin, aeppRpcClientId: id, innerTx,\n };\n if (returnSigned || innerTx === true) {\n return { signedTransaction: await this.signTransaction(tx, parameters) };\n }\n try {\n return jsonBig.parse(jsonBig.stringify({\n transactionHash: await this.sendTransaction(tx, { ...parameters, verify: false }),\n }));\n } catch (error) {\n const validation = await verifyTransaction(tx, this.api);\n if (validation.length > 0) throw new RpcInvalidTransactionError(validation);\n throw error;\n }\n },\n [METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n return {\n signature: Buffer.from(await this.signMessage(message, parameters)).toString('hex'),\n };\n },\n [METHODS.signTypedData]: async ({\n domain, aci, data, onAccount = this.address,\n }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = {\n ...domain, onAccount, aeppOrigin: origin, aeppRpcClientId: id,\n };\n return {\n signature: await this.signTypedData(data, aci, parameters),\n };\n },\n },\n ),\n };\n this._clients.set(id, client);\n return id;\n }\n\n /**\n * Send shareWalletInfo message to notify AEPP about wallet\n * @param clientId - ID of RPC client send message to\n */\n async shareWalletInfo(clientId: string): Promise<void> {\n this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo());\n }\n\n /**\n * Get Wallet info object\n * @returns Object with wallet information\n */\n async getWalletInfo(): Promise<WalletInfo> {\n return {\n id: this.id,\n name: this.name,\n networkId: await this.api.getNetworkId(),\n origin: window.location.origin,\n type: this._type,\n };\n }\n\n /**\n * Get Wallet accounts\n * @returns Object with accounts information (\\{ connected: Object, current: Object \\})\n */\n getAccounts(): Accounts {\n return {\n current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},\n connected: this.addresses()\n .filter((a) => a !== this.selectedAddress)\n .reduce((acc, a) => ({ ...acc, [a]: {} }), {}),\n };\n }\n}\n"],"mappings":";;;;;AAAA,SAASA,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAAC,OACtCC,KAAK;AAAA,OACLC,iBAAiB;AAAA,OACjBC,SAAS;AAAA,SAEdC,OAAO,EAAEC,UAAU,EAAEC,kBAAkB,EACvCC,0BAA0B,EAC1BC,oBAAoB,EAAEC,sBAAsB,EAAEC,2BAA2B;AAAA,SAElEC,aAAa,EAAEC,qBAAqB;AAAA,SAO3CC,WAAW;AAAA,OAKNC,OAAO;AA4Bd;AACA;AACA;AACA;AACA,eAAe,MAAMC,WAAW,SAASd,KAAK,CAAC;EAiB7C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEe,WAAWA,CAAAC,IAAA,EAiBiC;IAAA,IAjBhC;MACVC,IAAI;MACJC,EAAE;MACFC,IAAI;MACJC,YAAY;MACZC,cAAc;MACdC,YAAY;MACZC,aAAa;MACb,GAAGC;IASoC,CAAC,GAAAR,IAAA;IACxC,KAAK,CAACQ,OAAO,CAAC;IAACC,eAAA,mBAtCN,IAAIC,GAAG,EAA0B;IAuC1C,IAAI,CAACN,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,YAAY,GAAGA,YAAY;IAChC,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACN,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACS,KAAK,GAAGR,IAAI;EACnB;EAEAS,mBAAmBA,CAAA,EAAS;IAC1B,IAAI,IAAI,CAACC,QAAQ,IAAI,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,MAAM,CAAC;IAC7B,OAAOtB,EAAE;EACX;;EAEA;AACF;AACA;AACA;EACE,MAAM4G,eAAeA,CAAC5F,QAAgB,EAAiB;IACrD,IAAI,CAACG,UAAU,CAACH,QAAQ,CAAC,CAACI,GAAG,CAACG,MAAM,CAACtC,OAAO,CAAC4H,cAAc,EAAE,MAAM,IAAI,CAAC1C,aAAa,EAAE,CAAC;EAC1F;;EAEA;AACF;AACA;AACA;EACE,MAAMA,aAAaA,CAAA,EAAwB;IACzC,OAAO;MACLnE,EAAE,EAAE,IAAI,CAACA,EAAE;MACXD,IAAI,EAAE,IAAI,CAACA,IAAI;MACfuC,SAAS,EAAE,MAAM,IAAI,CAACJ,GAAG,CAACK,YAAY,EAAE;MACxCyB,MAAM,EAAE8C,MAAM,CAACC,QAAQ,CAAC/C,MAAM;MAC9B/D,IAAI,EAAE,IAAI,CAACQ;IACb,CAAC;EACH;;EAEA;AACF;AACA;AACA;EACEgB,WAAWA,CAAA,EAAa;IACtB,OAAO;MACLuF,OAAO,EAAE,IAAI,CAACC,eAAe,IAAI,IAAI,GAAG;QAAE,CAAC,IAAI,CAACA,eAAe,GAAG,CAAC;MAAE,CAAC,GAAG,CAAC,CAAC;MAC3EC,SAAS,EAAE,IAAI,CAACvC,SAAS,EAAE,CACxB5D,MAAM,CAAEoG,CAAC,IAAKA,CAAC,KAAK,IAAI,CAACF,eAAe,CAAC,CACzCG,MAAM,CAAC,CAACC,GAAG,EAAEF,CAAC,MAAM;QAAE,GAAGE,GAAG;QAAE,CAACF,CAAC,GAAG,CAAC;MAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;EACH;AACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Middleware as MiddlewareApi, MiddlewareOptionalParams } from './apis/middleware';
|
|
2
|
+
import { Encoded } from './utils/encoder';
|
|
3
|
+
import { ConsensusProtocolVersion } from './tx/builder/constants';
|
|
4
|
+
declare const bigIntPropertyNames: readonly [];
|
|
5
|
+
declare const numberPropertyNames: readonly [];
|
|
6
|
+
type BigIntPropertyNames = typeof bigIntPropertyNames[number];
|
|
7
|
+
type NumberPropertyNames = typeof numberPropertyNames[number];
|
|
8
|
+
type PreserveOptional<NewType, OrigType> = OrigType extends undefined ? NewType | undefined : NewType;
|
|
9
|
+
export type TransformMiddlewareType<Type> = Type extends (...args: infer Args) => infer Ret ? (...args: TransformMiddlewareType<Args>) => TransformMiddlewareType<Ret> : Type extends [infer Item, ...infer Rest] ? [TransformMiddlewareType<Item>, ...TransformMiddlewareType<Rest>] : Type extends Array<infer Item> ? Array<TransformMiddlewareType<Item>> : Type extends Promise<infer T> ? Promise<TransformMiddlewareType<T>> : Type extends {
|
|
10
|
+
[P in any]: any;
|
|
11
|
+
} ? {
|
|
12
|
+
[Property in keyof Type]: Property extends BigIntPropertyNames ? PreserveOptional<bigint, Type[Property]> : Property extends NumberPropertyNames ? PreserveOptional<number, Type[Property]> : Property extends 'txHash' ? PreserveOptional<Encoded.TxHash, Type[Property]> : Property extends 'bytecode' ? PreserveOptional<Encoded.ContractBytearray, Type[Property]> : TransformMiddlewareType<Type[Property]>;
|
|
13
|
+
} : Type;
|
|
14
|
+
type MiddlewareTransformedApi = new (...args: ConstructorParameters<typeof MiddlewareApi>) => {
|
|
15
|
+
[Name in keyof InstanceType<typeof MiddlewareApi>]: Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest' ? MiddlewareApi[Name] : TransformMiddlewareType<MiddlewareApi[Name]>;
|
|
16
|
+
};
|
|
17
|
+
export interface MiddlewareInfo {
|
|
18
|
+
url: string;
|
|
19
|
+
nodeNetworkId: string;
|
|
20
|
+
version: string;
|
|
21
|
+
consensusProtocolVersion: ConsensusProtocolVersion;
|
|
22
|
+
}
|
|
23
|
+
declare const Middleware_base: MiddlewareTransformedApi;
|
|
24
|
+
export default class Middleware extends Middleware_base {
|
|
25
|
+
/**
|
|
26
|
+
* @param url - Url for middleware API
|
|
27
|
+
* @param options - Options
|
|
28
|
+
* @param options.ignoreVersion - Don't check node version
|
|
29
|
+
* @param options.retryCount - Amount of extra requests to do in case of failure
|
|
30
|
+
* @param options.retryOverallDelay - Time in ms to wait between all retries
|
|
31
|
+
*/
|
|
32
|
+
constructor(url: string, { ignoreVersion, retryCount, retryOverallDelay, ...options }?: MiddlewareOptionalParams & {
|
|
33
|
+
ignoreVersion?: boolean;
|
|
34
|
+
retryCount?: number;
|
|
35
|
+
retryOverallDelay?: number;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {};
|