@aeternity/aepp-sdk 14.0.0 → 14.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/LICENSE +1 -1
- package/README.md +11 -19
- package/dist/aepp-sdk.browser-script.cjs +1 -1
- package/dist/aepp-sdk.browser-script.cjs.LICENSE.txt +2 -0
- package/dist/aepp-sdk.browser-script.cjs.map +1 -1
- package/dist/aepp-sdk.browser.cjs +1 -1
- package/dist/aepp-sdk.browser.cjs.map +1 -1
- package/dist/aepp-sdk.cjs +11678 -6969
- package/dist/aepp-sdk.cjs.map +1 -1
- package/es/AeSdkBase.d.ts +10 -1
- package/es/AeSdkBase.js +12 -2
- package/es/AeSdkBase.js.map +1 -1
- package/es/AeSdkMethods.d.ts +1 -1
- package/es/AeSdkMethods.js.map +1 -1
- package/es/AeSdkWallet.js +1 -1
- package/es/AeSdkWallet.js.map +1 -1
- package/es/Middleware.d.ts +5 -1
- package/es/Middleware.js +7 -2
- package/es/Middleware.js.map +1 -1
- package/es/MiddlewareSubscriber.d.ts +3 -0
- package/es/MiddlewareSubscriber.js +4 -0
- package/es/MiddlewareSubscriber.js.map +1 -1
- package/es/Node.d.ts +6 -1
- package/es/Node.js +28 -4
- package/es/Node.js.map +1 -1
- package/es/account/Base.d.ts +12 -0
- package/es/account/Base.js +1 -0
- package/es/account/Base.js.map +1 -1
- package/es/account/BaseFactory.d.ts +1 -0
- package/es/account/BaseFactory.js +1 -0
- package/es/account/BaseFactory.js.map +1 -1
- package/es/account/Generalized.d.ts +5 -0
- package/es/account/Generalized.js +9 -0
- package/es/account/Generalized.js.map +1 -1
- package/es/account/Ledger.d.ts +5 -0
- package/es/account/Ledger.js +9 -0
- package/es/account/Ledger.js.map +1 -1
- package/es/account/LedgerFactory.d.ts +2 -0
- package/es/account/LedgerFactory.js +10 -4
- package/es/account/LedgerFactory.js.map +1 -1
- package/es/account/Memory.d.ts +5 -0
- package/es/account/Memory.js +14 -5
- package/es/account/Memory.js.map +1 -1
- package/es/account/Metamask.d.ts +8 -0
- package/es/account/Metamask.js +13 -0
- package/es/account/Metamask.js.map +1 -1
- package/es/account/MetamaskFactory.d.ts +20 -2
- package/es/account/MetamaskFactory.js +93 -39
- package/es/account/MetamaskFactory.js.map +1 -1
- package/es/account/MnemonicFactory.d.ts +12 -2
- package/es/account/MnemonicFactory.js +48 -24
- package/es/account/MnemonicFactory.js.map +1 -1
- package/es/account/Rpc.d.ts +5 -0
- package/es/account/Rpc.js +8 -0
- package/es/account/Rpc.js.map +1 -1
- package/es/aens.d.ts +25 -5
- package/es/aens.js +52 -18
- package/es/aens.js.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.js.map +1 -1
- package/es/apis/middleware/middleware.d.ts +99 -9
- package/es/apis/middleware/middleware.js +560 -91
- package/es/apis/middleware/middleware.js.map +1 -1
- package/es/apis/middleware/models/index.d.ts +1267 -1582
- package/es/apis/middleware/models/index.js +1 -1363
- package/es/apis/middleware/models/index.js.map +1 -1
- package/es/apis/middleware/models/mappers.d.ts +126 -56
- package/es/apis/middleware/models/mappers.js +6250 -2989
- package/es/apis/middleware/models/mappers.js.map +1 -1
- package/es/apis/middleware/models/parameters.d.ts +54 -33
- package/es/apis/middleware/models/parameters.js +389 -134
- package/es/apis/middleware/models/parameters.js.map +1 -1
- package/es/apis/node/models/index.d.ts +60 -15
- package/es/apis/node/models/index.js.map +1 -1
- package/es/apis/node/models/mappers.d.ts +3 -0
- package/es/apis/node/models/mappers.js +130 -2
- package/es/apis/node/models/mappers.js.map +1 -1
- package/es/apis/node/node.d.ts +13 -1
- package/es/apis/node/node.js +54 -0
- package/es/apis/node/node.js.map +1 -1
- package/es/chain.d.ts +19 -6
- package/es/chain.js +30 -24
- package/es/chain.js.map +1 -1
- package/es/channel/Contract.d.ts +6 -3
- package/es/channel/Contract.js +5 -2
- package/es/channel/Contract.js.map +1 -1
- package/es/channel/Spend.d.ts +1 -1
- package/es/channel/Spend.js.map +1 -1
- package/es/channel/handlers.js +1 -2
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/internal.d.ts +1 -1
- package/es/channel/internal.js +2 -2
- package/es/channel/internal.js.map +1 -1
- package/es/contract/Contract.d.ts +13 -2
- package/es/contract/Contract.js +22 -12
- package/es/contract/Contract.js.map +1 -1
- package/es/contract/compiler/Base.d.ts +1 -0
- package/es/contract/compiler/Base.js +1 -0
- package/es/contract/compiler/Base.js.map +1 -1
- package/es/contract/compiler/Cli.d.ts +2 -1
- package/es/contract/compiler/Cli.js +11 -9
- package/es/contract/compiler/Cli.js.map +1 -1
- package/es/contract/compiler/Http.d.ts +2 -1
- package/es/contract/compiler/Http.js +3 -2
- package/es/contract/compiler/Http.js.map +1 -1
- package/es/contract/compiler/getFileSystem.d.ts +1 -0
- package/es/contract/compiler/getFileSystem.js +1 -0
- package/es/contract/compiler/getFileSystem.js.map +1 -1
- package/es/contract/ga.d.ts +3 -3
- package/es/contract/ga.js +3 -3
- package/es/contract/ga.js.map +1 -1
- package/es/index-browser.d.ts +32 -2
- package/es/index-browser.js +32 -2
- package/es/index-browser.js.map +1 -1
- package/es/oracle/Oracle.d.ts +10 -1
- package/es/oracle/Oracle.js +16 -6
- package/es/oracle/Oracle.js.map +1 -1
- package/es/oracle/OracleBase.d.ts +15 -2
- package/es/oracle/OracleBase.js +23 -1
- package/es/oracle/OracleBase.js.map +1 -1
- package/es/oracle/OracleClient.d.ts +3 -0
- package/es/oracle/OracleClient.js +6 -1
- package/es/oracle/OracleClient.js.map +1 -1
- package/es/spend.js +1 -1
- package/es/spend.js.map +1 -1
- package/es/tx/builder/common.js +6 -3
- package/es/tx/builder/common.js.map +1 -1
- package/es/tx/builder/constants.d.ts +53 -3
- package/es/tx/builder/constants.js +62 -12
- package/es/tx/builder/constants.js.map +1 -1
- package/es/tx/builder/delegation/schema.js +15 -0
- package/es/tx/builder/delegation/schema.js.map +1 -1
- package/es/tx/builder/entry/constants.d.ts +4 -1
- package/es/tx/builder/entry/constants.js +10 -1
- package/es/tx/builder/entry/constants.js.map +1 -1
- package/es/tx/builder/entry/index.js +1 -2
- package/es/tx/builder/entry/index.js.map +1 -1
- package/es/tx/builder/field-types/ct-version.js +1 -2
- package/es/tx/builder/field-types/ct-version.js.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +1 -1
- package/es/tx/builder/field-types/fee.js +4 -4
- package/es/tx/builder/field-types/fee.js.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +3 -0
- package/es/tx/builder/field-types/gas-price.js +1 -1
- package/es/tx/builder/field-types/gas-price.js.map +1 -1
- package/es/tx/builder/field-types/name-fee.js +1 -1
- package/es/tx/builder/field-types/name-fee.js.map +1 -1
- package/es/tx/builder/field-types/name-id.js +2 -2
- package/es/tx/builder/field-types/name-id.js.map +1 -1
- package/es/tx/builder/field-types/nonce.d.ts +1 -1
- package/es/tx/builder/field-types/nonce.js.map +1 -1
- package/es/tx/builder/field-types/pointers.js +3 -3
- package/es/tx/builder/field-types/pointers.js.map +1 -1
- package/es/tx/builder/field-types/ttl.js +1 -2
- package/es/tx/builder/field-types/ttl.js.map +1 -1
- package/es/tx/builder/helpers.d.ts +18 -12
- package/es/tx/builder/helpers.js +25 -17
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/schema.d.ts +27 -24
- package/es/tx/builder/schema.generated.d.ts +12 -12
- package/es/tx/builder/schema.generated.js.map +1 -1
- package/es/tx/builder/schema.js +5 -3
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/execution-cost.d.ts +3 -0
- package/es/tx/execution-cost.js +7 -4
- package/es/tx/execution-cost.js.map +1 -1
- package/es/tx/transaction-signer.d.ts +1 -0
- package/es/tx/transaction-signer.js +1 -0
- package/es/tx/transaction-signer.js.map +1 -1
- package/es/tx/validator.js +4 -3
- package/es/tx/validator.js.map +1 -1
- package/es/utils/MiddlewarePage.d.ts +4 -3
- package/es/utils/MiddlewarePage.js.map +1 -1
- package/es/utils/amount-formatter.d.ts +15 -1
- package/es/utils/amount-formatter.js +17 -1
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/autorest.d.ts +1 -1
- package/es/utils/autorest.js +10 -4
- package/es/utils/autorest.js.map +1 -1
- package/es/utils/bignumber.d.ts +1 -1
- package/es/utils/bignumber.js +1 -1
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.d.ts +3 -1
- package/es/utils/bytes.js +3 -1
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.d.ts +48 -15
- package/es/utils/crypto.js +80 -29
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/encoder-types.d.ts +1 -1
- package/es/utils/encoder-types.js +1 -1
- package/es/utils/encoder-types.js.map +1 -1
- package/es/utils/encoder.d.ts +2 -0
- package/es/utils/encoder.js +2 -0
- package/es/utils/encoder.js.map +1 -1
- package/es/utils/errors.d.ts +2 -2
- package/es/utils/errors.js +2 -2
- package/es/utils/errors.js.map +1 -1
- package/es/utils/json-big.js +1 -1
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/jwt.js +3 -3
- package/es/utils/jwt.js.map +1 -1
- package/es/utils/typed-data.d.ts +5 -0
- package/es/utils/typed-data.js +6 -0
- package/es/utils/typed-data.js.map +1 -1
- package/package.json +50 -51
package/es/Node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
2
2
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
4
3
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
4
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
5
5
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
6
6
|
// eslint-disable-next-line max-classes-per-file
|
|
7
7
|
|
|
@@ -10,12 +10,18 @@ import { genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterP
|
|
|
10
10
|
import { Node as NodeApi } from './apis/node/index.js';
|
|
11
11
|
import { UnsupportedVersionError } from './utils/errors.js';
|
|
12
12
|
import { ConsensusProtocolVersion } from './tx/builder/constants.js';
|
|
13
|
+
var _ignoreVersion = /*#__PURE__*/new WeakMap();
|
|
13
14
|
var _cachedStatusPromise = /*#__PURE__*/new WeakMap();
|
|
15
|
+
var _isHyperchainPromise = /*#__PURE__*/new WeakMap();
|
|
16
|
+
/**
|
|
17
|
+
* @category chain
|
|
18
|
+
*/
|
|
14
19
|
export default class Node extends NodeApi {
|
|
15
20
|
/**
|
|
16
21
|
* @param url - Url for node API
|
|
17
22
|
* @param options - Options
|
|
18
|
-
* @param options.ignoreVersion -
|
|
23
|
+
* @param options.ignoreVersion - Print warning instead of throwing exception if node
|
|
24
|
+
* or consensus protocol version is not supported, use with caution
|
|
19
25
|
* @param options.retryCount - Amount of extra requests to do in case of failure
|
|
20
26
|
* @param options.retryOverallDelay - Time in ms to wait between all retries
|
|
21
27
|
*/
|
|
@@ -29,10 +35,13 @@ export default class Node extends NodeApi {
|
|
|
29
35
|
// eslint-disable-next-line constructor-super
|
|
30
36
|
super(url, {
|
|
31
37
|
allowInsecureConnection: true,
|
|
32
|
-
additionalPolicies: [
|
|
38
|
+
additionalPolicies: [genVersionCheckPolicy('node', getVersion, '7.1.0', '8.0.0', ignoreVersion), genRequestQueuesPolicy(), genCombineGetRequestsPolicy(), genRetryOnFailurePolicy(retryCount, retryOverallDelay), genErrorFormatterPolicy(body => [' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`].join(''))],
|
|
33
39
|
...options
|
|
34
40
|
});
|
|
41
|
+
_classPrivateFieldInitSpec(this, _ignoreVersion, void 0);
|
|
35
42
|
_classPrivateFieldInitSpec(this, _cachedStatusPromise, void 0);
|
|
43
|
+
_classPrivateFieldInitSpec(this, _isHyperchainPromise, void 0);
|
|
44
|
+
_classPrivateFieldSet(_ignoreVersion, this, ignoreVersion);
|
|
36
45
|
this.pipeline.addPolicy(parseBigIntPolicy, {
|
|
37
46
|
phase: 'Deserialize'
|
|
38
47
|
});
|
|
@@ -58,6 +67,20 @@ export default class Node extends NodeApi {
|
|
|
58
67
|
}, () => {});
|
|
59
68
|
return promise;
|
|
60
69
|
}
|
|
70
|
+
async _isHyperchain() {
|
|
71
|
+
if (_classPrivateFieldGet(_isHyperchainPromise, this) != null) return _classPrivateFieldGet(_isHyperchainPromise, this);
|
|
72
|
+
_classPrivateFieldSet(_isHyperchainPromise, this, this.getHyperchainContractPubkeys({
|
|
73
|
+
requestOptions: {
|
|
74
|
+
customHeaders: {
|
|
75
|
+
'__no-retry': 'true'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}).then(() => true, error => {
|
|
79
|
+
if (error.message !== 'v3/hyperchain/contracts error: 404 status code') throw error;
|
|
80
|
+
return false;
|
|
81
|
+
}));
|
|
82
|
+
return _classPrivateFieldGet(_isHyperchainPromise, this);
|
|
83
|
+
}
|
|
61
84
|
|
|
62
85
|
/**
|
|
63
86
|
* Returns network ID provided by node.
|
|
@@ -84,7 +107,8 @@ export default class Node extends NodeApi {
|
|
|
84
107
|
const versions = Object.values(ConsensusProtocolVersion).filter(el => typeof el === 'number').map(el => +el);
|
|
85
108
|
const geVersion = Math.min(...versions).toString();
|
|
86
109
|
const ltVersion = (Math.max(...versions) + 1).toString();
|
|
87
|
-
|
|
110
|
+
const error = new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);
|
|
111
|
+
if (_classPrivateFieldGet(_ignoreVersion, this)) console.warn(error.message);else throw error;
|
|
88
112
|
}
|
|
89
113
|
return {
|
|
90
114
|
url: this.$host,
|
package/es/Node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.js","names":["userAgentPolicyName","setClientRequestIdPolicyName","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","parseBigIntPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","UnsupportedVersionError","ConsensusProtocolVersion","_cachedStatusPromise","WeakMap","constructor","url","ignoreVersion","retryCount","retryOverallDelay","options","getVersion","opts","_getCachedStatus","nodeVersion","allowInsecureConnection","additionalPolicies","body","reason","errorCode","join","_classPrivateFieldInitSpec","pipeline","addPolicy","phase","removePolicy","name","_classPrivateFieldGet","getStatus","args","promise","then","_classPrivateFieldSet","getNetworkId","networkId","getNodeInfo","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","version","toString","versions","Object","values","el","map","geVersion","Math","min","ltVersion","max","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { OperationOptions } from '@azure/core-client';\nimport { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline';\nimport {\n genRequestQueuesPolicy,\n genCombineGetRequestsPolicy,\n genErrorFormatterPolicy,\n parseBigIntPolicy,\n genVersionCheckPolicy,\n genRetryOnFailurePolicy,\n} from './utils/autorest.js';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node/index.js';\nimport { UnsupportedVersionError } from './utils/errors.js';\nimport { ConsensusProtocolVersion } from './tx/builder/constants.js';\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends NodeApi {\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Don't ensure that the node is supported\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false,\n retryCount = 3,\n retryOverallDelay = 800,\n ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n const getVersion = async (opts: OperationOptions): Promise<string> =>\n (await this._getCachedStatus(opts)).nodeVersion;\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n ...(ignoreVersion ? [] : [genVersionCheckPolicy('node', getVersion, '7.1.0', '8.0.0')]),\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) =>\n [' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`].join(''),\n ),\n ],\n ...options,\n });\n this.pipeline.addPolicy(parseBigIntPolicy, { phase: 'Deserialize' });\n this.pipeline.removePolicy({ name: userAgentPolicyName });\n this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });\n // TODO: use instead our retry policy\n this.pipeline.removePolicy({ name: 'defaultRetryPolicy' });\n }\n\n #cachedStatusPromise?: ReturnType<NodeApi['getStatus']>;\n\n async _getCachedStatus(options?: OperationOptions): ReturnType<NodeApi['getStatus']> {\n if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise;\n return this.getStatus(options);\n }\n\n override async getStatus(\n ...args: Parameters<NodeApi['getStatus']>\n ): ReturnType<NodeApi['getStatus']> {\n const promise = super.getStatus(...args);\n promise.then(\n () => {\n this.#cachedStatusPromise = promise;\n },\n () => {},\n );\n return promise;\n }\n\n /**\n * Returns network ID provided by node.\n * This method won't do extra requests on subsequent calls.\n */\n async getNetworkId(): Promise<string> {\n return (await this._getCachedStatus()).networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce((acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc), {\n effectiveAtHeight: -1,\n version: 0,\n }).version;\n if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {\n const version = consensusProtocolVersion.toString();\n const versions = Object.values(ConsensusProtocolVersion)\n .filter((el) => typeof el === 'number')\n .map((el) => +el);\n const geVersion = Math.min(...versions).toString();\n const ltVersion = (Math.max(...versions) + 1).toString();\n throw new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);\n }\n\n return {\n url: this.$host,\n nodeNetworkId,\n version: nodeVersion,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;AAAA;;AAEA,SAASA,mBAAmB,EAAEC,4BAA4B,QAAQ,2BAA2B;AAC7F,SACEC,sBAAsB,EACtBC,2BAA2B,EAC3BC,uBAAuB,EACvBC,iBAAiB,EACjBC,qBAAqB,EACrBC,uBAAuB,QAClB,qBAAqB;AAC5B,SAASC,IAAI,IAAIC,OAAO,QAAwC,sBAAsB;AACtF,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,wBAAwB,QAAQ,2BAA2B;AAAC,IAAAC,oBAAA,oBAAAC,OAAA;AASrE,eAAe,MAAML,IAAI,SAASC,OAAO,CAAC;EACxC;AACF;AACA;AACA;AACA;AACA;AACA;EACEK,WAAWA,CACTC,GAAW,EACX;IACEC,aAAa,GAAG,KAAK;IACrBC,UAAU,GAAG,CAAC;IACdC,iBAAiB,GAAG,GAAG;IACvB,GAAGC;EAKL,CAAC,GAAG,CAAC,CAAC,EACN;IACA,MAAMC,UAAU,GAAG,MAAOC,IAAsB,IAC9C,CAAC,MAAM,IAAI,CAACC,gBAAgB,CAACD,IAAI,CAAC,EAAEE,WAAW;IACjD;IACA,KAAK,CAACR,GAAG,EAAE;MACTS,uBAAuB,EAAE,IAAI;MAC7BC,kBAAkB,EAAE,CAClB,IAAIT,aAAa,GAAG,EAAE,GAAG,CAACV,qBAAqB,CAAC,MAAM,EAAEc,UAAU,EAAE,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AoB,EAAE4C,OAAO,EAAEO,SAAS,EAAEG,SAAS,CAAC;IACxF;IAEA,OAAO;MACLjD,GAAG,EAAE,IAAI,CAACmD,KAAK;MACfrB,aAAa;MACbS,OAAO,EAAE/B,WAAW;MACpByB;IACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Node.js","names":["userAgentPolicyName","setClientRequestIdPolicyName","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","parseBigIntPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","UnsupportedVersionError","ConsensusProtocolVersion","_ignoreVersion","WeakMap","_cachedStatusPromise","_isHyperchainPromise","constructor","url","ignoreVersion","retryCount","retryOverallDelay","options","getVersion","opts","_getCachedStatus","nodeVersion","allowInsecureConnection","additionalPolicies","body","reason","errorCode","join","_classPrivateFieldInitSpec","_classPrivateFieldSet","pipeline","addPolicy","phase","removePolicy","name","_classPrivateFieldGet","getStatus","args","promise","then","_isHyperchain","getHyperchainContractPubkeys","requestOptions","customHeaders","error","message","getNetworkId","networkId","getNodeInfo","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","version","toString","versions","Object","values","el","map","geVersion","Math","min","ltVersion","max","console","warn","$host"],"sources":["../src/Node.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { OperationOptions } from '@azure/core-client';\nimport { userAgentPolicyName, setClientRequestIdPolicyName } from '@azure/core-rest-pipeline';\nimport {\n genRequestQueuesPolicy,\n genCombineGetRequestsPolicy,\n genErrorFormatterPolicy,\n parseBigIntPolicy,\n genVersionCheckPolicy,\n genRetryOnFailurePolicy,\n} from './utils/autorest.js';\nimport { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node/index.js';\nimport { UnsupportedVersionError } from './utils/errors.js';\nimport { ConsensusProtocolVersion } from './tx/builder/constants.js';\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\n/**\n * @category chain\n */\nexport default class Node extends NodeApi {\n readonly #ignoreVersion: boolean;\n\n /**\n * @param url - Url for node API\n * @param options - Options\n * @param options.ignoreVersion - Print warning instead of throwing exception if node\n * or consensus protocol version is not supported, use with caution\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false,\n retryCount = 3,\n retryOverallDelay = 800,\n ...options\n }: NodeOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n const getVersion = async (opts: OperationOptions): Promise<string> =>\n (await this._getCachedStatus(opts)).nodeVersion;\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n genVersionCheckPolicy('node', getVersion, '7.1.0', '8.0.0', ignoreVersion),\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorModel) =>\n [' ', body.reason, body.errorCode == null ? '' : ` (${body.errorCode})`].join(''),\n ),\n ],\n ...options,\n });\n this.#ignoreVersion = ignoreVersion;\n this.pipeline.addPolicy(parseBigIntPolicy, { phase: 'Deserialize' });\n this.pipeline.removePolicy({ name: userAgentPolicyName });\n this.pipeline.removePolicy({ name: setClientRequestIdPolicyName });\n // TODO: use instead our retry policy\n this.pipeline.removePolicy({ name: 'defaultRetryPolicy' });\n }\n\n #cachedStatusPromise?: ReturnType<NodeApi['getStatus']>;\n\n async _getCachedStatus(options?: OperationOptions): ReturnType<NodeApi['getStatus']> {\n if (this.#cachedStatusPromise != null) return this.#cachedStatusPromise;\n return this.getStatus(options);\n }\n\n override async getStatus(\n ...args: Parameters<NodeApi['getStatus']>\n ): ReturnType<NodeApi['getStatus']> {\n const promise = super.getStatus(...args);\n promise.then(\n () => {\n this.#cachedStatusPromise = promise;\n },\n () => {},\n );\n return promise;\n }\n\n #isHyperchainPromise?: Promise<boolean>;\n\n async _isHyperchain(): Promise<boolean> {\n if (this.#isHyperchainPromise != null) return this.#isHyperchainPromise;\n this.#isHyperchainPromise = this.getHyperchainContractPubkeys({\n requestOptions: { customHeaders: { '__no-retry': 'true' } },\n }).then(\n () => true,\n (error) => {\n if (error.message !== 'v3/hyperchain/contracts error: 404 status code') throw error;\n return false;\n },\n );\n return this.#isHyperchainPromise;\n }\n\n /**\n * Returns network ID provided by node.\n * This method won't do extra requests on subsequent calls.\n */\n async getNetworkId(): Promise<string> {\n return (await this._getCachedStatus()).networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce((acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc), {\n effectiveAtHeight: -1,\n version: 0,\n }).version;\n if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {\n const version = consensusProtocolVersion.toString();\n const versions = Object.values(ConsensusProtocolVersion)\n .filter((el) => typeof el === 'number')\n .map((el) => +el);\n const geVersion = Math.min(...versions).toString();\n const ltVersion = (Math.max(...versions) + 1).toString();\n const error = new UnsupportedVersionError(\n 'consensus protocol',\n version,\n geVersion,\n ltVersion,\n );\n if (this.#ignoreVersion) console.warn(error.message);\n else throw error;\n }\n\n return {\n url: this.$host,\n nodeNetworkId,\n version: nodeVersion,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;AAAA;;AAEA,SAASA,mBAAmB,EAAEC,4BAA4B,QAAQ,2BAA2B;AAC7F,SACEC,sBAAsB,EACtBC,2BAA2B,EAC3BC,uBAAuB,EACvBC,iBAAiB,EACjBC,qBAAqB,EACrBC,uBAAuB,QAClB,qBAAqB;AAC5B,SAASC,IAAI,IAAIC,OA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,MAAMS,SAAS,GAAG,CAACF,IAAI,CAACG,GAAG,CAAC,GAAGT,QAAQ,CAAC,GAAG,CAAC,EAAED,QAAQ,CAAC,CAAC;MACxD,MAAMf,KAAK,GAAG,IAAItC,uBAAuB,CACvC,oBAAoB,EACpBoD,OAAO,EACPO,SAAS,EACTG,SACF,CAAC;MACD,IAAIjC,qBAAA,CAAK3B,cAAc,EAAnB,IAAkB,CAAC,EAAE8D,OAAO,CAACC,IAAI,CAAC3B,KAAK,CAACC,OAAO,CAAC,CAAC,KAChD,MAAMD,KAAK;IAClB;IAEA,OAAO;MACL/B,GAAG,EAAE,IAAI,CAAC2D,KAAK;MACfvB,aAAa;MACbS,OAAO,EAAErC,WAAW;MACpB+B;IACF,CAAC;EACH;AACF","ignoreList":[]}
|
package/es/account/Base.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface AuthData {
|
|
|
14
14
|
/**
|
|
15
15
|
* Account is one of the three basic building blocks of an
|
|
16
16
|
* {@link AeSdk} and provides access to a signing key pair.
|
|
17
|
+
* @category account
|
|
17
18
|
*/
|
|
18
19
|
export default abstract class AccountBase {
|
|
19
20
|
/**
|
|
@@ -59,11 +60,22 @@ export default abstract class AccountBase {
|
|
|
59
60
|
* @param data - Data blob to sign
|
|
60
61
|
* @param options - Options
|
|
61
62
|
* @returns Signature
|
|
63
|
+
* @deprecated Use `unsafeSign` method instead
|
|
62
64
|
*/
|
|
63
65
|
abstract sign(data: string | Uint8Array, options?: {
|
|
64
66
|
aeppOrigin?: string;
|
|
65
67
|
aeppRpcClientId?: string;
|
|
66
68
|
}): Promise<Uint8Array>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign data blob
|
|
71
|
+
* @param data - Data blob to sign
|
|
72
|
+
* @param options - Options
|
|
73
|
+
* @returns Signature
|
|
74
|
+
*/
|
|
75
|
+
abstract unsafeSign(data: string | Uint8Array, options?: {
|
|
76
|
+
aeppOrigin?: string;
|
|
77
|
+
aeppRpcClientId?: string;
|
|
78
|
+
}): Promise<Uint8Array>;
|
|
67
79
|
/**
|
|
68
80
|
* Account address
|
|
69
81
|
*/
|
package/es/account/Base.js
CHANGED
package/es/account/Base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base.js","names":["AccountBase"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder.js';\nimport Node from '../Node.js';\nimport CompilerBase from '../contract/compiler/Base.js';\nimport { Int } from '../tx/builder/constants.js';\nimport { AciValue, Domain } from '../utils/typed-data.js';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign typed data\n * @param data - Encoded data to sign\n * @param aci - Type of data to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n options?: Domain & {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Signature>;\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n */\n abstract sign(\n data: string | Uint8Array,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address!: Encoded.AccountAddress;\n\n /**\n * Sign delegation, works only in Ceres\n * @param delegation - Delegation to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signDelegation(\n delegation: Encoded.Bytearray,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Signature>;\n}\n"],"mappings":"AAeA;AACA;AACA;AACA;AACA,eAAe,MAAeA,WAAW,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Base.js","names":["AccountBase"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder.js';\nimport Node from '../Node.js';\nimport CompilerBase from '../contract/compiler/Base.js';\nimport { Int } from '../tx/builder/constants.js';\nimport { AciValue, Domain } from '../utils/typed-data.js';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n * @category account\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign typed data\n * @param data - Encoded data to sign\n * @param aci - Type of data to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n options?: Domain & {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Signature>;\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n * @deprecated Use `unsafeSign` method instead\n */\n abstract sign(\n data: string | Uint8Array,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n */\n abstract unsafeSign(\n data: string | Uint8Array,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address!: Encoded.AccountAddress;\n\n /**\n * Sign delegation, works only in Ceres\n * @param delegation - Delegation to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signDelegation(\n delegation: Encoded.Bytearray,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Signature>;\n}\n"],"mappings":"AAeA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAeA,WAAW,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseFactory.js","names":["AccountBaseFactory","discover","node","index","result","account","push","initialize","getAccountByPubkey","address","then"],"sources":["../../src/account/BaseFactory.ts"],"sourcesContent":["import Node from '../Node.js';\nimport AccountBase from './Base.js';\n\n/**\n * A factory class that generates instances of AccountBase by index.\n */\nexport default abstract class AccountBaseFactory {\n /**\n * Get an instance of AccountBase for a given account index.\n * @param accountIndex - Index of account\n */\n abstract initialize(accountIndex: number): Promise<AccountBase>;\n\n /**\n * Discovers accounts in set that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountBase[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (\n await node.getAccountByPubkey(account.address).then(\n () => true,\n () => false,\n )\n );\n return result;\n }\n}\n"],"mappings":"AAGA;AACA;AACA;AACA,eAAe,MAAeA,kBAAkB,CAAC;EAC/C;AACF;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;EACE,MAAMC,QAAQA,CAACC,IAAU,EAA0B;IACjD,IAAIC,KAAK,GAAG,CAAC;IACb,MAAMC,MAAM,GAAG,EAAE;IACjB,IAAIC,OAAO;IACX,GAAG;MACD,IAAIA,OAAO,IAAI,IAAI,EAAED,MAAM,CAACE,IAAI,CAACD,OAAO,CAAC;MACzCA,OAAO,GAAG,MAAM,IAAI,CAACE,UAAU,CAACJ,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QACC,MAAMD,IAAI,CAACM,kBAAkB,CAACH,OAAO,CAACI,OAAO,CAAC,CAACC,IAAI,CACjD,MAAM,IAAI,EACV,MAAM,KACR,CAAC;IAEH,OAAON,MAAM;EACf;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"BaseFactory.js","names":["AccountBaseFactory","discover","node","index","result","account","push","initialize","getAccountByPubkey","address","then"],"sources":["../../src/account/BaseFactory.ts"],"sourcesContent":["import Node from '../Node.js';\nimport AccountBase from './Base.js';\n\n/**\n * A factory class that generates instances of AccountBase by index.\n * @category account\n */\nexport default abstract class AccountBaseFactory {\n /**\n * Get an instance of AccountBase for a given account index.\n * @param accountIndex - Index of account\n */\n abstract initialize(accountIndex: number): Promise<AccountBase>;\n\n /**\n * Discovers accounts in set that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountBase[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (\n await node.getAccountByPubkey(account.address).then(\n () => true,\n () => false,\n )\n );\n return result;\n }\n}\n"],"mappings":"AAGA;AACA;AACA;AACA;AACA,eAAe,MAAeA,kBAAkB,CAAC;EAC/C;AACF;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;EACE,MAAMC,QAAQA,CAACC,IAAU,EAA0B;IACjD,IAAIC,KAAK,GAAG,CAAC;IACb,MAAMC,MAAM,GAAG,EAAE;IACjB,IAAIC,OAAO;IACX,GAAG;MACD,IAAIA,OAAO,IAAI,IAAI,EAAED,MAAM,CAACE,IAAI,CAACD,OAAO,CAAC;MACzCA,OAAO,GAAG,MAAM,IAAI,CAACE,UAAU,CAACJ,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QACC,MAAMD,IAAI,CAACM,kBAAkB,CAACH,OAAO,CAACI,OAAO,CAAC,CAACC,IAAI,CACjD,MAAM,IAAI,EACV,MAAM,KACR,CAAC;IAEH,OAAON,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@ import AccountBase from './Base.js';
|
|
|
2
2
|
import { Encoded } from '../utils/encoder.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generalized account class
|
|
5
|
+
* @category account generalized
|
|
5
6
|
*/
|
|
6
7
|
export default class AccountGeneralized extends AccountBase {
|
|
7
8
|
#private;
|
|
@@ -10,7 +11,11 @@ export default class AccountGeneralized extends AccountBase {
|
|
|
10
11
|
* @param address - Address of generalized account
|
|
11
12
|
*/
|
|
12
13
|
constructor(address: Encoded.AccountAddress);
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use `unsafeSign` method instead
|
|
16
|
+
*/
|
|
13
17
|
sign(): Promise<Uint8Array>;
|
|
18
|
+
unsafeSign(): Promise<Uint8Array>;
|
|
14
19
|
signMessage(): Promise<Uint8Array>;
|
|
15
20
|
signTypedData(): Promise<Encoded.Signature>;
|
|
16
21
|
signDelegation(): Promise<Encoded.Signature>;
|
|
@@ -13,6 +13,7 @@ import { Tag } from '../tx/builder/constants.js';
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Generalized account class
|
|
16
|
+
* @category account generalized
|
|
16
17
|
*/
|
|
17
18
|
var _authFun = /*#__PURE__*/new WeakMap();
|
|
18
19
|
export default class AccountGeneralized extends AccountBase {
|
|
@@ -26,8 +27,16 @@ export default class AccountGeneralized extends AccountBase {
|
|
|
26
27
|
this.address = address;
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `unsafeSign` method instead
|
|
32
|
+
*/
|
|
29
33
|
// eslint-disable-next-line class-methods-use-this
|
|
30
34
|
async sign() {
|
|
35
|
+
return this.unsafeSign();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39
|
+
async unsafeSign() {
|
|
31
40
|
throw new NotImplementedError("Can't sign using generalized account");
|
|
32
41
|
}
|
|
33
42
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Generalized.js","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","sign","signMessage","signTypedData","signDelegation","signTransaction","tx","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base.js';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors.js';\nimport { decode, Encoded } from '../utils/encoder.js';\nimport { getAccount } from '../chain.js';\nimport Contract from '../contract/Contract.js';\nimport { buildTxAsync, buildTx } from '../tx/builder/index.js';\nimport { Tag } from '../tx/builder/constants.js';\n\n/**\n * Generalized account class\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegation(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const { callData, sourceCode, args, fee, gasLimit, gasPrice } =\n typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData =\n callData ??\n (await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })());\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;;AAAA,OAAOA,WAAW,MAAM,WAAW;AACnC,SACEC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB,QACd,oBAAoB;AAC3B,SAASC,MAAM,QAAiB,qBAAqB;AACrD,SAASC,UAAU,QAAQ,aAAa;AACxC,OAAOC,QAAQ,MAAM,yBAAyB;AAC9C,SAASC,YAAY,EAAEC,OAAO,QAAQ,wBAAwB;AAC9D,SAASC,GAAG,QAAQ,4BAA4B;;AAEhD;AACA;AACA;
|
|
1
|
+
{"version":3,"file":"Generalized.js","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","sign","unsafeSign","signMessage","signTypedData","signDelegation","signTransaction","tx","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base.js';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors.js';\nimport { decode, Encoded } from '../utils/encoder.js';\nimport { getAccount } from '../chain.js';\nimport Contract from '../contract/Contract.js';\nimport { buildTxAsync, buildTx } from '../tx/builder/index.js';\nimport { Tag } from '../tx/builder/constants.js';\n\n/**\n * Generalized account class\n * @category account generalized\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n /**\n * @deprecated Use `unsafeSign` method instead\n */\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n return this.unsafeSign();\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async unsafeSign(): Promise<Uint8Array> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError(\"Can't sign using generalized account\");\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegation(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const { callData, sourceCode, args, fee, gasLimit, gasPrice } =\n typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData =\n callData ??\n (await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })());\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;;AAAA,OAAOA,WAAW,MAAM,WAAW;AACnC,SACEC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB,QACd,oBAAoB;AAC3B,SAASC,MAAM,QAAiB,qBAAqB;AACrD,SAASC,UAAU,QAAQ,aAAa;AACxC,OAAOC,QAAQ,MAAM,yBAAyB;AAC9C,SAASC,YAAY,EAAEC,OAAO,QAAQ,wBAAwB;AAC9D,SAASC,GAAG,QAAQ,4BAA4B;;AAEhD;AACA;AACA;AACA;AAHA,IAAAC,QAAA,oBAAAC,OAAA;AAIA,eAAe,MAAMC,kBAAkB,SAASb,WAAW,CAAC;EAK1D;AACF;AACA;EACEc,WAAWA,CAACC,OAA+B,EAAE;IAC3C,KAAK,CAAC,CAAC;IANTC,0BAAA,OAAAL,QAAQ;IAONN,MAAM,CAACU,OAAO,CAAC;IACf,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;;EAEA;AACF;AACA;EACE;EACA,MAAeE,IAAIA,CAAA,EAAwB;IACzC,OAAO,IAAI,CAACC,UAAU,CAAC,CAAC;EAC1B;;EAEA;EACA,MAAeA,UAAUA,CAAA,EAAwB;IAC/C,MAAM,IAAId,mBAAmB,CAAC,sCAAsC,CAAC;EACvE;;EAEA;EACA,MAAee,WAAWA,CAAA,EAAwB;IAChD,MAAM,IAAIf,mBAAmB,CAAC,sCAAsC,CAAC;EACvE;;EAEA;EACA,MAAegB,aAAaA,CAAA,EAA+B;IACzD,MAAM,IAAIhB,mBAAmB,CAAC,sCAAsC,CAAC;EACvE;;EAEA;EACA,MAAeiB,cAAcA,CAAA,EAA+B;IAC1D,MAAM,IAAIjB,mBAAmB,CAAC,8CAA8C,CAAC;EAC/E;EAEA,MAAekB,eAAeA,CAC5BC,EAAuB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W,CAAC,CAAC;MAC9E,OAAOW,QAAQ,CAACE,SAAS,CAACC,MAAM,CAACH,QAAQ,CAACI,KAAK,EAAET,qBAAA,CAAKvB,QAAQ,EAAb,IAAY,CAAC,EAAEkB,IAAI,CAAC;IACvE,CAAC,EAAE,CAAE;IAEP,MAAMe,QAAQ,GAAG,MAAMpC,YAAY,CAAC;MAClCqC,GAAG,EAAEnC,GAAG,CAACoC,QAAQ;MACjBvB,EAAE,EAAE;QAAEsB,GAAG,EAAEnC,GAAG,CAACqC,QAAQ;QAAEC,SAAS,EAAE3C,MAAM,CAACkB,EAAE,CAAC;QAAE0B,UAAU,EAAE;MAAG,CAAC;MAChEC,IAAI,EAAE,IAAI,CAACnC,OAAO;MAClBS,QAAQ,EAAES,YAAY;MACtBH,GAAG;MACHC,QAAQ;MACRC,QAAQ;MACRN;IACF,CAAC,CAAC;IACF,OAAOjB,OAAO,CAAC;MAAEoC,GAAG,EAAEnC,GAAG,CAACqC,QAAQ;MAAEC,SAAS,EAAE3C,MAAM,CAACuC,QAAQ,CAAC;MAAEK,UAAU,EAAE;IAAG,CAAC,CAAC;EACpF;AACF","ignoreList":[]}
|
package/es/account/Ledger.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const GET_APP_CONFIGURATION = 6;
|
|
|
8
8
|
export declare const SIGN_PERSONAL_MESSAGE = 8;
|
|
9
9
|
/**
|
|
10
10
|
* Ledger wallet account class
|
|
11
|
+
* @category account
|
|
11
12
|
*/
|
|
12
13
|
export default class AccountLedger extends AccountBase {
|
|
13
14
|
readonly transport: Transport;
|
|
@@ -19,7 +20,11 @@ export default class AccountLedger extends AccountBase {
|
|
|
19
20
|
* @param address - Address of account
|
|
20
21
|
*/
|
|
21
22
|
constructor(transport: Transport, index: number, address: Encoded.AccountAddress);
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use `unsafeSign` method instead
|
|
25
|
+
*/
|
|
22
26
|
sign(): Promise<Uint8Array>;
|
|
27
|
+
unsafeSign(): Promise<Uint8Array>;
|
|
23
28
|
signTypedData(): Promise<Encoded.Signature>;
|
|
24
29
|
signDelegation(): Promise<Encoded.Signature>;
|
|
25
30
|
signTransaction(tx: Encoded.Transaction, { innerTx, networkId }?: {
|
package/es/account/Ledger.js
CHANGED
|
@@ -12,6 +12,7 @@ export const SIGN_PERSONAL_MESSAGE = 0x08;
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Ledger wallet account class
|
|
15
|
+
* @category account
|
|
15
16
|
*/
|
|
16
17
|
export default class AccountLedger extends AccountBase {
|
|
17
18
|
/**
|
|
@@ -27,8 +28,16 @@ export default class AccountLedger extends AccountBase {
|
|
|
27
28
|
transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], 'w0w');
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `unsafeSign` method instead
|
|
33
|
+
*/
|
|
30
34
|
// eslint-disable-next-line class-methods-use-this
|
|
31
35
|
async sign() {
|
|
36
|
+
return this.unsafeSign();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line class-methods-use-this
|
|
40
|
+
async unsafeSign() {
|
|
32
41
|
throw new NotImplementedError('RAW signing using Ledger HW');
|
|
33
42
|
}
|
|
34
43
|
|
package/es/account/Ledger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ledger.js","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","decorateAppAPIMethods","sign","signTypedData","signDelegation","signTransaction","tx","innerTx","networkId","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","length","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base.js';\nimport { ArgumentError, NotImplementedError } from '../utils/errors.js';\nimport { decode, Encoded } from '../utils/encoder.js';\nimport { buildTx } from '../tx/builder/index.js';\nimport { Tag } from '../tx/builder/constants.js';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n */\nexport default class AccountLedger extends AccountBase {\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(\n readonly transport: Transport,\n readonly index: number,\n override readonly address: Encoded.AccountAddress,\n ) {\n super();\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], 'w0w');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Typed data signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegation(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(buffer, bufferOffset, 0, networkIdBuffer.length);\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(CLA, SIGN_TRANSACTION, i === 0 ? 0x00 : 0x80, 0x00, data);\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize =\n offset + maxChunkSize > message.length ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(CLA, SIGN_PERSONAL_MESSAGE, i === 0 ? 0x00 : 0x80, 0x00, data);\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\n"],"mappings":";AACA,OAAOA,WAAW,MAAM,WAAW;AACnC,SAASC,aAAa,EAAEC,mBAAmB,QAAQ,oBAAoB;AACvE,SAASC,MAAM,QAAiB,qBAAqB;AACrD,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,GAAG,QAAQ,4BAA4B;AAEhD,OAAO,MAAMC,GAAG,GAAG,IAAI;AACvB,OAAO,MAAMC,WAAW,GAAG,IAAI;AAC/B,OAAO,MAAMC,gBAAgB,GAAG,IAAI;AACpC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;AACzC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;;AAEzC;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAASX,WAAW,CAAC;EACrD;AACF;AACA;AACA;AACA;EACEY,WAAWA,CACAC,SAAoB,EACpBC,KAAa,EACJC,OAA+B,EACjD;IACA,KAAK,CAAC,CAAC;IAAC,KAJCF,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,KAAa,GAAbA,KAAa;IAAA,KACJC,OAA+B,GAA/BA,OAA+B;IAGjDF,SAAS,CAACG,qBAAqB,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAAE,KAAK,CAAC;EAClF;;EAEA;EACA,MAAeC,IAAIA,CAAA,EAAwB;IACzC,MAAM,
|
|
1
|
+
{"version":3,"file":"Ledger.js","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","decorateAppAPIMethods","sign","unsafeSign","signTypedData","signDelegation","signTransaction","tx","innerTx","networkId","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","length","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base.js';\nimport { ArgumentError, NotImplementedError } from '../utils/errors.js';\nimport { decode, Encoded } from '../utils/encoder.js';\nimport { buildTx } from '../tx/builder/index.js';\nimport { Tag } from '../tx/builder/constants.js';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n * @category account\n */\nexport default class AccountLedger extends AccountBase {\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(\n readonly transport: Transport,\n readonly index: number,\n override readonly address: Encoded.AccountAddress,\n ) {\n super();\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], 'w0w');\n }\n\n /**\n * @deprecated Use `unsafeSign` method instead\n */\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n return this.unsafeSign();\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async unsafeSign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Typed data signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegation(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(buffer, bufferOffset, 0, networkIdBuffer.length);\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(CLA, SIGN_TRANSACTION, i === 0 ? 0x00 : 0x80, 0x00, data);\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize =\n offset + maxChunkSize > message.length ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(CLA, SIGN_PERSONAL_MESSAGE, i === 0 ? 0x00 : 0x80, 0x00, data);\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\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
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* A factory class that generates instances of AccountLedger based on provided transport.
|
|
10
|
+
* @category account
|
|
10
11
|
*/
|
|
11
12
|
export default class AccountLedgerFactory extends AccountBaseFactory {
|
|
12
13
|
#private;
|
|
@@ -15,6 +16,7 @@ export default class AccountLedgerFactory extends AccountBaseFactory {
|
|
|
15
16
|
* @param transport - Connection to Ledger to use
|
|
16
17
|
*/
|
|
17
18
|
constructor(transport: Transport);
|
|
19
|
+
_enableExperimentalLedgerAppSupport: boolean;
|
|
18
20
|
/**
|
|
19
21
|
* It throws an exception if Aeternity app on Ledger has an incompatible version, not opened or
|
|
20
22
|
* not installed.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Buffer as _Buffer } from "buffer";
|
|
2
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
3
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
3
4
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
4
5
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
@@ -13,6 +14,7 @@ var _ensureReadyPromise = /*#__PURE__*/new WeakMap();
|
|
|
13
14
|
var _AccountLedgerFactory_brand = /*#__PURE__*/new WeakSet();
|
|
14
15
|
/**
|
|
15
16
|
* A factory class that generates instances of AccountLedger based on provided transport.
|
|
17
|
+
* @category account
|
|
16
18
|
*/
|
|
17
19
|
export default class AccountLedgerFactory extends AccountBaseFactory {
|
|
18
20
|
/**
|
|
@@ -22,6 +24,8 @@ export default class AccountLedgerFactory extends AccountBaseFactory {
|
|
|
22
24
|
super();
|
|
23
25
|
_classPrivateMethodInitSpec(this, _AccountLedgerFactory_brand);
|
|
24
26
|
_classPrivateFieldInitSpec(this, _ensureReadyPromise, void 0);
|
|
27
|
+
// TODO: remove after release Ledger app v1.0.0
|
|
28
|
+
_defineProperty(this, "_enableExperimentalLedgerAppSupport", false);
|
|
25
29
|
this.transport = transport;
|
|
26
30
|
transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], 'w0w');
|
|
27
31
|
}
|
|
@@ -33,8 +37,9 @@ export default class AccountLedgerFactory extends AccountBaseFactory {
|
|
|
33
37
|
const {
|
|
34
38
|
version
|
|
35
39
|
} = await _assertClassBrand(_AccountLedgerFactory_brand, this, _getAppConfiguration).call(this);
|
|
36
|
-
const
|
|
37
|
-
|
|
40
|
+
const oldApp = [version, '0.4.4', '0.5.0'];
|
|
41
|
+
const newApp = [version, '1.0.0', '2.0.0'];
|
|
42
|
+
if (!semverSatisfies(...oldApp) && (!this._enableExperimentalLedgerAppSupport || !semverSatisfies(...newApp))) throw new UnsupportedVersionError('Aeternity app on Ledger', ...oldApp);
|
|
38
43
|
_classPrivateFieldSet(_ensureReadyPromise, this, Promise.resolve());
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
@@ -72,9 +77,10 @@ async function _ensureReady() {
|
|
|
72
77
|
return _classPrivateFieldGet(_ensureReadyPromise, this);
|
|
73
78
|
}
|
|
74
79
|
async function _getAppConfiguration() {
|
|
75
|
-
|
|
80
|
+
let response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);
|
|
81
|
+
if (response.length === 6) response = response.subarray(1);
|
|
76
82
|
return {
|
|
77
|
-
version: [response[
|
|
83
|
+
version: [response[0], response[1], response[2]].join('.')
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
86
|
//# sourceMappingURL=LedgerFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LedgerFactory.js","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountBaseFactory","_ensureReadyPromise","WeakMap","_AccountLedgerFactory_brand","WeakSet","AccountLedgerFactory","constructor","transport","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","decorateAppAPIMethods","ensureReady","version","_assertClassBrand","_getAppConfiguration","call","
|
|
1
|
+
{"version":3,"file":"LedgerFactory.js","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountBaseFactory","_ensureReadyPromise","WeakMap","_AccountLedgerFactory_brand","WeakSet","AccountLedgerFactory","constructor","transport","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","_defineProperty","decorateAppAPIMethods","ensureReady","version","_assertClassBrand","_getAppConfiguration","call","oldApp","newApp","_enableExperimentalLedgerAppSupport","_classPrivateFieldSet","Promise","resolve","getAppConfiguration","getAddress","accountIndex","verify","_ensureReady","buffer","_Buffer","alloc","writeUInt32BE","response","send","addressLength","subarray","toString","initialize","_classPrivateFieldGet2","_classPrivateFieldGet","length","join"],"sources":["../../src/account/LedgerFactory.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountLedger, { CLA, GET_ADDRESS, GET_APP_CONFIGURATION } from './Ledger.js';\nimport { UnsupportedVersionError } from '../utils/errors.js';\nimport { Encoded } from '../utils/encoder.js';\nimport semverSatisfies from '../utils/semver-satisfies.js';\nimport AccountBaseFactory from './BaseFactory.js';\n\ninterface AppConfiguration {\n version: string;\n}\n\n/**\n * A factory class that generates instances of AccountLedger based on provided transport.\n * @category account\n */\nexport default class AccountLedgerFactory extends AccountBaseFactory {\n /**\n * @param transport - Connection to Ledger to use\n */\n constructor(readonly transport: Transport) {\n super();\n transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], 'w0w');\n }\n\n #ensureReadyPromise?: Promise<void>;\n\n // TODO: remove after release Ledger app v1.0.0\n _enableExperimentalLedgerAppSupport = false;\n\n /**\n * It throws an exception if Aeternity app on Ledger has an incompatible version, not opened or\n * not installed.\n */\n async ensureReady(): Promise<void> {\n const { version } = await this.#getAppConfiguration();\n const oldApp = [version, '0.4.4', '0.5.0'] as const;\n const newApp = [version, '1.0.0', '2.0.0'] as const;\n if (\n !semverSatisfies(...oldApp) &&\n (!this._enableExperimentalLedgerAppSupport || !semverSatisfies(...newApp))\n )\n throw new UnsupportedVersionError('Aeternity app on Ledger', ...oldApp);\n this.#ensureReadyPromise = Promise.resolve();\n }\n\n async #ensureReady(): Promise<void> {\n this.#ensureReadyPromise ??= this.ensureReady();\n return this.#ensureReadyPromise;\n }\n\n async #getAppConfiguration(): Promise<AppConfiguration> {\n let response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);\n if (response.length === 6) response = response.subarray(1);\n return {\n version: [response[0], response[1], response[2]].join('.'),\n };\n }\n\n /**\n * @returns the version of Aeternity app installed on Ledger wallet\n */\n async getAppConfiguration(): Promise<AppConfiguration> {\n return this.#getAppConfiguration();\n }\n\n /**\n * Get `ak_`-prefixed address for a given account index.\n * @param accountIndex - Index of account\n * @param verify - Ask user to confirm address by showing it on the device screen\n */\n async getAddress(accountIndex: number, verify = false): Promise<Encoded.AccountAddress> {\n await this.#ensureReady();\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(accountIndex, 0);\n const response = await this.transport.send(\n CLA,\n GET_ADDRESS,\n verify ? 0x01 : 0x00,\n 0x00,\n buffer,\n );\n const addressLength = response[0];\n return response.subarray(1, 1 + addressLength).toString('ascii') as Encoded.AccountAddress;\n }\n\n /**\n * Get an instance of AccountLedger for a given account index.\n * @param accountIndex - Index of account\n */\n async initialize(accountIndex: number): Promise<AccountLedger> {\n return new AccountLedger(this.transport, accountIndex, await this.getAddress(accountIndex));\n }\n}\n"],"mappings":";;;;;;;;AACA,OAAOA,aAAa,IAAIC,GAAG,EAAEC,WAAW,EAAEC,qBAAqB,QAAQ,aAAa;AACpF,SAASC,uBAAuB,QAAQ,oBAAoB;AAE5D,OAAOC,eAAe,MAAM,8BAA8B;AAC1D,OAAOC,kBAAkB,MAAM,kBAAkB;AAAC,IAAAC,mBAAA,oBAAAC,OAAA;AAAA,IAAAC,2BAAA,oBAAAC,OAA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AAC,EAAER,QAAQ,GAAGA,QAAQ,CAACG,QAAQ,CAAC,CAAC,CAAC;EAC1D,OAAO;IACLtB,OAAO,EAAE,CAACmB,QAAQ,CAAC,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,CAAC,CAAC,CAACS,IAAI,CAAC,GAAG;EAC3D,CAAC;AACH","ignoreList":[]}
|
package/es/account/Memory.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AciValue } from '../utils/typed-data.js';
|
|
|
4
4
|
export declare function getBufferToSign(transaction: Encoded.Transaction, networkId: string, innerTx: boolean): Uint8Array;
|
|
5
5
|
/**
|
|
6
6
|
* In-memory account class
|
|
7
|
+
* @category account
|
|
7
8
|
*/
|
|
8
9
|
export default class AccountMemory extends AccountBase {
|
|
9
10
|
#private;
|
|
@@ -17,7 +18,11 @@ export default class AccountMemory extends AccountBase {
|
|
|
17
18
|
* Generates a new AccountMemory using a random secret key
|
|
18
19
|
*/
|
|
19
20
|
static generate(): AccountMemory;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `unsafeSign` method instead
|
|
23
|
+
*/
|
|
20
24
|
sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;
|
|
25
|
+
unsafeSign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;
|
|
21
26
|
signTransaction(transaction: Encoded.Transaction, { innerTx, networkId, ...options }?: {
|
|
22
27
|
innerTx?: boolean;
|
|
23
28
|
networkId?: string;
|
package/es/account/Memory.js
CHANGED
|
@@ -6,7 +6,7 @@ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a),
|
|
|
6
6
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
7
7
|
import nacl from 'tweetnacl';
|
|
8
8
|
import AccountBase from './Base.js';
|
|
9
|
-
import { hash,
|
|
9
|
+
import { hash, hashMessage, messagePrefixLength } from '../utils/crypto.js';
|
|
10
10
|
import { ArgumentError } from '../utils/errors.js';
|
|
11
11
|
import { decode, encode, Encoding } from '../utils/encoder.js';
|
|
12
12
|
import { concatBuffers } from '../utils/other.js';
|
|
@@ -22,6 +22,7 @@ export function getBufferToSign(transaction, networkId, innerTx) {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* In-memory account class
|
|
25
|
+
* @category account
|
|
25
26
|
*/
|
|
26
27
|
var _secretKeyDecoded = /*#__PURE__*/new WeakMap();
|
|
27
28
|
export default class AccountMemory extends AccountBase {
|
|
@@ -45,8 +46,16 @@ export default class AccountMemory extends AccountBase {
|
|
|
45
46
|
return new AccountMemory(secretKey);
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `unsafeSign` method instead
|
|
51
|
+
*/
|
|
48
52
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
53
|
async sign(data, options) {
|
|
54
|
+
return this.unsafeSign(data, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
58
|
+
async unsafeSign(data, options) {
|
|
50
59
|
return nacl.sign.detached(_Buffer.from(data), _classPrivateFieldGet(_secretKeyDecoded, this));
|
|
51
60
|
}
|
|
52
61
|
async signTransaction(transaction, {
|
|
@@ -59,7 +68,7 @@ export default class AccountMemory extends AccountBase {
|
|
|
59
68
|
}
|
|
60
69
|
const rlpBinaryTx = decode(transaction);
|
|
61
70
|
const txWithNetworkId = getBufferToSign(transaction, networkId, innerTx === true);
|
|
62
|
-
const signatures = [await this.
|
|
71
|
+
const signatures = [await this.unsafeSign(txWithNetworkId, options)];
|
|
63
72
|
return buildTx({
|
|
64
73
|
tag: Tag.SignedTx,
|
|
65
74
|
encodedTx: rlpBinaryTx,
|
|
@@ -67,7 +76,7 @@ export default class AccountMemory extends AccountBase {
|
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
78
|
async signMessage(message, options) {
|
|
70
|
-
return this.
|
|
79
|
+
return this.unsafeSign(hashMessage(message), options);
|
|
71
80
|
}
|
|
72
81
|
async signTypedData(data, aci, {
|
|
73
82
|
name,
|
|
@@ -82,7 +91,7 @@ export default class AccountMemory extends AccountBase {
|
|
|
82
91
|
networkId,
|
|
83
92
|
contractAddress
|
|
84
93
|
});
|
|
85
|
-
const signature = await this.
|
|
94
|
+
const signature = await this.unsafeSign(dHash, options);
|
|
86
95
|
return encode(signature, Encoding.Signature);
|
|
87
96
|
}
|
|
88
97
|
async signDelegation(delegation, {
|
|
@@ -90,7 +99,7 @@ export default class AccountMemory extends AccountBase {
|
|
|
90
99
|
} = {}) {
|
|
91
100
|
if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
|
|
92
101
|
const payload = concatBuffers([messagePrefixLength, new Uint8Array([1]), _Buffer.from(networkId), decode(delegation)]);
|
|
93
|
-
const signature = await this.
|
|
102
|
+
const signature = await this.unsafeSign(payload);
|
|
94
103
|
return encode(signature, Encoding.Signature);
|
|
95
104
|
}
|
|
96
105
|
}
|