@aeternity/aepp-sdk 14.1.0 → 15.0.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.
Files changed (91) hide show
  1. package/dist/aepp-sdk.browser-script.cjs +1 -1
  2. package/dist/aepp-sdk.browser-script.cjs.map +1 -1
  3. package/dist/aepp-sdk.browser.cjs +1 -1
  4. package/dist/aepp-sdk.browser.cjs.map +1 -1
  5. package/dist/aepp-sdk.cjs +10776 -6350
  6. package/dist/aepp-sdk.cjs.map +1 -1
  7. package/es/account/Base.d.ts +6 -1
  8. package/es/account/Base.js.map +1 -1
  9. package/es/account/Generalized.d.ts +1 -1
  10. package/es/account/Generalized.js +7 -1
  11. package/es/account/Generalized.js.map +1 -1
  12. package/es/aens.d.ts +10 -2
  13. package/es/aens.js +10 -2
  14. package/es/aens.js.map +1 -1
  15. package/es/apis/middleware/models/index.js.map +1 -1
  16. package/es/apis/node/models/index.d.ts +405 -79
  17. package/es/apis/node/models/index.js.map +1 -1
  18. package/es/apis/node/models/mappers.d.ts +54 -4
  19. package/es/apis/node/models/mappers.js +1910 -500
  20. package/es/apis/node/models/mappers.js.map +1 -1
  21. package/es/apis/node/node.d.ts +28 -6
  22. package/es/apis/node/node.js +276 -5
  23. package/es/apis/node/node.js.map +1 -1
  24. package/es/channel/Contract.d.ts +5 -0
  25. package/es/channel/Contract.js +8 -2
  26. package/es/channel/Contract.js.map +1 -1
  27. package/es/channel/handlers.js +3 -3
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/contract/compiler/Cli.js +6 -2
  30. package/es/contract/compiler/Cli.js.map +1 -1
  31. package/es/contract/ga.d.ts +5 -2
  32. package/es/contract/ga.js +53 -21
  33. package/es/contract/ga.js.map +1 -1
  34. package/es/index-browser.d.ts +3 -1
  35. package/es/index-browser.js +2 -1
  36. package/es/index-browser.js.map +1 -1
  37. package/es/tx/builder/constants.d.ts +12 -2
  38. package/es/tx/builder/constants.js +11 -1
  39. package/es/tx/builder/constants.js.map +1 -1
  40. package/es/tx/builder/entry/index.js +6 -0
  41. package/es/tx/builder/entry/index.js.map +1 -1
  42. package/es/tx/builder/entry/schema.d.ts +10 -10
  43. package/es/tx/builder/field-types/ct-version.d.ts +14 -0
  44. package/es/tx/builder/field-types/ct-version.js +14 -0
  45. package/es/tx/builder/field-types/ct-version.js.map +1 -1
  46. package/es/tx/builder/field-types/fee.d.ts +9 -7
  47. package/es/tx/builder/field-types/fee.js +75 -66
  48. package/es/tx/builder/field-types/fee.js.map +1 -1
  49. package/es/tx/builder/field-types/gas-limit.d.ts +5 -3
  50. package/es/tx/builder/field-types/gas-limit.js +25 -14
  51. package/es/tx/builder/field-types/gas-limit.js.map +1 -1
  52. package/es/tx/builder/field-types/gas-price.d.ts +6 -4
  53. package/es/tx/builder/field-types/gas-price.js +87 -21
  54. package/es/tx/builder/field-types/gas-price.js.map +1 -1
  55. package/es/tx/builder/field-types/interface.d.ts +20 -0
  56. package/es/tx/builder/field-types/interface.js +17 -1
  57. package/es/tx/builder/field-types/interface.js.map +1 -1
  58. package/es/tx/builder/field-types/name-fee.d.ts +3 -2
  59. package/es/tx/builder/field-types/name-fee.js +6 -0
  60. package/es/tx/builder/field-types/name-fee.js.map +1 -1
  61. package/es/tx/builder/field-types/pointers.d.ts +2 -1
  62. package/es/tx/builder/field-types/pointers.js +6 -2
  63. package/es/tx/builder/field-types/pointers.js.map +1 -1
  64. package/es/tx/builder/field-types/transaction.d.ts +4 -1
  65. package/es/tx/builder/field-types/transaction.js +18 -3
  66. package/es/tx/builder/field-types/transaction.js.map +1 -1
  67. package/es/tx/builder/field-types/ttl.d.ts +1 -2
  68. package/es/tx/builder/field-types/ttl.js +7 -4
  69. package/es/tx/builder/field-types/ttl.js.map +1 -1
  70. package/es/tx/builder/field-types/with-formatting.d.ts +1 -1
  71. package/es/tx/builder/field-types/with-formatting.js +1 -1
  72. package/es/tx/builder/field-types/with-formatting.js.map +1 -1
  73. package/es/tx/builder/index.d.ts +13 -0
  74. package/es/tx/builder/index.js +92 -5
  75. package/es/tx/builder/index.js.map +1 -1
  76. package/es/tx/builder/protocol-parameters.d.ts +123 -0
  77. package/es/tx/builder/protocol-parameters.js +519 -0
  78. package/es/tx/builder/protocol-parameters.js.map +1 -0
  79. package/es/tx/builder/schema.d.ts +179 -201
  80. package/es/tx/builder/schema.js +5 -1
  81. package/es/tx/builder/schema.js.map +1 -1
  82. package/es/tx/execution-cost.js +5 -5
  83. package/es/tx/execution-cost.js.map +1 -1
  84. package/es/tx/transaction-signer.js +2 -2
  85. package/es/tx/transaction-signer.js.map +1 -1
  86. package/es/tx/validator.js +4 -4
  87. package/es/tx/validator.js.map +1 -1
  88. package/es/utils/wrap-proxy.d.ts +10 -0
  89. package/es/utils/wrap-proxy.js +18 -0
  90. package/es/utils/wrap-proxy.js.map +1 -1
  91. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- export default function withFormatting<Input, Output, Binary, Params, Options>(format: (v: Input | undefined) => Input, field: {
1
+ export default function withFormatting<Input, Output, Binary, Params, Options>(format: (v: Input | undefined, params: Params) => Input, field: {
2
2
  serialize: (value: Input, params: Params, options: Options) => Binary;
3
3
  deserialize: (value: Binary) => Output;
4
4
  }): {
@@ -2,7 +2,7 @@ export default function withFormatting(format, field) {
2
2
  return {
3
3
  ...field,
4
4
  serialize(value, params, options) {
5
- return field.serialize(format(value), params, options);
5
+ return field.serialize(format(value, params), params, options);
6
6
  }
7
7
  };
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"with-formatting.js","names":["withFormatting","format","field","serialize","value","params","options"],"sources":["../../../../src/tx/builder/field-types/with-formatting.ts"],"sourcesContent":["export default function withFormatting<Input, Output, Binary, Params, Options>(\n format: (v: Input | undefined) => Input,\n field: {\n serialize: (value: Input, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n} {\n return {\n ...field,\n\n serialize(value, params, options) {\n return field.serialize(format(value), params, options);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,cAAcA,CACpCC,MAAuC,EACvCC,KAGC,EAID;EACA,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAE;MAChC,OAAOJ,KAAK,CAACC,SAAS,CAACF,MAAM,CAACG,KAAK,CAAC,EAAEC,MAAM,EAAEC,OAAO,CAAC;IACxD;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"with-formatting.js","names":["withFormatting","format","field","serialize","value","params","options"],"sources":["../../../../src/tx/builder/field-types/with-formatting.ts"],"sourcesContent":["export default function withFormatting<Input, Output, Binary, Params, Options>(\n format: (v: Input | undefined, params: Params) => Input,\n field: {\n serialize: (value: Input, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n },\n): {\n serialize: (value: Input | undefined, params: Params, options: Options) => Binary;\n deserialize: (value: Binary) => Output;\n} {\n return {\n ...field,\n\n serialize(value, params, options) {\n return field.serialize(format(value, params), params, options);\n },\n };\n}\n"],"mappings":"AAAA,eAAe,SAASA,cAAcA,CACpCC,MAAuD,EACvDC,KAGC,EAID;EACA,OAAO;IACL,GAAGA,KAAK;IAERC,SAASA,CAACC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAE;MAChC,OAAOJ,KAAK,CAACC,SAAS,CAACF,MAAM,CAACG,KAAK,EAAEC,MAAM,CAAC,EAAEA,MAAM,EAAEC,OAAO,CAAC;IAChE;EACF,CAAC;AACH","ignoreList":[]}
@@ -13,6 +13,19 @@ type TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees | En
13
13
  * @param params - Transaction params
14
14
  */
15
15
  export declare function buildTx(params: TxParams): Encoded.Transaction;
16
+ /**
17
+ * Serializes a transaction that already exists — the result of an `unpackTx` — back to its
18
+ * `tx_`-encoded form.
19
+ *
20
+ * Use it instead of `buildTx` for a round trip. The values of such a transaction are fixed, and
21
+ * belong to the protocol parameters of the node it was built for: a node running a lower minimum
22
+ * gas price than the SDK release, a hyperchain or a devnet, produces a transaction that plain
23
+ * `buildTx` would refuse to serialize again because its fee is below the minimum this process
24
+ * computes. Nothing about it can be changed by re-serializing it, so nothing about it is checked.
25
+ * @category transaction builder
26
+ * @param params - Unpacked transaction, as returned by `unpackTx`
27
+ */
28
+ export declare function rebuildUnpackedTx(params: TxUnpacked): Encoded.Transaction;
16
29
  export type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<TxParamsAsync & {
17
30
  tag: TxType;
18
31
  }, 'tag' | OmitFields>;
@@ -1,12 +1,14 @@
1
1
  import { decode, encode, Encoding } from '../../utils/encoder.js';
2
2
  import { hash } from '../../utils/crypto.js';
3
+ import { serializeAsIsParam } from './field-types/interface.js';
3
4
  import { txSchema } from './schema.js';
4
5
  import { Tag } from './constants.js';
5
6
  import { buildContractId } from './helpers.js';
6
7
  import { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';
7
8
  import { ArgumentError } from '../../utils/errors.js';
8
9
  import { packEntry, unpackEntry } from './entry/index.js';
9
-
10
+ import { checkParametersUsable, getCachedProtocolParameters } from './protocol-parameters.js';
11
+ import { unwrapProxyIfPossible } from '../../utils/wrap-proxy.js';
10
12
  /**
11
13
  * JavaScript-based Transaction builder
12
14
  */
@@ -20,6 +22,11 @@ export function getSchema(tag, version) {
20
22
  * @param params - Transaction params
21
23
  */
22
24
  export function buildTx(params) {
25
+ // as trusted as `fee` is, see `checkParametersUsable`
26
+ const {
27
+ protocolParameters
28
+ } = params;
29
+ if (protocolParameters != null) checkParametersUsable(protocolParameters);
23
30
  return packRecord(txSchema, Tag, params, {
24
31
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
25
32
  unpackTx,
@@ -31,6 +38,58 @@ export function buildTx(params) {
31
38
  packEntry
32
39
  }, Encoding.Transaction);
33
40
  }
41
+
42
+ /**
43
+ * Serializes a transaction that already exists — the result of an `unpackTx` — back to its
44
+ * `tx_`-encoded form.
45
+ *
46
+ * Use it instead of `buildTx` for a round trip. The values of such a transaction are fixed, and
47
+ * belong to the protocol parameters of the node it was built for: a node running a lower minimum
48
+ * gas price than the SDK release, a hyperchain or a devnet, produces a transaction that plain
49
+ * `buildTx` would refuse to serialize again because its fee is below the minimum this process
50
+ * computes. Nothing about it can be changed by re-serializing it, so nothing about it is checked.
51
+ * @category transaction builder
52
+ * @param params - Unpacked transaction, as returned by `unpackTx`
53
+ */
54
+ export function rebuildUnpackedTx(params) {
55
+ return buildTx({
56
+ ...params,
57
+ [serializeAsIsParam]: true
58
+ });
59
+ }
60
+ // the fields the protocol parameters price
61
+ const parametrizedFields = ['fee', 'gasPrice', 'gasLimit'];
62
+
63
+ /**
64
+ * The parameters are needed to compute a priced value the caller didn't provide, and to check one
65
+ * it did against what node accepts. A build that provides every priced field of its type, and
66
+ * nests no transaction that still has to be built, serializes to the same bytes with or without
67
+ * them — requesting them would turn a build that needs no node into one that waits for it, as it
68
+ * would for a caller that passes `fee` exactly to avoid the round trip.
69
+ */
70
+ function needsProtocolParameters(schema, params) {
71
+ return schema.some(([key, field]) => {
72
+ const value = params[key];
73
+ if (parametrizedFields.includes(key)) return value == null;
74
+ // a nested transaction that is neither built (`tx_`) nor serialized (a buffer) yet is built
75
+ // here, and priced by these parameters in turn
76
+ if (field.nestedTransaction !== true) return false;
77
+ if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) return false;
78
+ // it is built here, but that doesn't mean anything in it is priced — the `SignedTx` wrapping
79
+ // an already serialized transaction that `AccountGeneralized` nests in its `GaMetaTx` has no
80
+ // priced field of its own
81
+ const nested = value;
82
+ let nestedSchema;
83
+ try {
84
+ nestedSchema = getSchema(nested.tag, nested.version);
85
+ } catch {
86
+ // an unknown tag or version fails later in `buildTx` with a better message than here
87
+ return true;
88
+ }
89
+ return needsProtocolParameters(nestedSchema, nested);
90
+ });
91
+ }
92
+
34
93
  // TODO: require onNode because it is the only reason this builder is async [breaking change]
35
94
  /**
36
95
  * Build transaction async (may request node for additional data)
@@ -39,14 +98,42 @@ export function buildTx(params) {
39
98
  * @returns tx_-encoded transaction
40
99
  */
41
100
  export async function buildTxAsync(params) {
42
- await Promise.all(getSchema(params.tag, params.version).map(async ([key, field]) => {
101
+ var _target$protocolParam;
102
+ // the caller may build another transaction out of the same object, and `prepare` writing the
103
+ // value it computed back would make the next build reuse them — the same nonce above all, and a
104
+ // `fee` that makes it skip the request for the parameters that priced this one
105
+ const paramsCopy = {
106
+ ...params
107
+ };
108
+ const {
109
+ onNode
110
+ } = paramsCopy;
111
+ const target = paramsCopy;
112
+ const schema = getSchema(paramsCopy.tag, paramsCopy.version);
113
+ // `onNode` of an sdk instance is a proxy that is not `null` even when no node is selected, and
114
+ // dereferencing it throws — a transaction that needs no node is still buildable in that case
115
+ const node = onNode != null ? unwrapProxyIfPossible(onNode) : undefined;
116
+ // started before the `prepare` calls below so that it runs in parallel with them: they read the
117
+ // parameters, but get this very request from the cache it registers synchronously. Below the
118
+ // `Promise.all` it would make `prepare` the originator and serialize the two requests
119
+ const parametersPromise = node != null && target.protocolParameters == null && needsProtocolParameters(schema, paramsCopy) ? getCachedProtocolParameters(node) : undefined;
120
+ // it is awaited after the `prepare` calls below, don't report it as an unhandled rejection if
121
+ // one of them throws first
122
+ parametersPromise?.catch(() => {});
123
+ await Promise.all(schema.map(async ([key, field]) => {
43
124
  if (field.prepare == null) return;
44
- // @ts-expect-error the type of `params[key]` can't be determined accurately
45
- params[key] = await field.prepare(params[key], params, params);
125
+ // @ts-expect-error the type of `paramsCopy[key]` can't be determined accurately
126
+ paramsCopy[key] = await field.prepare(paramsCopy[key], paramsCopy, paramsCopy);
46
127
  }));
128
+ const protocolParameters = (_target$protocolParam = target.protocolParameters) !== null && _target$protocolParam !== void 0 ? _target$protocolParam : await parametersPromise;
47
129
 
48
130
  // @ts-expect-error after preparation properties should be compatible with sync tx builder
49
- return buildTx(params);
131
+ return buildTx({
132
+ ...paramsCopy,
133
+ ...(protocolParameters != null && {
134
+ protocolParameters
135
+ })
136
+ });
50
137
  }
51
138
 
52
139
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["decode","encode","Encoding","hash","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","packEntry","unpackEntry","tag","version","buildTx","params","unpackTx","rebuildTx","overrideParams","Transaction","buildTxAsync","Promise","all","map","key","field","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../utils/encoder.js';\nimport { hash } from '../../utils/crypto.js';\nimport { Field } from './field-types/interface.js';\nimport { txSchema } from './schema.js';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated.js';\nimport { Tag } from './constants.js';\nimport { buildContractId } from './helpers.js';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';\nimport { ArgumentError } from '../../utils/errors.js';\nimport { packEntry, unpackEntry } from './entry/index.js';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding =\n | Encoding.Transaction\n | Encoding.Poi\n | Encoding.StateTrees\n | Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction {\n return packRecord(\n txSchema,\n Tag,\n params,\n {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx({ ...params, ...overrideParams }),\n packEntry,\n },\n Encoding.Transaction,\n );\n}\n\nexport type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<\n TxParamsAsync & { tag: TxType },\n 'tag' | OmitFields\n>;\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n await Promise.all(\n getSchema(params.tag, params.version).map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `params[key]` can't be determined accurately\n params[key] = await field.prepare(params[key], params, params);\n }),\n );\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx(params);\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, { unpackTx, unpackEntry }) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,wBAAwB;AAC1E,SAASC,IAAI,QAAQ,uBAA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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBW,SAAsC,EACtCC,MAAe,EACe;EAC9B,OAAOpB,YAAY,CAACN,QAAQ,EAAEC,GAAG,EAAEwB,SAAS,EAAEC,MAAM,EAAE;IAAEZ,QAAQ;IAAEL;EAAY,CAAC,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASkB,WAAWA,CAACC,KAAuC,EAAkB;EACnF,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACE,UAAU,CAAC,KAAK,CAAC,GAAGlC,MAAM,CAACgC,KAAK,CAAC,GAAGA,KAAK;EACzF,OAAO/B,MAAM,CAACE,IAAI,CAAC8B,IAAI,CAAC,EAAE/B,QAAQ,CAACiC,MAAM,CAAC;AAC5C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,2BAA2BA,CACzCC,UAA+B,EACN;EACzB,IAAIpB,MAAM,GAAGC,QAAQ,CAACmB,UAAU,CAAC;EACjC,IAAIhC,GAAG,CAACiC,QAAQ,KAAKrB,MAAM,CAACH,GAAG,EAAEG,MAAM,GAAGA,MAAM,CAACY,SAAS;EAC1D,IAAIxB,GAAG,CAACkC,gBAAgB,KAAKtB,MAAM,CAACH,GAAG,IAAIT,GAAG,CAACmC,UAAU,KAAKvB,MAAM,CAACH,GAAG,EAAE;IACxE,MAAM,IAAIH,aAAa,CAAC,YAAY,EAAE,gCAAgC,EAAEM,MAAM,CAACH,GAAG,CAAC;EACrF;EACA,OAAOR,eAAe,CAACW,MAAM,CAACwB,OAAO,EAAExB,MAAM,CAACyB,KAAK,CAAC;AACtD","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["decode","encode","Encoding","hash","serializeAsIsParam","txSchema","Tag","buildContractId","getSchema","getSchemaCommon","packRecord","unpackRecord","ArgumentError","packEntry","unpackEntry","checkParametersUsable","getCachedProtocolParameters","unwrapProxyIfPossible","tag","version","buildTx","params","protocolParameters","unpackTx","rebuildTx","overrideParams","Transaction","rebuildUnpackedTx","parametrizedFields","needsProtocolParameters","schema","some","key","field","value","includes","nestedTransaction","ArrayBuffer","isView","nested","nestedSchema","buildTxAsync","_target$protocolParam","paramsCopy","onNode","target","node","undefined","parametersPromise","catch","Promise","all","map","prepare","encodedTx","txType","buildTxHash","rawTx","data","startsWith","TxHash","buildContractIdByContractTx","contractTx","SignedTx","ContractCreateTx","GaAttachTx","ownerId","nonce"],"sources":["../../../src/tx/builder/index.ts"],"sourcesContent":["import { decode, encode, Encoded, Encoding } from '../../utils/encoder.js';\nimport { hash } from '../../utils/crypto.js';\nimport { Field, serializeAsIsParam } from './field-types/interface.js';\nimport { txSchema } from './schema.js';\nimport { TxUnpacked, TxParams, TxParamsAsync } from './schema.generated.js';\nimport { Tag } from './constants.js';\nimport { buildContractId } from './helpers.js';\nimport { getSchema as getSchemaCommon, packRecord, unpackRecord } from './common.js';\nimport { ArgumentError } from '../../utils/errors.js';\nimport { packEntry, unpackEntry } from './entry/index.js';\nimport {\n checkParametersUsable,\n getCachedProtocolParameters,\n ProtocolParameters,\n ProtocolParametersOption,\n} from './protocol-parameters.js';\nimport { unwrapProxyIfPossible } from '../../utils/wrap-proxy.js';\nimport type Node from '../../Node.js';\n\n/**\n * JavaScript-based Transaction builder\n */\n\nexport function getSchema(tag: Tag, version?: number): Array<[string, Field]> {\n return getSchemaCommon(txSchema, Tag, tag, version);\n}\n\ntype TxEncoding =\n | Encoding.Transaction\n | Encoding.Poi\n | Encoding.StateTrees\n | Encoding.CallStateTree;\n\n/**\n * Build transaction\n * @category transaction builder\n * @param params - Transaction params\n */\nexport function buildTx(params: TxParams): Encoded.Transaction {\n // as trusted as `fee` is, see `checkParametersUsable`\n const { protocolParameters } = params as ProtocolParametersOption;\n if (protocolParameters != null) checkParametersUsable(protocolParameters);\n return packRecord(\n txSchema,\n Tag,\n params,\n {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n unpackTx,\n buildTx,\n rebuildTx: (overrideParams: any) => buildTx({ ...params, ...overrideParams }),\n packEntry,\n },\n Encoding.Transaction,\n );\n}\n\n/**\n * Serializes a transaction that already exists — the result of an `unpackTx` — back to its\n * `tx_`-encoded form.\n *\n * Use it instead of `buildTx` for a round trip. The values of such a transaction are fixed, and\n * belong to the protocol parameters of the node it was built for: a node running a lower minimum\n * gas price than the SDK release, a hyperchain or a devnet, produces a transaction that plain\n * `buildTx` would refuse to serialize again because its fee is below the minimum this process\n * computes. Nothing about it can be changed by re-serializing it, so nothing about it is checked.\n * @category transaction builder\n * @param params - Unpacked transaction, as returned by `unpackTx`\n */\nexport function rebuildUnpackedTx(params: TxUnpacked): Encoded.Transaction {\n return buildTx({ ...params, [serializeAsIsParam]: true } as unknown as TxParams);\n}\n\nexport type BuildTxOptions<TxType extends Tag, OmitFields extends string> = Omit<\n TxParamsAsync & { tag: TxType },\n 'tag' | OmitFields\n>;\n\n// the fields the protocol parameters price\nconst parametrizedFields = ['fee', 'gasPrice', 'gasLimit'];\n\n/**\n * The parameters are needed to compute a priced value the caller didn't provide, and to check one\n * it did against what node accepts. A build that provides every priced field of its type, and\n * nests no transaction that still has to be built, serializes to the same bytes with or without\n * them — requesting them would turn a build that needs no node into one that waits for it, as it\n * would for a caller that passes `fee` exactly to avoid the round trip.\n */\nfunction needsProtocolParameters(schema: Array<[string, Field]>, params: TxParamsAsync): boolean {\n return schema.some(([key, field]) => {\n const value = (params as unknown as Record<string, unknown>)[key];\n if (parametrizedFields.includes(key)) return value == null;\n // a nested transaction that is neither built (`tx_`) nor serialized (a buffer) yet is built\n // here, and priced by these parameters in turn\n if (field.nestedTransaction !== true) return false;\n if (value == null || typeof value === 'string' || ArrayBuffer.isView(value)) return false;\n // it is built here, but that doesn't mean anything in it is priced — the `SignedTx` wrapping\n // an already serialized transaction that `AccountGeneralized` nests in its `GaMetaTx` has no\n // priced field of its own\n const nested = value as TxParamsAsync;\n let nestedSchema;\n try {\n nestedSchema = getSchema(nested.tag, nested.version);\n } catch {\n // an unknown tag or version fails later in `buildTx` with a better message than here\n return true;\n }\n return needsProtocolParameters(nestedSchema, nested);\n });\n}\n\n// TODO: require onNode because it is the only reason this builder is async [breaking change]\n/**\n * Build transaction async (may request node for additional data)\n * @category transaction builder\n * @param params - Transaction params\n * @returns tx_-encoded transaction\n */\nexport async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Transaction> {\n // the caller may build another transaction out of the same object, and `prepare` writing the\n // value it computed back would make the next build reuse them — the same nonce above all, and a\n // `fee` that makes it skip the request for the parameters that priced this one\n const paramsCopy = { ...params };\n const { onNode } = paramsCopy as { onNode?: Node };\n const target = paramsCopy as { protocolParameters?: ProtocolParameters };\n const schema = getSchema(paramsCopy.tag, paramsCopy.version);\n // `onNode` of an sdk instance is a proxy that is not `null` even when no node is selected, and\n // dereferencing it throws — a transaction that needs no node is still buildable in that case\n const node = onNode != null ? unwrapProxyIfPossible(onNode) : undefined;\n // started before the `prepare` calls below so that it runs in parallel with them: they read the\n // parameters, but get this very request from the cache it registers synchronously. Below the\n // `Promise.all` it would make `prepare` the originator and serialize the two requests\n const parametersPromise =\n node != null && target.protocolParameters == null && needsProtocolParameters(schema, paramsCopy)\n ? getCachedProtocolParameters(node)\n : undefined;\n // it is awaited after the `prepare` calls below, don't report it as an unhandled rejection if\n // one of them throws first\n parametersPromise?.catch(() => {});\n\n await Promise.all(\n schema.map(async ([key, field]) => {\n if (field.prepare == null) return;\n // @ts-expect-error the type of `paramsCopy[key]` can't be determined accurately\n paramsCopy[key] = await field.prepare(paramsCopy[key], paramsCopy, paramsCopy);\n }),\n );\n\n const protocolParameters = target.protocolParameters ?? (await parametersPromise);\n\n // @ts-expect-error after preparation properties should be compatible with sync tx builder\n return buildTx({ ...paramsCopy, ...(protocolParameters != null && { protocolParameters }) });\n}\n\n/**\n * Unpack transaction encoded as string\n * @category transaction builder\n * @param encodedTx - Encoded transaction\n * @param txType - Expected transaction type\n * @returns Transaction params\n */\nexport function unpackTx<TxType extends Tag>(\n encodedTx: Encoded.Generic<TxEncoding>,\n txType?: TxType,\n): TxUnpacked & { tag: TxType } {\n return unpackRecord(txSchema, Tag, encodedTx, txType, { unpackTx, unpackEntry }) as any;\n}\n\n/**\n * Build a transaction hash\n * @category transaction builder\n * @param rawTx - base64 or rlp encoded transaction\n * @returns Transaction hash\n */\nexport function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash {\n const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx) : rawTx;\n return encode(hash(data), Encoding.TxHash);\n}\n\n/**\n * Build a contract public key by contractCreateTx, gaAttach or signedTx\n * @category contract\n * @param contractTx - Transaction\n * @returns Contract public key\n */\nexport function buildContractIdByContractTx(\n contractTx: Encoded.Transaction,\n): Encoded.ContractAddress {\n let params = unpackTx(contractTx);\n if (Tag.SignedTx === params.tag) params = params.encodedTx;\n if (Tag.ContractCreateTx !== params.tag && Tag.GaAttachTx !== params.tag) {\n throw new ArgumentError('contractTx', 'a contractCreateTx or gaAttach', params.tag);\n }\n return buildContractId(params.ownerId, params.nonce);\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,EAAWC,QAAQ,QAAQ,wBAAwB;AAC1E,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAAgBC,kBAAkB,QAAQ,4BAA4B;AACtE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ,cAAc;AAC9C,SAASC,SAAS,IAAIC,eAAe,EAAEC,UAAU,EAAEC,YAAY,QAAQ,aAAa;AACpF,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,SAAS,EAAEC,WAAW,QAAQ,kBAAkB;AACzD,SACEC,qBAAqB,EACrBC,2BAA2B,QAGtB,0BAA0B;AACjC,SAASC,qBAAqB,QAAQ,2BAA2B;AAGjE;AACA;AACA;;AAEA,OAAO,SAAST,SAASA,CAACU,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AC1D,IAAIhD,GAAG,CAAC0D,gBAAgB,KAAK3C,MAAM,CAACH,GAAG,IAAIZ,GAAG,CAAC2D,UAAU,KAAK5C,MAAM,CAACH,GAAG,EAAE;IACxE,MAAM,IAAIN,aAAa,CAAC,YAAY,EAAE,gCAAgC,EAAES,MAAM,CAACH,GAAG,CAAC;EACrF;EACA,OAAOX,eAAe,CAACc,MAAM,CAAC6C,OAAO,EAAE7C,MAAM,CAAC8C,KAAK,CAAC;AACtD","ignoreList":[]}
@@ -0,0 +1,123 @@
1
+ import { AbiVersion, Tag } from './constants.js';
2
+ import type Node from '../../Node.js';
3
+ /**
4
+ * Consensus parameters and node policy settings the transaction builder needs to produce a
5
+ * transaction the node would accept — see {@link getCachedProtocolParameters}.
6
+ * @category transaction builder
7
+ */
8
+ export interface ProtocolParameters {
9
+ /**
10
+ * Consensus minimum gas price in aettos, the minimum transaction fee is the transaction's fee
11
+ * gas multiplied by this value
12
+ */
13
+ readonly minGasPrice: bigint;
14
+ /**
15
+ * Minimum gas price accepted by the miner of the node the SDK is connected to. A transaction
16
+ * below it is still valid, but this node won't mine it.
17
+ */
18
+ readonly minMinerGasPrice: bigint;
19
+ /** Gas per serialized transaction byte counted into the minimum fee */
20
+ readonly gasPerByte: number;
21
+ /**
22
+ * Maximum total gas the node the SDK is connected to accepts in a single micro block. Node
23
+ * policy rather than a consensus parameter, it may differ between nodes.
24
+ */
25
+ readonly blockGasLimit: number;
26
+ /**
27
+ * Maximum gas accepted for a generalized account authentication function by the node the SDK is
28
+ * connected to. Node policy rather than a consensus parameter, it may differ between nodes.
29
+ */
30
+ readonly maxAuthFunGas: number;
31
+ /** Base fee gas by transaction type, transactions not executing contract code */
32
+ readonly txBaseGas: Readonly<Partial<Record<Tag, number>>>;
33
+ /** Base fee gas of contract-executing transaction types, by ABI version */
34
+ readonly contractTxBaseGas: Readonly<Partial<Record<Tag, Readonly<Partial<Record<AbiVersion, number>>>>>>;
35
+ /**
36
+ * State rent gas fraction per key block by transaction type,
37
+ * state gas is `ceil(relativeTtl * part / whole)`
38
+ */
39
+ readonly stateGasPerBlock: Readonly<Partial<Record<Tag, Readonly<{
40
+ part: number;
41
+ whole: number;
42
+ }>>>>;
43
+ }
44
+ /**
45
+ * Transaction option to build a transaction against specific consensus parameters. `buildTxAsync`
46
+ * sets it to the parameters it requests from node, provide it to build a transaction offline for a
47
+ * node that doesn't run the protocol version the current SDK release was made for.
48
+ * @category transaction builder
49
+ */
50
+ export interface ProtocolParametersOption {
51
+ protocolParameters?: ProtocolParameters;
52
+ }
53
+ /**
54
+ * Protocol parameters of Ceres as they were at the moment of the SDK release. Used to build
55
+ * transactions without a node connection, and on nodes that don't provide the protocol parameters
56
+ * endpoint yet.
57
+ * @category transaction builder
58
+ * @see {@link https://github.com/aeternity/protocol/blob/master/consensus/README.md#gas}
59
+ */
60
+ export declare const defaultProtocolParameters: ProtocolParameters;
61
+ /**
62
+ * `Math.max(...array)` passes every element as an argument and overflows the stack on an array
63
+ * node can make arbitrarily long — it reports one entry per transaction type and abi version.
64
+ */
65
+ export declare function maxOf(numbers: number[]): number;
66
+ /**
67
+ * Checks that parameters a caller provided in options can price a transaction at all — only values
68
+ * that would produce `NaN`, `Infinity`, or a division by zero, not their magnitude: options are the
69
+ * way out of the bounds {@link convertProtocolParameters} applies, bounding them here would leave
70
+ * no way to build against a network the SDK release doesn't know. They are as trusted as `fee` and
71
+ * `gasLimit`: must not come from untrusted input, this only turns an unusable value into an error
72
+ * naming the field. See `serializeAsIsParam`.
73
+ * @param parameters - Parameters provided in options
74
+ */
75
+ export declare function checkParametersUsable(parameters: ProtocolParameters): void;
76
+ /**
77
+ * Factor the gas price ceiling of `gas-price.ts` is lowered by, so that the worst case fee doesn't
78
+ * become the product of that ceiling and the fee gas bound of {@link convertProtocolParameters}.
79
+ * The gas limit raise is charged to the gas limit default instead ({@link getGasLimitDivisor}).
80
+ * It is 1 unless the parameters came from node.
81
+ *
82
+ * The biggest raise among all transaction types, not the one of the type being built — so a node
83
+ * repricing one type lowers the ceiling for every type. The ceiling is 100000 times the minimum
84
+ * gas price, far above the demand-based price this bounds in practice.
85
+ * @param parameters - Parameters a transaction is built against
86
+ */
87
+ export declare function getGasPriceDivisor(parameters: ProtocolParameters): number;
88
+ /**
89
+ * The cost of a contract transaction is `gasPrice * gasLimit`, and the gas limit the SDK defaults
90
+ * to comes from `blockGasLimit` — from `maxAuthFunGas` on a `GaMetaTx`. This is the factor node
91
+ * raises the one `tag` reads by, so that lowering the default by it keeps the product within the
92
+ * one of the SDK release. It is 1 unless the parameters came from node.
93
+ *
94
+ * Only the limit `tag` reads: charging the other one would shrink a gas limit because node raised
95
+ * something that transaction never reads. The fee gas raise is charged to the gas price ceiling
96
+ * ({@link getGasPriceDivisor}) instead.
97
+ * @param parameters - Parameters a transaction is built against
98
+ * @param tag - Type of the transaction the gas limit is defaulted for
99
+ */
100
+ export declare function getGasLimitDivisor(parameters: ProtocolParameters, tag: Tag): number;
101
+ /**
102
+ * Converts the node responses to the shape the transaction builder uses, rejecting values far
103
+ * above the ones the SDK was released with. Not a part of the public api, it is exported for
104
+ * tests — use {@link getCachedProtocolParameters}.
105
+ * @param response - Response of the `/v3/protocol-parameters` endpoint
106
+ * @param nodeSettings - Response of the `/v3/node-settings` endpoint
107
+ */
108
+ export declare function convertProtocolParameters(response: Awaited<ReturnType<Node['getProtocolParameters']>>, nodeSettings: Awaited<ReturnType<Node['getNodeSettings']>>): ProtocolParameters;
109
+ /**
110
+ * Requests protocol parameters from node, the result is cached per node instance.
111
+ *
112
+ * Falls back to {@link defaultProtocolParameters} for a node that doesn't provide the endpoints,
113
+ * can't be reached, or answers something this SDK release can't read. Rejects only when node
114
+ * reports parameters that would price a transaction far above the SDK release — see
115
+ * {@link ProtocolParametersOption} for the way out of that.
116
+ *
117
+ * The cache is keyed by the `Node` object, so code that constructs a `Node` per request (a
118
+ * serverless handler, an edge worker) requests the parameters again for each one. Keep one `Node`
119
+ * instance per endpoint to get the benefit of the cache.
120
+ * @category transaction builder
121
+ * @param nodeOrProxy - Node to request the parameters from
122
+ */
123
+ export declare function getCachedProtocolParameters(nodeOrProxy: Node): Promise<ProtocolParameters>;