@alephium/web3 1.12.0-danube.1 → 1.12.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 (51) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/address/address.d.ts +3 -2
  4. package/dist/src/address/address.js +39 -41
  5. package/dist/src/api/api-alephium.d.ts +66 -15
  6. package/dist/src/api/api-alephium.js +1 -1
  7. package/dist/src/api/types.d.ts +1 -1
  8. package/dist/src/api/types.js +5 -10
  9. package/dist/src/codec/checksum-codec.d.ts +8 -0
  10. package/dist/src/codec/checksum-codec.js +50 -0
  11. package/dist/src/codec/instr-codec.d.ts +10 -26
  12. package/dist/src/codec/instr-codec.js +18 -38
  13. package/dist/src/codec/lockup-script-codec.d.ts +16 -7
  14. package/dist/src/codec/lockup-script-codec.js +11 -5
  15. package/dist/src/codec/public-key-like-codec.d.ts +17 -0
  16. package/dist/src/codec/public-key-like-codec.js +30 -0
  17. package/dist/src/codec/reader.d.ts +2 -0
  18. package/dist/src/codec/reader.js +10 -0
  19. package/dist/src/codec/unlock-script-codec.d.ts +3 -11
  20. package/dist/src/codec/unlock-script-codec.js +4 -14
  21. package/dist/src/contract/contract.d.ts +9 -13
  22. package/dist/src/contract/contract.js +21 -42
  23. package/dist/src/contract/deployment.d.ts +0 -2
  24. package/dist/src/contract/ralph.js +1 -2
  25. package/dist/src/signer/signer.d.ts +13 -13
  26. package/dist/src/signer/signer.js +11 -85
  27. package/dist/src/signer/tx-builder.d.ts +4 -4
  28. package/dist/src/signer/tx-builder.js +2 -42
  29. package/dist/src/signer/types.d.ts +14 -13
  30. package/dist/src/signer/types.js +9 -0
  31. package/dist/src/utils/djb2.js +1 -1
  32. package/dist/src/utils/sign.js +2 -2
  33. package/dist/src/utils/webcrypto.d.ts +1 -3
  34. package/package.json +2 -2
  35. package/src/address/address.ts +43 -48
  36. package/src/api/api-alephium.ts +66 -15
  37. package/src/api/types.ts +5 -10
  38. package/src/codec/checksum-codec.ts +47 -0
  39. package/src/codec/instr-codec.ts +21 -45
  40. package/src/codec/lockup-script-codec.ts +23 -12
  41. package/src/codec/public-key-like-codec.ts +37 -0
  42. package/src/codec/reader.ts +10 -0
  43. package/src/codec/unlock-script-codec.ts +8 -23
  44. package/src/contract/contract.ts +33 -71
  45. package/src/contract/deployment.ts +0 -2
  46. package/src/contract/ralph.ts +2 -5
  47. package/src/signer/signer.ts +25 -118
  48. package/src/signer/tx-builder.ts +15 -62
  49. package/src/signer/types.ts +28 -30
  50. package/src/utils/djb2.ts +1 -1
  51. package/src/utils/sign.ts +2 -2
@@ -5,7 +5,8 @@ export declare enum AddressType {
5
5
  P2MPKH = 1,
6
6
  P2SH = 2,
7
7
  P2C = 3,
8
- P2PK = 4
8
+ P2PK = 4,
9
+ P2HMPK = 5
9
10
  }
10
11
  export declare function validateAddress(address: string): void;
11
12
  export declare function isValidAddress(address: string): boolean;
@@ -14,7 +15,7 @@ export declare function isAssetAddress(address: string): boolean;
14
15
  export declare function isGrouplessAddress(address: string): boolean;
15
16
  export declare function isGrouplessAddressWithoutGroupIndex(address: string): boolean;
16
17
  export declare function isGrouplessAddressWithGroupIndex(address: string): boolean;
17
- export declare function defaultGroupOfGrouplessAddress(pubKey: Uint8Array): number;
18
+ export declare function defaultGroupOfGrouplessAddress(bytes: Uint8Array): number;
18
19
  export declare function isContractAddress(address: string): boolean;
19
20
  export declare function groupOfAddress(address: string): number;
20
21
  export declare function contractIdFromAddress(address: string): Uint8Array;
@@ -55,6 +55,7 @@ const codec_1 = require("../codec");
55
55
  const djb2_1 = __importDefault(require("../utils/djb2"));
56
56
  const error_1 = require("../error");
57
57
  const codec_2 = require("../codec/codec");
58
+ const public_key_like_codec_1 = require("../codec/public-key-like-codec");
58
59
  const secp256k1 = new elliptic_1.ec('secp256k1');
59
60
  const secp256r1 = new elliptic_1.ec('p256');
60
61
  const ed25519 = new elliptic_1.eddsa('ed25519');
@@ -66,6 +67,7 @@ var AddressType;
66
67
  AddressType[AddressType["P2SH"] = 2] = "P2SH";
67
68
  AddressType[AddressType["P2C"] = 3] = "P2C";
68
69
  AddressType[AddressType["P2PK"] = 4] = "P2PK";
70
+ AddressType[AddressType["P2HMPK"] = 5] = "P2HMPK";
69
71
  })(AddressType = exports.AddressType || (exports.AddressType = {}));
70
72
  function validateAddress(address) {
71
73
  decodeAndValidateAddress(address);
@@ -110,36 +112,23 @@ function decodeAndValidateAddress(address) {
110
112
  if (decoded.length === 33)
111
113
  return decoded;
112
114
  }
113
- else if (isGrouplessAddressWithGroup(decoded)) {
114
- // [type, keyType, ...publicKey, ...checkSum, ...groupByte]
115
- const publicKeyToIndex = decoded.length - 1 - 4;
116
- const publicKeyLikeBytes = decoded.slice(1, publicKeyToIndex);
117
- const checksum = (0, utils_1.binToHex)(decoded.slice(publicKeyToIndex, publicKeyToIndex + 4));
118
- const expectedChecksum = (0, utils_1.binToHex)(codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(publicKeyLikeBytes)));
119
- if (checksum !== expectedChecksum) {
120
- throw new Error(`Invalid checksum for P2PK address: ${address}`);
121
- }
122
- const group = codec_2.byteCodec.decode(decoded.slice(decoded.length - 1, decoded.length));
123
- validateGroupIndex(group);
115
+ else if (addressType === AddressType.P2PK) {
116
+ const p2pk = lockup_script_codec_1.lockupScriptCodec.decode(decoded).value;
117
+ validateGroupIndex(p2pk.group);
118
+ return decoded;
119
+ }
120
+ else if (addressType === AddressType.P2HMPK) {
121
+ const p2hmpk = lockup_script_codec_1.lockupScriptCodec.decode(decoded).value;
122
+ validateGroupIndex(p2hmpk.group);
124
123
  return decoded;
125
124
  }
126
125
  throw new Error(`Invalid address: ${address}`);
127
126
  }
128
- function isGrouplessAddressWithoutGroup(decoded) {
129
- // An ED25519 public key is 32 bytes; other public keys are 33 bytes.
130
- // Format: AddressType(1 byte) + KeyType(1 byte) + PublicKey(32/33 bytes) + Checksum(4 bytes)
131
- return decoded[0] === AddressType.P2PK && (decoded.length === 38 || decoded.length === 39);
132
- }
133
- function isGrouplessAddressWithGroup(decoded) {
134
- // An ED25519 public key is 32 bytes; other public keys are 33 bytes.
135
- // Format: AddressType(1 byte) + KeyType(1 byte) + PublicKey(32/33 bytes) + Checksum(4 bytes) + GroupIndex(1 byte)
136
- return decoded[0] === AddressType.P2PK && (decoded.length === 39 || decoded.length === 40);
137
- }
138
127
  function addressToBytes(address) {
139
128
  if (hasExplicitGroupIndex(address)) {
140
129
  const groupIndex = parseGroupIndex(address[address.length - 1]);
141
130
  const decoded = (0, bs58_1.base58ToBytes)(address.slice(0, address.length - 2));
142
- if (isGrouplessAddressWithoutGroup(decoded)) {
131
+ if (decoded.length > 0 && isGrouplessType(decoded[0])) {
143
132
  const groupByte = codec_2.byteCodec.encode(groupIndex);
144
133
  return new Uint8Array([...decoded, ...groupByte]);
145
134
  }
@@ -147,7 +136,7 @@ function addressToBytes(address) {
147
136
  }
148
137
  else {
149
138
  const decoded = (0, bs58_1.base58ToBytes)(address);
150
- if (isGrouplessAddressWithoutGroup(decoded)) {
139
+ if (decoded.length > 0 && isGrouplessType(decoded[0])) {
151
140
  const group = defaultGroupOfGrouplessAddress(decoded.slice(2, decoded.length - 4));
152
141
  const groupByte = codec_2.byteCodec.encode(group);
153
142
  return new Uint8Array([...decoded, ...groupByte]);
@@ -161,12 +150,15 @@ function isAssetAddress(address) {
161
150
  return (addressType === AddressType.P2PKH ||
162
151
  addressType === AddressType.P2MPKH ||
163
152
  addressType === AddressType.P2SH ||
164
- addressType === AddressType.P2PK);
153
+ addressType === AddressType.P2PK ||
154
+ addressType === AddressType.P2HMPK);
165
155
  }
166
156
  exports.isAssetAddress = isAssetAddress;
157
+ function isGrouplessType(type) {
158
+ return type === AddressType.P2PK || type === AddressType.P2HMPK;
159
+ }
167
160
  function isGrouplessAddress(address) {
168
- const addressType = decodeAndValidateAddress(address)[0];
169
- return addressType === AddressType.P2PK;
161
+ return isGrouplessType(decodeAndValidateAddress(address)[0]);
170
162
  }
171
163
  exports.isGrouplessAddress = isGrouplessAddress;
172
164
  function isGrouplessAddressWithoutGroupIndex(address) {
@@ -177,8 +169,8 @@ function isGrouplessAddressWithGroupIndex(address) {
177
169
  return hasExplicitGroupIndex(address) && isGrouplessAddress(address);
178
170
  }
179
171
  exports.isGrouplessAddressWithGroupIndex = isGrouplessAddressWithGroupIndex;
180
- function defaultGroupOfGrouplessAddress(pubKey) {
181
- return pubKey[pubKey.length - 1] & 0xff % constants_1.TOTAL_NUMBER_OF_GROUPS;
172
+ function defaultGroupOfGrouplessAddress(bytes) {
173
+ return (bytes[bytes.length - 1] & 0xff) % constants_1.TOTAL_NUMBER_OF_GROUPS;
182
174
  }
183
175
  exports.defaultGroupOfGrouplessAddress = defaultGroupOfGrouplessAddress;
184
176
  function isContractAddress(address) {
@@ -190,17 +182,17 @@ function groupOfAddress(address) {
190
182
  const decoded = decodeAndValidateAddress(address);
191
183
  const addressType = decoded[0];
192
184
  const addressBody = decoded.slice(1);
193
- if (addressType == AddressType.P2PKH) {
185
+ if (addressType === AddressType.P2PKH) {
194
186
  return groupOfP2pkhAddress(addressBody);
195
187
  }
196
- else if (addressType == AddressType.P2MPKH) {
188
+ else if (addressType === AddressType.P2MPKH) {
197
189
  return groupOfP2mpkhAddress(addressBody);
198
190
  }
199
- else if (addressType == AddressType.P2SH) {
191
+ else if (addressType === AddressType.P2SH) {
200
192
  return groupOfP2shAddress(addressBody);
201
193
  }
202
- else if (addressType == AddressType.P2PK) {
203
- return groupOfP2pkAddress(addressBody);
194
+ else if (isGrouplessType(addressType)) {
195
+ return groupOfGrouplessAddress(addressBody);
204
196
  }
205
197
  else {
206
198
  // Contract Address
@@ -217,8 +209,8 @@ function groupOfP2pkhAddress(address) {
217
209
  function groupOfP2mpkhAddress(address) {
218
210
  return groupFromBytes(address.slice(1, 33));
219
211
  }
220
- function groupOfP2pkAddress(address) {
221
- return codec_2.byteCodec.decode(address.slice(38, 39)) % constants_1.TOTAL_NUMBER_OF_GROUPS;
212
+ function groupOfGrouplessAddress(address) {
213
+ return address[address.length - 1] % constants_1.TOTAL_NUMBER_OF_GROUPS;
222
214
  }
223
215
  // Pay to script hash address
224
216
  function groupOfP2shAddress(address) {
@@ -266,10 +258,16 @@ function publicKeyFromPrivateKey(privateKey, _keyType) {
266
258
  }
267
259
  exports.publicKeyFromPrivateKey = publicKeyFromPrivateKey;
268
260
  function p2pkAddressFromPublicKey(publicKey, keyType) {
269
- const keyTypeByte = keyType === 'gl-secp256k1' ? 0x00 : keyType === 'gl-secp256r1' ? 0x01 : keyType === 'gl-ed25519' ? 0x02 : 0x03;
270
- const publicKeyBytes = new Uint8Array([keyTypeByte, ...(0, utils_1.hexToBinUnsafe)(publicKey)]);
271
- const checksum = codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(publicKeyBytes));
272
- const bytes = new Uint8Array([AddressType.P2PK, ...publicKeyBytes, ...checksum]);
261
+ const rawBytes = (0, utils_1.hexToBinUnsafe)(publicKey);
262
+ const publicKeyLike = keyType === 'gl-secp256k1'
263
+ ? { kind: 'SecP256K1', value: rawBytes }
264
+ : keyType === 'gl-secp256r1'
265
+ ? { kind: 'SecP256R1', value: rawBytes }
266
+ : keyType === 'gl-ed25519'
267
+ ? { kind: 'ED25519', value: rawBytes }
268
+ : { kind: 'WebAuthn', value: rawBytes };
269
+ const publicKeyBytes = public_key_like_codec_1.safePublicKeyLikeCodec.encode(publicKeyLike);
270
+ const bytes = new Uint8Array([AddressType.P2PK, ...publicKeyBytes]);
273
271
  return bs58_1.default.encode(bytes);
274
272
  }
275
273
  function addressFromPublicKey(publicKey, _keyType) {
@@ -340,7 +338,7 @@ function groupOfLockupScript(lockupScript) {
340
338
  else if (lockupScript.kind === 'P2SH') {
341
339
  return groupFromBytes(lockupScript.value);
342
340
  }
343
- else if (lockupScript.kind === 'P2PK') {
341
+ else if (lockupScript.kind === 'P2PK' || lockupScript.kind === 'P2HMPK') {
344
342
  return lockupScript.value.group % constants_1.TOTAL_NUMBER_OF_GROUPS;
345
343
  }
346
344
  else {
@@ -372,7 +370,7 @@ function addressWithoutExplicitGroupIndex(address) {
372
370
  }
373
371
  exports.addressWithoutExplicitGroupIndex = addressWithoutExplicitGroupIndex;
374
372
  function addressFromLockupScript(lockupScript) {
375
- if (lockupScript.kind === 'P2PK') {
373
+ if (lockupScript.kind === 'P2PK' || lockupScript.kind === 'P2HMPK') {
376
374
  const groupByte = lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(-1);
377
375
  const address = bs58_1.default.encode(lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(0, -1));
378
376
  return `${address}:${groupByte}`;
@@ -250,26 +250,58 @@ export interface BuildExecuteScriptTx {
250
250
  group?: number;
251
251
  /** @format double */
252
252
  gasEstimationMultiplier?: number;
253
+ /** @format uint256 */
254
+ dustAmount?: string;
253
255
  }
254
256
  /** BuildExecuteScriptTxResult */
255
257
  export type BuildExecuteScriptTxResult = BuildGrouplessExecuteScriptTxResult | BuildSimpleExecuteScriptTxResult;
256
258
  /** BuildGrouplessDeployContractTxResult */
257
259
  export interface BuildGrouplessDeployContractTxResult {
258
- transferTxs: BuildSimpleTransferTxResult[];
259
- deployContractTx: BuildSimpleDeployContractTxResult;
260
- type: string;
260
+ /** @format int32 */
261
+ fromGroup: number;
262
+ /** @format int32 */
263
+ toGroup: number;
264
+ unsignedTx: string;
265
+ /** @format gas */
266
+ gasAmount: number;
267
+ /** @format uint256 */
268
+ gasPrice: string;
269
+ /** @format 32-byte-hash */
270
+ txId: string;
271
+ /** @format address */
272
+ contractAddress: string;
273
+ fundingTxs?: BuildSimpleTransferTxResult[];
261
274
  }
262
275
  /** BuildGrouplessExecuteScriptTxResult */
263
276
  export interface BuildGrouplessExecuteScriptTxResult {
264
- transferTxs: BuildSimpleTransferTxResult[];
265
- executeScriptTx: BuildSimpleExecuteScriptTxResult;
266
- type: string;
277
+ /** @format int32 */
278
+ fromGroup: number;
279
+ /** @format int32 */
280
+ toGroup: number;
281
+ unsignedTx: string;
282
+ /** @format gas */
283
+ gasAmount: number;
284
+ /** @format uint256 */
285
+ gasPrice: string;
286
+ /** @format 32-byte-hash */
287
+ txId: string;
288
+ simulationResult: SimulationResult;
289
+ fundingTxs?: BuildSimpleTransferTxResult[];
267
290
  }
268
291
  /** BuildGrouplessTransferTxResult */
269
292
  export interface BuildGrouplessTransferTxResult {
270
- transferTxs: BuildSimpleTransferTxResult[];
271
- transferTx: BuildSimpleTransferTxResult;
272
- type: string;
293
+ unsignedTx: string;
294
+ /** @format gas */
295
+ gasAmount: number;
296
+ /** @format uint256 */
297
+ gasPrice: string;
298
+ /** @format 32-byte-hash */
299
+ txId: string;
300
+ /** @format int32 */
301
+ fromGroup: number;
302
+ /** @format int32 */
303
+ toGroup: number;
304
+ fundingTxs?: BuildSimpleTransferTxResult[];
273
305
  }
274
306
  /** BuildInfo */
275
307
  export interface BuildInfo {
@@ -289,17 +321,24 @@ export interface BuildMultisig {
289
321
  /** @format address */
290
322
  fromAddress: string;
291
323
  fromPublicKeys: string[];
324
+ fromPublicKeyTypes?: string[];
325
+ fromPublicKeyIndexes?: number[];
292
326
  destinations: Destination[];
293
327
  /** @format gas */
294
328
  gas?: number;
295
329
  /** @format uint256 */
296
330
  gasPrice?: string;
331
+ /** @format group-index */
332
+ group?: number;
333
+ multiSigType?: 'P2HMPK' | 'P2MPKH';
297
334
  }
298
335
  /** BuildMultisigAddress */
299
336
  export interface BuildMultisigAddress {
300
337
  keys: string[];
338
+ keyTypes?: string[];
301
339
  /** @format int32 */
302
340
  mrequired: number;
341
+ multiSigType?: 'P2HMPK' | 'P2MPKH';
303
342
  }
304
343
  /** BuildMultisigAddressResult */
305
344
  export interface BuildMultisigAddressResult {
@@ -321,7 +360,6 @@ export interface BuildSimpleDeployContractTxResult {
321
360
  txId: string;
322
361
  /** @format address */
323
362
  contractAddress: string;
324
- type: string;
325
363
  }
326
364
  /** BuildSimpleExecuteScriptTxResult */
327
365
  export interface BuildSimpleExecuteScriptTxResult {
@@ -337,7 +375,6 @@ export interface BuildSimpleExecuteScriptTxResult {
337
375
  /** @format 32-byte-hash */
338
376
  txId: string;
339
377
  simulationResult: SimulationResult;
340
- type: string;
341
378
  }
342
379
  /** BuildSimpleTransferTxResult */
343
380
  export interface BuildSimpleTransferTxResult {
@@ -352,12 +389,13 @@ export interface BuildSimpleTransferTxResult {
352
389
  fromGroup: number;
353
390
  /** @format int32 */
354
391
  toGroup: number;
355
- type: string;
356
392
  }
357
393
  /** BuildSweepAddressTransactions */
358
394
  export interface BuildSweepAddressTransactions {
359
- /** @format public-key */
395
+ /** @format hex-string */
360
396
  fromPublicKey: string;
397
+ /** @format hex-string */
398
+ fromPublicKeyType?: string;
361
399
  /** @format address */
362
400
  toAddress: string;
363
401
  /** @format uint256 */
@@ -372,6 +410,8 @@ export interface BuildSweepAddressTransactions {
372
410
  targetBlockHash?: string;
373
411
  /** @format int32 */
374
412
  utxosLimit?: number;
413
+ /** @format group-index */
414
+ group?: number;
375
415
  }
376
416
  /** BuildSweepAddressTransactionsResult */
377
417
  export interface BuildSweepAddressTransactionsResult {
@@ -386,6 +426,8 @@ export interface BuildSweepMultisig {
386
426
  /** @format address */
387
427
  fromAddress: string;
388
428
  fromPublicKeys: string[];
429
+ fromPublicKeyTypes?: string[];
430
+ fromPublicKeyIndexes?: number[];
389
431
  /** @format address */
390
432
  toAddress: string;
391
433
  /** @format uint256 */
@@ -400,6 +442,9 @@ export interface BuildSweepMultisig {
400
442
  utxosLimit?: number;
401
443
  /** @format block-hash */
402
444
  targetBlockHash?: string;
445
+ /** @format group-index */
446
+ group?: number;
447
+ multiSigType?: 'P2HMPK' | 'P2MPKH';
403
448
  }
404
449
  /** BuildTransferTx */
405
450
  export interface BuildTransferTx {
@@ -551,6 +596,7 @@ export interface CompilerOptions {
551
596
  ignoreCheckExternalCallerWarnings?: boolean;
552
597
  ignoreUnusedFunctionReturnWarnings?: boolean;
553
598
  skipAbstractContractCheck?: boolean;
599
+ skipTests?: boolean;
554
600
  }
555
601
  /** Confirmed */
556
602
  export interface Confirmed {
@@ -914,6 +960,8 @@ export interface RichAssetInput {
914
960
  /** @format address */
915
961
  address: string;
916
962
  tokens: Token[];
963
+ /** @format 32-byte-hash */
964
+ outputRefTxId: string;
917
965
  }
918
966
  /** RichBlockAndEvents */
919
967
  export interface RichBlockAndEvents {
@@ -960,6 +1008,8 @@ export interface RichContractInput {
960
1008
  /** @format address */
961
1009
  address: string;
962
1010
  tokens: Token[];
1011
+ /** @format 32-byte-hash */
1012
+ outputRefTxId: string;
963
1013
  }
964
1014
  /** RichTransaction */
965
1015
  export interface RichTransaction {
@@ -1115,6 +1165,7 @@ export interface TestContract {
1115
1165
  args?: Val[];
1116
1166
  existingContracts?: ContractState[];
1117
1167
  inputAssets?: TestInputAsset[];
1168
+ /** @format uint256 */
1118
1169
  dustAmount?: string;
1119
1170
  }
1120
1171
  /** TestContractResult */
@@ -1376,7 +1427,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
1376
1427
  }
1377
1428
  /**
1378
1429
  * @title Alephium API
1379
- * @version 3.12.2
1430
+ * @version 4.0.0
1380
1431
  * @baseUrl ../
1381
1432
  */
1382
1433
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -2212,7 +2263,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
2212
2263
  * @summary Build a multisig unsigned transaction
2213
2264
  * @request POST:/multisig/build
2214
2265
  */
2215
- postMultisigBuild: (data: BuildMultisig, params?: RequestParams) => Promise<BuildSimpleTransferTxResult>;
2266
+ postMultisigBuild: (data: BuildMultisig, params?: RequestParams) => Promise<BuildSimpleTransferTxResult | BuildGrouplessTransferTxResult>;
2216
2267
  /**
2217
2268
  * No description
2218
2269
  *
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 3.12.2
154
+ * @version 4.0.0
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -18,7 +18,7 @@ export declare function toApiNumber256(v: Val): string;
18
18
  export declare function toApiNumber256Optional(v?: Val): string | undefined;
19
19
  export declare function fromApiNumber256(n: string): bigint;
20
20
  export declare function toApiByteVec(v: Val): string;
21
- export declare function toApiAddress(v0: Val): string;
21
+ export declare function toApiAddress(v: Val): string;
22
22
  export declare function toApiArray(tpe: string, v: Val): node.Val;
23
23
  export declare function toApiVal(v: Val, tpe: string): node.Val;
24
24
  export declare function fromApiPrimitiveVal(value: node.Val, tpe: string, systemEvent?: boolean): Val;
@@ -18,7 +18,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.StdInterfaceIds = exports.request = exports.requestWithLog = exports.forwardRequests = exports.getDefaultPrimitiveValue = exports.decodeArrayType = exports.fromApiPrimitiveVal = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = exports.PrimitiveTypes = void 0;
21
- const address_1 = require("../address");
22
21
  const constants_1 = require("../constants");
23
22
  const debug_1 = require("../debug");
24
23
  const error_1 = require("../error");
@@ -92,19 +91,15 @@ function toApiByteVec(v) {
92
91
  throw new Error(`Invalid hex-string: ${v}`);
93
92
  }
94
93
  exports.toApiByteVec = toApiByteVec;
95
- function toApiAddress(v0) {
96
- if (typeof v0 === 'string') {
97
- let v = v0;
98
- if ((0, address_1.hasExplicitGroupIndex)(v)) {
99
- v = v.slice(0, -2);
100
- }
94
+ function toApiAddress(v) {
95
+ if (typeof v === 'string') {
101
96
  if ((0, utils_1.isBase58)(v)) {
102
- return v0;
97
+ return v;
103
98
  }
104
- throw new Error(`Invalid base58 string: ${v0}`);
99
+ throw new Error(`Invalid base58 string: ${v}`);
105
100
  }
106
101
  else {
107
- throw new Error(`Invalid value: ${v0}, expected a base58 string`);
102
+ throw new Error(`Invalid value: ${v}, expected a base58 string`);
108
103
  }
109
104
  }
110
105
  exports.toApiAddress = toApiAddress;
@@ -0,0 +1,8 @@
1
+ import { Reader } from './reader';
2
+ import { Codec } from './codec';
3
+ export declare class Checksum<T> extends Codec<T> {
4
+ private rawCodec;
5
+ constructor(rawCodec: Codec<T>);
6
+ encode(value: T): Uint8Array;
7
+ _decode(input: Reader): T;
8
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Checksum = void 0;
24
+ const utils_1 = require("../utils");
25
+ const djb2_1 = __importDefault(require("../utils/djb2"));
26
+ const int_as_4bytes_codec_1 = require("./int-as-4bytes-codec");
27
+ const codec_1 = require("./codec");
28
+ class Checksum extends codec_1.Codec {
29
+ constructor(rawCodec) {
30
+ super();
31
+ this.rawCodec = rawCodec;
32
+ }
33
+ encode(value) {
34
+ const rawEncoded = this.rawCodec.encode(value);
35
+ const checksum = int_as_4bytes_codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(rawEncoded));
36
+ return (0, utils_1.concatBytes)([rawEncoded, checksum]);
37
+ }
38
+ _decode(input) {
39
+ const fromIndex = input.getIndex();
40
+ const rawDecoded = this.rawCodec._decode(input);
41
+ const toIndex = input.getIndex();
42
+ const checksum = int_as_4bytes_codec_1.intAs4BytesCodec._decode(input);
43
+ const expected = (0, djb2_1.default)(input.getBytes(fromIndex, toIndex));
44
+ if (expected != checksum) {
45
+ throw new Error(`Invalid checksum: expected ${expected}, but got ${checksum}`);
46
+ }
47
+ return rawDecoded;
48
+ }
49
+ }
50
+ exports.Checksum = Checksum;
@@ -180,19 +180,19 @@ export type Instr = {
180
180
  name: 'U256ModMul';
181
181
  code: 0x37;
182
182
  } | {
183
- name: 'NumericBitAnd';
183
+ name: 'U256BitAnd';
184
184
  code: 0x38;
185
185
  } | {
186
- name: 'NumericBitOr';
186
+ name: 'U256BitOr';
187
187
  code: 0x39;
188
188
  } | {
189
- name: 'NumericXor';
189
+ name: 'U256Xor';
190
190
  code: 0x3a;
191
191
  } | {
192
- name: 'NumericSHL';
192
+ name: 'U256SHL';
193
193
  code: 0x3b;
194
194
  } | {
195
- name: 'NumericSHR';
195
+ name: 'U256SHR';
196
196
  code: 0x3c;
197
197
  } | {
198
198
  name: 'I256ToU256';
@@ -438,12 +438,6 @@ export type Instr = {
438
438
  } | {
439
439
  name: 'GroupOfAddress';
440
440
  code: 0x8c;
441
- } | {
442
- name: 'VerifySignature';
443
- code: 0x8d;
444
- } | {
445
- name: 'GetSegregatedWebAuthnSignature';
446
- code: 0x8e;
447
441
  } | {
448
442
  name: 'LoadMutField';
449
443
  code: 0xa0;
@@ -610,12 +604,6 @@ export type Instr = {
610
604
  name: 'CallExternalBySelector';
611
605
  code: 0xd4;
612
606
  selector: number;
613
- } | {
614
- name: 'ExternalCallerContractId';
615
- code: 0xd5;
616
- } | {
617
- name: 'ExternalCallerAddress';
618
- code: 0xd6;
619
607
  };
620
608
  export declare const CallLocalCode = 0;
621
609
  export declare const CallExternalCode = 1;
@@ -691,11 +679,11 @@ export declare const U256Ge: Instr;
691
679
  export declare const U256ModAdd: Instr;
692
680
  export declare const U256ModSub: Instr;
693
681
  export declare const U256ModMul: Instr;
694
- export declare const NumericBitAnd: Instr;
695
- export declare const NumericBitOr: Instr;
696
- export declare const NumericXor: Instr;
697
- export declare const NumericSHL: Instr;
698
- export declare const NumericSHR: Instr;
682
+ export declare const U256BitAnd: Instr;
683
+ export declare const U256BitOr: Instr;
684
+ export declare const U256Xor: Instr;
685
+ export declare const U256SHL: Instr;
686
+ export declare const U256SHR: Instr;
699
687
  export declare const I256ToU256: Instr;
700
688
  export declare const I256ToByteVec: Instr;
701
689
  export declare const U256ToI256: Instr;
@@ -776,8 +764,6 @@ export declare const U256ToString: Instr;
776
764
  export declare const I256ToString: Instr;
777
765
  export declare const BoolToString: Instr;
778
766
  export declare const GroupOfAddress: Instr;
779
- export declare const VerifySignature: Instr;
780
- export declare const GetSegregatedWebAuthnSignature: Instr;
781
767
  export declare const LoadMutField: (index: number) => Instr;
782
768
  export declare const StoreMutField: (index: number) => Instr;
783
769
  export declare const ApproveAlph: Instr;
@@ -831,8 +817,6 @@ export declare const MinimalContractDeposit: Instr;
831
817
  export declare const CreateMapEntry: (immFieldsNum: number, mutFieldsNum: number) => Instr;
832
818
  export declare const MethodSelector: (selector: number) => Instr;
833
819
  export declare const CallExternalBySelector: (selector: number) => Instr;
834
- export declare const ExternalCallerContractId: Instr;
835
- export declare const ExternalCallerAddress: Instr;
836
820
  export declare class InstrCodec extends Codec<Instr> {
837
821
  encode(instr: Instr): Uint8Array;
838
822
  _decode(input: Reader): Instr;