@aeternity/aepp-sdk 13.1.0 → 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/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 +2162 -1566
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +10 -0
- package/es/AeSdkBase.mjs +27 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +1 -1
- package/es/AeSdkWallet.mjs +53 -20
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Middleware.mjs.map +1 -1
- package/es/MiddlewareSubscriber.mjs +3 -3
- package/es/MiddlewareSubscriber.mjs.map +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +44 -2
- package/es/account/Base.mjs +95 -1
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +3 -0
- package/es/account/Generalized.mjs +15 -0
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +3 -0
- package/es/account/Ledger.mjs +15 -0
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +10 -0
- package/es/account/Memory.mjs +34 -0
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +4 -0
- package/es/account/Rpc.mjs +29 -0
- package/es/account/Rpc.mjs.map +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.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +1 -0
- package/es/aepp-wallet-communication/schema.mjs +20 -19
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/middleware/middleware.mjs.map +1 -1
- package/es/apis/middleware/models/index.mjs +340 -124
- package/es/apis/middleware/models/index.mjs.map +1 -1
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.mjs +1 -1
- package/es/chain.mjs.map +1 -1
- 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 +6 -6
- 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/Cli.mjs.map +1 -1
- package/es/contract/compiler/Http.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/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.mjs +26 -23
- 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.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -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.mjs.map +1 -1
- package/es/tx/builder/index.mjs.map +1 -1
- 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.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.map +1 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- 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.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.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.mjs +0 -1
- package/es/utils/typed-data.mjs.map +1 -1
- package/package.json +35 -35
- package/src/AeSdkBase.ts +36 -0
- package/src/AeSdkWallet.ts +36 -12
- package/src/account/Base.ts +84 -3
- package/src/account/Generalized.ts +15 -0
- package/src/account/Ledger.ts +15 -0
- package/src/account/Memory.ts +53 -1
- package/src/account/Rpc.ts +35 -0
- package/src/aepp-wallet-communication/rpc/types.ts +10 -0
- package/src/aepp-wallet-communication/schema.ts +1 -0
- package/src/chain.ts +1 -1
- package/src/contract/Contract.ts +1 -1
- package/src/contract/delegation-signature.ts +37 -11
- package/src/spend.ts +2 -2
- package/src/tx/builder/field-types/index.ts +28 -58
- package/src/tx/builder/field-types/u-int.ts +1 -1
- package/types-legacy/ts4.2/AeSdkBase.d.ts +10 -0
- package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.2/account/Base.d.ts +44 -2
- package/types-legacy/ts4.2/account/Generalized.d.ts +3 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +3 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +10 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +4 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +1 -0
- package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.2/spend.d.ts +2 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
- package/types-legacy/ts4.5/AeSdkBase.d.ts +10 -0
- package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.5/account/Base.d.ts +44 -2
- package/types-legacy/ts4.5/account/Generalized.d.ts +3 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +3 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +10 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +4 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +1 -0
- package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.5/spend.d.ts +2 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
package/src/AeSdkBase.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import { Encoded } from './utils/encoder';
|
|
7
7
|
import CompilerBase from './contract/compiler/Base';
|
|
8
8
|
import AeSdkMethods, { OnAccount, getValueOrErrorProxy, AeSdkMethodsOptions } from './AeSdkMethods';
|
|
9
|
+
import { AensName } from './tx/builder/constants';
|
|
9
10
|
|
|
10
11
|
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };
|
|
11
12
|
|
|
@@ -176,6 +177,41 @@ export default class AeSdkBase extends AeSdkMethods {
|
|
|
176
177
|
return this._resolveAccount(onAccount).signTypedData(data, aci, options);
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
async signDelegationToContract(
|
|
181
|
+
contractAddress: Encoded.ContractAddress,
|
|
182
|
+
{ onAccount, ...options }: { onAccount?: OnAccount }
|
|
183
|
+
& Parameters<AccountBase['signDelegationToContract']>[1] = {},
|
|
184
|
+
): Promise<Encoded.Signature> {
|
|
185
|
+
options.networkId ??= this.selectedNodeName !== null
|
|
186
|
+
? await this.api.getNetworkId() : undefined;
|
|
187
|
+
return this._resolveAccount(onAccount)
|
|
188
|
+
.signDelegationToContract(contractAddress, options);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async signNameDelegationToContract(
|
|
192
|
+
contractAddress: Encoded.ContractAddress,
|
|
193
|
+
name: AensName,
|
|
194
|
+
{ onAccount, ...options }: { onAccount?: OnAccount }
|
|
195
|
+
& Parameters<AccountBase['signNameDelegationToContract']>[2] = {},
|
|
196
|
+
): Promise<Encoded.Signature> {
|
|
197
|
+
options.networkId ??= this.selectedNodeName !== null
|
|
198
|
+
? await this.api.getNetworkId() : undefined;
|
|
199
|
+
return this._resolveAccount(onAccount)
|
|
200
|
+
.signNameDelegationToContract(contractAddress, name, options);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async signOracleQueryDelegationToContract(
|
|
204
|
+
contractAddress: Encoded.ContractAddress,
|
|
205
|
+
oracleQueryId: Encoded.OracleQueryId,
|
|
206
|
+
{ onAccount, ...options }: { onAccount?: OnAccount }
|
|
207
|
+
& Parameters<AccountBase['signOracleQueryDelegationToContract']>[2] = {},
|
|
208
|
+
): Promise<Encoded.Signature> {
|
|
209
|
+
options.networkId ??= this.selectedNodeName !== null
|
|
210
|
+
? await this.api.getNetworkId() : undefined;
|
|
211
|
+
return this._resolveAccount(onAccount)
|
|
212
|
+
.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
|
|
213
|
+
}
|
|
214
|
+
|
|
179
215
|
override _getOptions(callOptions: AeSdkMethodsOptions = {}): {
|
|
180
216
|
onNode: Node;
|
|
181
217
|
onAccount: AccountBase;
|
package/src/AeSdkWallet.ts
CHANGED
|
@@ -106,12 +106,23 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
106
106
|
this._type = type;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
_getAccountsForClient({ addressSubscription }: RpcClientsInfo): Accounts {
|
|
110
|
+
const { current, connected } = this.getAccounts();
|
|
111
|
+
return {
|
|
112
|
+
current: addressSubscription.has('current') || addressSubscription.has('connected')
|
|
113
|
+
? current : {},
|
|
114
|
+
connected: addressSubscription.has('connected') ? connected : {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
109
118
|
_pushAccountsToApps(): void {
|
|
110
119
|
if (this._clients == null) return;
|
|
111
120
|
Array.from(this._clients.keys())
|
|
112
|
-
.filter((clientId) => this.
|
|
113
|
-
.map((clientId) => this._getClient(clientId)
|
|
114
|
-
.
|
|
121
|
+
.filter((clientId) => this._isRpcClientConnected(clientId))
|
|
122
|
+
.map((clientId) => this._getClient(clientId))
|
|
123
|
+
.filter((client) => client.addressSubscription.size !== 0)
|
|
124
|
+
.forEach((client) => client.rpc
|
|
125
|
+
.notify(METHODS.updateAddress, this._getAccountsForClient(client)));
|
|
115
126
|
}
|
|
116
127
|
|
|
117
128
|
override selectAccount(address: Encoded.AccountAddress): void {
|
|
@@ -149,11 +160,6 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
149
160
|
return client;
|
|
150
161
|
}
|
|
151
162
|
|
|
152
|
-
_isRpcClientSubscribed(clientId: string): boolean {
|
|
153
|
-
return this._isRpcClientConnected(clientId)
|
|
154
|
-
&& this._getClient(clientId).addressSubscription.size !== 0;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
163
|
_isRpcClientConnected(clientId: string): boolean {
|
|
158
164
|
return RPC_STATUS.CONNECTED === this._getClient(clientId).status
|
|
159
165
|
&& this._getClient(clientId).rpc.connection.isConnected();
|
|
@@ -219,10 +225,10 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
219
225
|
[METHODS.subscribeAddress]: async ({ type, value }, origin) => {
|
|
220
226
|
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
221
227
|
|
|
222
|
-
await this.onSubscription(id, { type, value }, origin);
|
|
223
|
-
|
|
224
228
|
switch (type) {
|
|
225
229
|
case SUBSCRIPTION_TYPES.subscribe:
|
|
230
|
+
// TODO: remove `type` as it always subscribe
|
|
231
|
+
await this.onSubscription(id, { type, value }, origin);
|
|
226
232
|
client.addressSubscription.add(value);
|
|
227
233
|
break;
|
|
228
234
|
case SUBSCRIPTION_TYPES.unsubscribe:
|
|
@@ -234,11 +240,11 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
234
240
|
|
|
235
241
|
return {
|
|
236
242
|
subscription: Array.from(client.addressSubscription),
|
|
237
|
-
address: this.
|
|
243
|
+
address: this._getAccountsForClient(client),
|
|
238
244
|
};
|
|
239
245
|
},
|
|
240
246
|
[METHODS.address]: async (params, origin) => {
|
|
241
|
-
if (!this.
|
|
247
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
242
248
|
await this.onAskAccounts(id, params, origin);
|
|
243
249
|
return this.addresses();
|
|
244
250
|
},
|
|
@@ -295,6 +301,24 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
295
301
|
signature: await this.signTypedData(data, aci, parameters),
|
|
296
302
|
};
|
|
297
303
|
},
|
|
304
|
+
[METHODS.signDelegationToContract]: async ({
|
|
305
|
+
contractAddress, name, oracleQueryId, onAccount = this.address,
|
|
306
|
+
}, origin) => {
|
|
307
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
308
|
+
if (!this.addresses().includes(onAccount)) {
|
|
309
|
+
throw new RpcPermissionDenyError(onAccount);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };
|
|
313
|
+
const signature = await (
|
|
314
|
+
(name == null ? null : this
|
|
315
|
+
.signNameDelegationToContract(contractAddress, name, parameters))
|
|
316
|
+
?? (oracleQueryId == null ? null : this
|
|
317
|
+
.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, parameters))
|
|
318
|
+
?? this.signDelegationToContract(contractAddress, parameters)
|
|
319
|
+
);
|
|
320
|
+
return { signature };
|
|
321
|
+
},
|
|
298
322
|
},
|
|
299
323
|
),
|
|
300
324
|
};
|
package/src/account/Base.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Encoded } from '../utils/encoder';
|
|
2
2
|
import Node from '../Node';
|
|
3
3
|
import CompilerBase from '../contract/compiler/Base';
|
|
4
|
-
import { Int } from '../tx/builder/constants';
|
|
4
|
+
import { AensName, Int } from '../tx/builder/constants';
|
|
5
5
|
import { AciValue, Domain } from '../utils/typed-data';
|
|
6
|
+
import { NotImplementedError } from '../utils/errors';
|
|
6
7
|
|
|
7
8
|
interface AuthData {
|
|
8
9
|
fee?: Int;
|
|
@@ -60,14 +61,94 @@ export default abstract class AccountBase {
|
|
|
60
61
|
* @param options - Options
|
|
61
62
|
* @returns Signature
|
|
62
63
|
*/
|
|
63
|
-
abstract
|
|
64
|
+
// TODO: make abstract in the next major release
|
|
65
|
+
// eslint-disable-next-line class-methods-use-this
|
|
66
|
+
async signTypedData(
|
|
67
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
64
68
|
data: Encoded.ContractBytearray,
|
|
65
69
|
aci: AciValue,
|
|
66
70
|
options?: Domain & {
|
|
67
71
|
aeppOrigin?: string;
|
|
68
72
|
aeppRpcClientId?: string;
|
|
69
73
|
},
|
|
70
|
-
|
|
74
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
75
|
+
): Promise<Encoded.Signature> {
|
|
76
|
+
throw new NotImplementedError('signTypedData method');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sign delegation of AENS, oracle operations to a contract
|
|
81
|
+
* @param contractAddress - Address of a contract to delegate permissions to
|
|
82
|
+
* @param options - Options
|
|
83
|
+
* @returns Signature
|
|
84
|
+
*/
|
|
85
|
+
// TODO: make abstract in the next major release
|
|
86
|
+
// eslint-disable-next-line class-methods-use-this
|
|
87
|
+
async signDelegationToContract(
|
|
88
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
89
|
+
contractAddress: Encoded.ContractAddress,
|
|
90
|
+
options?: {
|
|
91
|
+
networkId?: string;
|
|
92
|
+
aeppOrigin?: string;
|
|
93
|
+
aeppRpcClientId?: string;
|
|
94
|
+
},
|
|
95
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
96
|
+
): Promise<Encoded.Signature> {
|
|
97
|
+
throw new NotImplementedError('signDelegationToContract method');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Sign delegation of an AENS name to a contract
|
|
102
|
+
* @param contractAddress - Address of a contract to delegate permissions to
|
|
103
|
+
* @param name - AENS name to manage by a contract
|
|
104
|
+
* @param options - Options
|
|
105
|
+
* @returns Signature
|
|
106
|
+
*/
|
|
107
|
+
// TODO: make abstract in the next major release
|
|
108
|
+
// eslint-disable-next-line class-methods-use-this
|
|
109
|
+
async signNameDelegationToContract(
|
|
110
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
111
|
+
contractAddress: Encoded.ContractAddress,
|
|
112
|
+
name: AensName,
|
|
113
|
+
options?: {
|
|
114
|
+
networkId?: string;
|
|
115
|
+
aeppOrigin?: string;
|
|
116
|
+
aeppRpcClientId?: string;
|
|
117
|
+
},
|
|
118
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
119
|
+
): Promise<Encoded.Signature> {
|
|
120
|
+
throw new NotImplementedError('signNameDelegationToContract method');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sign delegation of oracle query to a contract
|
|
125
|
+
*
|
|
126
|
+
* Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
|
|
127
|
+
* current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
|
|
128
|
+
*
|
|
129
|
+
* Warning! Implementations needs to ensure that oracle query and contract exists unless
|
|
130
|
+
* https://github.com/aeternity/aesophia/issues/474 is fixed.
|
|
131
|
+
*
|
|
132
|
+
* @param contractAddress - Address of a contract to delegate permissions to
|
|
133
|
+
* @param oracleQueryId - Oracle query ID to reply by a contract
|
|
134
|
+
* @param options - Options
|
|
135
|
+
* @returns Signature
|
|
136
|
+
*/
|
|
137
|
+
// TODO: make abstract in the next major release
|
|
138
|
+
// eslint-disable-next-line class-methods-use-this
|
|
139
|
+
async signOracleQueryDelegationToContract(
|
|
140
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
141
|
+
contractAddress: Encoded.ContractAddress,
|
|
142
|
+
oracleQueryId: Encoded.OracleQueryId,
|
|
143
|
+
options?: {
|
|
144
|
+
networkId?: string;
|
|
145
|
+
aeppOrigin?: string;
|
|
146
|
+
aeppRpcClientId?: string;
|
|
147
|
+
},
|
|
148
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
149
|
+
): Promise<Encoded.Signature> {
|
|
150
|
+
throw new NotImplementedError('signOracleQueryDelegationToContract method');
|
|
151
|
+
}
|
|
71
152
|
|
|
72
153
|
/**
|
|
73
154
|
* Sign data blob
|
|
@@ -43,6 +43,21 @@ export default class AccountGeneralized extends AccountBase {
|
|
|
43
43
|
throw new NotImplementedError('Can\'t sign using generalized account');
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// eslint-disable-next-line class-methods-use-this
|
|
47
|
+
override async signDelegationToContract(): Promise<Encoded.Signature> {
|
|
48
|
+
throw new NotImplementedError('signing delegation to contract using generalized account');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line class-methods-use-this
|
|
52
|
+
override async signNameDelegationToContract(): Promise<Encoded.Signature> {
|
|
53
|
+
throw new NotImplementedError('signing delegation to contract using generalized account');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line class-methods-use-this
|
|
57
|
+
override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
|
|
58
|
+
throw new NotImplementedError('signing delegation to contract using generalized account');
|
|
59
|
+
}
|
|
60
|
+
|
|
46
61
|
override async signTransaction(
|
|
47
62
|
tx: Encoded.Transaction,
|
|
48
63
|
{ authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],
|
package/src/account/Ledger.ts
CHANGED
|
@@ -45,6 +45,21 @@ export default class AccountLedger extends AccountBase {
|
|
|
45
45
|
throw new NotImplementedError('Typed data signing using Ledger HW');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// eslint-disable-next-line class-methods-use-this
|
|
49
|
+
override async signDelegationToContract(): Promise<Encoded.Signature> {
|
|
50
|
+
throw new NotImplementedError('signing delegation to contract using Ledger HW');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// eslint-disable-next-line class-methods-use-this
|
|
54
|
+
override async signNameDelegationToContract(): Promise<Encoded.Signature> {
|
|
55
|
+
throw new NotImplementedError('signing delegation to contract using Ledger HW');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line class-methods-use-this
|
|
59
|
+
override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
|
|
60
|
+
throw new NotImplementedError('signing delegation to contract using Ledger HW');
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
override async signTransaction(
|
|
49
64
|
tx: Encoded.Transaction,
|
|
50
65
|
{ innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},
|
package/src/account/Memory.ts
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
import { concatBuffers } from '../utils/other';
|
|
10
10
|
import { hashTypedData, AciValue } from '../utils/typed-data';
|
|
11
11
|
import { buildTx } from '../tx/builder';
|
|
12
|
-
import { Tag } from '../tx/builder/constants';
|
|
12
|
+
import { Tag, AensName } from '../tx/builder/constants';
|
|
13
|
+
import { produceNameId } from '../tx/builder/helpers';
|
|
13
14
|
|
|
14
15
|
const secretKeys = new WeakMap();
|
|
15
16
|
|
|
@@ -89,4 +90,55 @@ export default class AccountMemory extends AccountBase {
|
|
|
89
90
|
const signature = await this.sign(dHash, options);
|
|
90
91
|
return encode(signature, Encoding.Signature);
|
|
91
92
|
}
|
|
93
|
+
|
|
94
|
+
override async signDelegationToContract(
|
|
95
|
+
contractAddress: Encoded.ContractAddress,
|
|
96
|
+
{ networkId }: { networkId?: string } = {},
|
|
97
|
+
): Promise<Encoded.Signature> {
|
|
98
|
+
if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
|
|
99
|
+
const payload = concatBuffers([
|
|
100
|
+
Buffer.from(networkId),
|
|
101
|
+
decode(this.address),
|
|
102
|
+
decode(contractAddress),
|
|
103
|
+
]);
|
|
104
|
+
const signature = await this.sign(payload);
|
|
105
|
+
return encode(signature, Encoding.Signature);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
override async signNameDelegationToContract(
|
|
109
|
+
contractAddress: Encoded.ContractAddress,
|
|
110
|
+
name: AensName,
|
|
111
|
+
{ networkId }: { networkId?: string } = {},
|
|
112
|
+
): Promise<Encoded.Signature> {
|
|
113
|
+
if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
|
|
114
|
+
const payload = concatBuffers([
|
|
115
|
+
Buffer.from(networkId),
|
|
116
|
+
decode(this.address),
|
|
117
|
+
decode(produceNameId(name)),
|
|
118
|
+
decode(contractAddress),
|
|
119
|
+
]);
|
|
120
|
+
const signature = await this.sign(payload);
|
|
121
|
+
return encode(signature, Encoding.Signature);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
override async signOracleQueryDelegationToContract(
|
|
125
|
+
contractAddress: Encoded.ContractAddress,
|
|
126
|
+
oracleQueryId: Encoded.OracleQueryId,
|
|
127
|
+
{ networkId }: { networkId?: string } = {},
|
|
128
|
+
): Promise<Encoded.Signature> {
|
|
129
|
+
const oracleQueryIdDecoded = decode(oracleQueryId);
|
|
130
|
+
const addressDecoded = decode(this.address);
|
|
131
|
+
// TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475
|
|
132
|
+
if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {
|
|
133
|
+
throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);
|
|
134
|
+
}
|
|
135
|
+
if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
|
|
136
|
+
const payload = concatBuffers([
|
|
137
|
+
Buffer.from(networkId),
|
|
138
|
+
oracleQueryIdDecoded,
|
|
139
|
+
decode(contractAddress),
|
|
140
|
+
]);
|
|
141
|
+
const signature = await this.sign(payload);
|
|
142
|
+
return encode(signature, Encoding.Signature);
|
|
143
|
+
}
|
|
92
144
|
}
|
package/src/account/Rpc.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ArgumentError, NotImplementedError, UnsupportedProtocolError } from '..
|
|
|
4
4
|
import { Encoded } from '../utils/encoder';
|
|
5
5
|
import RpcClient from '../aepp-wallet-communication/rpc/RpcClient';
|
|
6
6
|
import { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';
|
|
7
|
+
import { AensName } from '../tx/builder/constants';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Account provided by wallet
|
|
@@ -69,4 +70,38 @@ export default class AccountRpc extends AccountBase {
|
|
|
69
70
|
});
|
|
70
71
|
return signature;
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
override async signDelegationToContract(
|
|
75
|
+
contractAddress: Encoded.ContractAddress,
|
|
76
|
+
): Promise<Encoded.Signature> {
|
|
77
|
+
const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
78
|
+
onAccount: this.address,
|
|
79
|
+
contractAddress,
|
|
80
|
+
});
|
|
81
|
+
return signature;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override async signNameDelegationToContract(
|
|
85
|
+
contractAddress: Encoded.ContractAddress,
|
|
86
|
+
name: AensName,
|
|
87
|
+
): Promise<Encoded.Signature> {
|
|
88
|
+
const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
89
|
+
onAccount: this.address,
|
|
90
|
+
contractAddress,
|
|
91
|
+
name,
|
|
92
|
+
});
|
|
93
|
+
return signature;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override async signOracleQueryDelegationToContract(
|
|
97
|
+
contractAddress: Encoded.ContractAddress,
|
|
98
|
+
oracleQueryId: Encoded.OracleQueryId,
|
|
99
|
+
): Promise<Encoded.Signature> {
|
|
100
|
+
const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
101
|
+
onAccount: this.address,
|
|
102
|
+
contractAddress,
|
|
103
|
+
oracleQueryId,
|
|
104
|
+
});
|
|
105
|
+
return signature;
|
|
106
|
+
}
|
|
72
107
|
}
|
|
@@ -3,6 +3,7 @@ import { Domain, AciValue } from '../../utils/typed-data';
|
|
|
3
3
|
import { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema';
|
|
4
4
|
import { TransformNodeType } from '../../Node';
|
|
5
5
|
import { SignedTx } from '../../apis/node';
|
|
6
|
+
import { AensName } from '../../tx/builder/constants';
|
|
6
7
|
|
|
7
8
|
export interface WalletInfo {
|
|
8
9
|
id: string;
|
|
@@ -82,6 +83,15 @@ export interface WalletApi {
|
|
|
82
83
|
onAccount: Encoded.AccountAddress;
|
|
83
84
|
},
|
|
84
85
|
) => Promise<{ signature: Encoded.Signature }>;
|
|
86
|
+
|
|
87
|
+
[METHODS.signDelegationToContract]: (
|
|
88
|
+
p: {
|
|
89
|
+
contractAddress: Encoded.ContractAddress;
|
|
90
|
+
name?: AensName;
|
|
91
|
+
oracleQueryId?: Encoded.OracleQueryId;
|
|
92
|
+
onAccount: Encoded.AccountAddress;
|
|
93
|
+
},
|
|
94
|
+
) => Promise<{ signature: Encoded.Signature }>;
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
export interface AeppApi {
|
|
@@ -37,6 +37,7 @@ export const enum METHODS {
|
|
|
37
37
|
sign = 'transaction.sign',
|
|
38
38
|
signMessage = 'message.sign',
|
|
39
39
|
signTypedData = 'typedData.sign',
|
|
40
|
+
signDelegationToContract = 'delegationToContract.sign',
|
|
40
41
|
subscribeAddress = 'address.subscribe',
|
|
41
42
|
updateNetwork = 'networkId.update',
|
|
42
43
|
closeConnection = 'connection.close',
|
package/src/chain.ts
CHANGED
|
@@ -197,7 +197,7 @@ export async function sendTransaction(
|
|
|
197
197
|
rawTx: tx,
|
|
198
198
|
};
|
|
199
199
|
// wait for transaction confirmation
|
|
200
|
-
if (confirm != null &&
|
|
200
|
+
if (confirm != null && +confirm > 0) {
|
|
201
201
|
const c = typeof confirm === 'boolean' ? undefined : confirm;
|
|
202
202
|
return {
|
|
203
203
|
...txData,
|
package/src/contract/Contract.ts
CHANGED
|
@@ -312,7 +312,7 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
312
312
|
|
|
313
313
|
if (fn == null) throw new MissingFunctionNameError();
|
|
314
314
|
if (fn === 'init' && callStatic !== true) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
|
|
315
|
-
if (fn !== 'init' && opt.amount != null && opt.amount > 0 && !fnAci.payable) {
|
|
315
|
+
if (fn !== 'init' && opt.amount != null && +opt.amount > 0 && !fnAci.payable) {
|
|
316
316
|
throw new NotPayableFunctionError(opt.amount, fn);
|
|
317
317
|
}
|
|
318
318
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { decode, Encoded } from '../utils/encoder';
|
|
2
|
+
import { ArgumentError } from '../utils/errors';
|
|
2
3
|
import { AensName } from '../tx/builder/constants';
|
|
3
4
|
import AccountBase from '../account/Base';
|
|
4
|
-
import {
|
|
5
|
-
import { isNameValid, produceNameId } from '../tx/builder/helpers';
|
|
5
|
+
import { isNameValid } from '../tx/builder/helpers';
|
|
6
6
|
import Node from '../Node';
|
|
7
7
|
|
|
8
|
+
function ensureOracleQuery(oq: string): asserts oq is Encoded.OracleQueryId {
|
|
9
|
+
if (!oq.startsWith('oq_')) throw new ArgumentError('oq', 'oracle query', oq);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Helper to generate a signature to delegate
|
|
10
14
|
* - pre-claim/claim/transfer/revoke of a name to a contract.
|
|
@@ -17,6 +21,7 @@ import Node from '../Node';
|
|
|
17
21
|
* @param options.onAccount - Account to use
|
|
18
22
|
* @param options.onNode - Node to use
|
|
19
23
|
* @returns Signature
|
|
24
|
+
* @deprecated use methods `sign*DelegationToContract` of Account instance instead
|
|
20
25
|
* @example
|
|
21
26
|
* ```js
|
|
22
27
|
* const aeSdk = new AeSdk({ ... })
|
|
@@ -42,15 +47,36 @@ import Node from '../Node';
|
|
|
42
47
|
export default async function createDelegationSignature(
|
|
43
48
|
contractAddress: Encoded.ContractAddress,
|
|
44
49
|
ids: Array<Encoded.Any | AensName>,
|
|
45
|
-
|
|
50
|
+
{ onAccount, omitAddress, ...options }: {
|
|
51
|
+
omitAddress?: boolean;
|
|
52
|
+
onAccount: AccountBase;
|
|
53
|
+
onNode: Node;
|
|
54
|
+
},
|
|
46
55
|
): Promise<Uint8Array> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (ids.length > 1) throw new ArgumentError('ids', 'shorter than 2', ids);
|
|
57
|
+
const networkId = await options.onNode.getNetworkId();
|
|
58
|
+
if (ids.length === 0) {
|
|
59
|
+
if (omitAddress === true) {
|
|
60
|
+
throw new ArgumentError('omitAddress', 'equal false', omitAddress);
|
|
61
|
+
}
|
|
62
|
+
return decode(await onAccount.signDelegationToContract(contractAddress, { networkId }));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const [payload] = ids;
|
|
66
|
+
if (isNameValid(payload)) {
|
|
67
|
+
if (omitAddress === true) {
|
|
68
|
+
throw new ArgumentError('omitAddress', 'equal false', omitAddress);
|
|
69
|
+
}
|
|
70
|
+
return decode(
|
|
71
|
+
await onAccount.signNameDelegationToContract(contractAddress, payload, { networkId }),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ensureOracleQuery(payload);
|
|
76
|
+
if (omitAddress !== true) {
|
|
77
|
+
throw new ArgumentError('omitAddress', 'equal true', omitAddress);
|
|
78
|
+
}
|
|
79
|
+
return decode(
|
|
80
|
+
await onAccount.signOracleQueryDelegationToContract(contractAddress, payload, { networkId }),
|
|
55
81
|
);
|
|
56
82
|
}
|
package/src/spend.ts
CHANGED
|
@@ -60,11 +60,11 @@ interface SpendOptions extends SpendOptionsType {}
|
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export async function transferFunds(
|
|
63
|
-
fraction: number | string,
|
|
63
|
+
fraction: number | string, // TODO: accept only number
|
|
64
64
|
recipientIdOrName: AensName | Encoded.AccountAddress,
|
|
65
65
|
options: TransferFundsOptions,
|
|
66
66
|
): ReturnType<typeof sendTransaction> {
|
|
67
|
-
if (fraction < 0 || fraction > 1) {
|
|
67
|
+
if (+fraction < 0 || +fraction > 1) {
|
|
68
68
|
throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);
|
|
69
69
|
}
|
|
70
70
|
const recipientId = await resolveName<Encoding.AccountAddress>(
|
|
@@ -1,61 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
// TODO: remove after fixing https://github.com/Gerrit0/typedoc-plugin-missing-exports/issues/15
|
|
31
|
-
const abiVersion = _abiVersion;
|
|
32
|
-
const address = _address;
|
|
33
|
-
const array = _array;
|
|
34
|
-
const boolean = _boolean;
|
|
35
|
-
const coinAmount = _coinAmount;
|
|
36
|
-
const ctVersion = _ctVersion;
|
|
37
|
-
const deposit = _deposit;
|
|
38
|
-
const encoded = _encoded;
|
|
39
|
-
const entry = _entry;
|
|
40
|
-
const enumeration = _enumeration;
|
|
41
|
-
const fee = _fee;
|
|
42
|
-
const field = _field;
|
|
43
|
-
const gasLimit = _gasLimit;
|
|
44
|
-
const gasPrice = _gasPrice;
|
|
45
|
-
const map = _map;
|
|
46
|
-
const mptree = _mptree;
|
|
47
|
-
const name = _name;
|
|
48
|
-
const nameFee = _nameFee;
|
|
49
|
-
const nameId = _nameId;
|
|
50
|
-
const nonce = _nonce;
|
|
51
|
-
const pointers = _pointers;
|
|
52
|
-
const raw = _raw;
|
|
53
|
-
const shortUInt = _shortUInt;
|
|
54
|
-
const shortUIntConst = _shortUIntConst;
|
|
55
|
-
const string = _string;
|
|
56
|
-
const ttl = _ttl;
|
|
57
|
-
const uInt = _uInt;
|
|
58
|
-
const wrapped = _wrapped;
|
|
1
|
+
import abiVersion from './abi-version';
|
|
2
|
+
import address from './address';
|
|
3
|
+
import array from './array';
|
|
4
|
+
import boolean from './boolean';
|
|
5
|
+
import coinAmount from './coin-amount';
|
|
6
|
+
import ctVersion from './ct-version';
|
|
7
|
+
import deposit from './deposit';
|
|
8
|
+
import encoded from './encoded';
|
|
9
|
+
import entry from './entry';
|
|
10
|
+
import enumeration from './enumeration';
|
|
11
|
+
import fee from './fee';
|
|
12
|
+
import field from './field';
|
|
13
|
+
import gasLimit from './gas-limit';
|
|
14
|
+
import gasPrice from './gas-price';
|
|
15
|
+
import map from './map';
|
|
16
|
+
import mptree from './mptree';
|
|
17
|
+
import name from './name';
|
|
18
|
+
import nameFee from './name-fee';
|
|
19
|
+
import nameId from './name-id';
|
|
20
|
+
import nonce from './nonce';
|
|
21
|
+
import pointers from './pointers';
|
|
22
|
+
import raw from './raw';
|
|
23
|
+
import shortUInt from './short-u-int';
|
|
24
|
+
import shortUIntConst from './short-u-int-const';
|
|
25
|
+
import string from './string';
|
|
26
|
+
import ttl from './ttl';
|
|
27
|
+
import uInt from './u-int';
|
|
28
|
+
import wrapped from './wrapped';
|
|
59
29
|
|
|
60
30
|
export type BinaryData = Buffer | Buffer[] | Buffer[][]
|
|
61
31
|
| Array<[Buffer, Array<[Buffer, Buffer[]]>]>;
|
|
@@ -5,7 +5,7 @@ import { toBytes } from '../../../utils/bytes';
|
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
serialize(value: Int): Buffer {
|
|
8
|
-
if (value < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
|
|
8
|
+
if (+value < 0) throw new ArgumentError('value', 'greater or equal to 0', value);
|
|
9
9
|
return toBytes(value, true);
|
|
10
10
|
},
|
|
11
11
|
|