@alephium/web3 1.12.0-beta.0 → 1.12.0-danube.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.
@@ -77,45 +77,38 @@ function decodeAndValidateAddress(address: string): Uint8Array {
77
77
  } else if (addressType === AddressType.P2PKH || addressType === AddressType.P2SH || addressType === AddressType.P2C) {
78
78
  // [type, ...hash]
79
79
  if (decoded.length === 33) return decoded
80
- } else if (isGrouplessAddressWithGroup(decoded)) {
81
- // [type, keyType, ...publicKey, ...checkSum, ...groupByte]
82
- const publicKeyToIndex = decoded.length - 1 - 4
83
- const publicKeyLikeBytes = decoded.slice(1, publicKeyToIndex)
84
- const checksum = binToHex(decoded.slice(publicKeyToIndex, publicKeyToIndex + 4))
85
- const expectedChecksum = binToHex(intAs4BytesCodec.encode(djb2(publicKeyLikeBytes)))
86
- if (checksum !== expectedChecksum) {
87
- throw new Error(`Invalid checksum for P2PK address: ${address}`)
80
+ } else if (addressType === AddressType.P2PK) {
81
+ if (decoded.length === 40) {
82
+ // [type, keyType, ...publicKey, ...checkSum, ...groupByte]
83
+ const publicKeyLikeBytes = decoded.slice(1, 35)
84
+ const checksum = binToHex(decoded.slice(35, 39))
85
+ const expectedChecksum = binToHex(intAs4BytesCodec.encode(djb2(publicKeyLikeBytes)))
86
+ if (checksum !== expectedChecksum) {
87
+ throw new Error(`Invalid checksum for P2PK address: ${address}`)
88
+ }
89
+ const group = byteCodec.decode(decoded.slice(39, 40))
90
+ validateGroupIndex(group)
91
+
92
+ return decoded
88
93
  }
89
- const group = byteCodec.decode(decoded.slice(decoded.length - 1, decoded.length))
90
- validateGroupIndex(group)
91
-
92
- return decoded
93
94
  }
94
95
 
95
96
  throw new Error(`Invalid address: ${address}`)
96
97
  }
97
98
 
98
- function isGrouplessAddressWithoutGroup(decoded: Uint8Array): boolean {
99
- return decoded[0] === AddressType.P2PK && (decoded.length === 38 || decoded.length === 39)
100
- }
101
-
102
- function isGrouplessAddressWithGroup(decoded: Uint8Array): boolean {
103
- return decoded[0] === AddressType.P2PK && (decoded.length === 39 || decoded.length === 40)
104
- }
105
-
106
99
  export function addressToBytes(address: string): Uint8Array {
107
100
  if (hasExplicitGroupIndex(address)) {
108
101
  const groupIndex = parseGroupIndex(address[address.length - 1])
109
102
  const decoded = base58ToBytes(address.slice(0, address.length - 2))
110
- if (isGrouplessAddressWithoutGroup(decoded)) {
103
+ if (decoded[0] === 0x04 && decoded.length === 39) {
111
104
  const groupByte = byteCodec.encode(groupIndex)
112
105
  return new Uint8Array([...decoded, ...groupByte])
113
106
  }
114
107
  throw new Error(`Invalid groupless address: ${address}`)
115
108
  } else {
116
109
  const decoded = base58ToBytes(address)
117
- if (isGrouplessAddressWithoutGroup(decoded)) {
118
- const group = defaultGroupOfGrouplessAddress(decoded.slice(2, decoded.length - 4))
110
+ if (decoded[0] === 0x04 && decoded.length === 39) {
111
+ const group = defaultGroupOfGrouplessAddress(decoded.slice(2, 35))
119
112
  const groupByte = byteCodec.encode(group)
120
113
  return new Uint8Array([...decoded, ...groupByte])
121
114
  }
@@ -222,7 +215,7 @@ export function groupOfPrivateKey(privateKey: string, keyType?: KeyType): number
222
215
  export function publicKeyFromPrivateKey(privateKey: string, _keyType?: KeyType): string {
223
216
  const keyType = _keyType ?? 'default'
224
217
 
225
- if (keyType === 'default' || keyType === 'groupless') {
218
+ if (keyType === 'default' || keyType === 'gl-secp256k1') {
226
219
  const key = ec.keyFromPrivate(privateKey)
227
220
  return key.getPublic(true, 'hex')
228
221
  } else {
@@ -237,7 +230,7 @@ export function addressFromPublicKey(publicKey: string, _keyType?: KeyType): str
237
230
  const hash = blake.blake2b(hexToBinUnsafe(publicKey), undefined, 32)
238
231
  const bytes = new Uint8Array([AddressType.P2PKH, ...hash])
239
232
  return bs58.encode(bytes)
240
- } else if (keyType === 'groupless') {
233
+ } else if (keyType === 'gl-secp256k1') {
241
234
  const publicKeyBytes = new Uint8Array([0x00, ...hexToBinUnsafe(publicKey)])
242
235
  const hashBytes = intAs4BytesCodec.encode(djb2(publicKeyBytes))
243
236
  const bytes = new Uint8Array([0x04, ...publicKeyBytes, ...hashBytes])
@@ -319,6 +312,13 @@ export function hasExplicitGroupIndex(address: string): boolean {
319
312
  return address.length > 2 && address[address.length - 2] === ':'
320
313
  }
321
314
 
315
+ export function addressWithoutExplicitGroupIndex(address: string): string {
316
+ if (hasExplicitGroupIndex(address)) {
317
+ return address.slice(0, address.length - 2)
318
+ }
319
+ return address
320
+ }
321
+
322
322
  export function addressFromLockupScript(lockupScript: LockupScript): string {
323
323
  if (lockupScript.kind === 'P2PK') {
324
324
  const groupByte = lockupScriptCodec.encode(lockupScript).slice(-1)
@@ -206,7 +206,7 @@ export interface BuildChainedDeployContractTx {
206
206
 
207
207
  /** BuildChainedDeployContractTxResult */
208
208
  export interface BuildChainedDeployContractTxResult {
209
- value: BuildDeployContractTxResult
209
+ value: BuildSimpleDeployContractTxResult
210
210
  type: string
211
211
  }
212
212
 
@@ -218,7 +218,7 @@ export interface BuildChainedExecuteScriptTx {
218
218
 
219
219
  /** BuildChainedExecuteScriptTxResult */
220
220
  export interface BuildChainedExecuteScriptTxResult {
221
- value: BuildExecuteScriptTxResult
221
+ value: BuildSimpleExecuteScriptTxResult
222
222
  type: string
223
223
  }
224
224
 
@@ -230,7 +230,7 @@ export interface BuildChainedTransferTx {
230
230
 
231
231
  /** BuildChainedTransferTxResult */
232
232
  export interface BuildChainedTransferTxResult {
233
- value: BuildTransferTxResult
233
+ value: BuildSimpleTransferTxResult
234
234
  type: string
235
235
  }
236
236
 
@@ -262,26 +262,14 @@ export interface BuildDeployContractTx {
262
262
  gasAmount?: number
263
263
  /** @format uint256 */
264
264
  gasPrice?: string
265
+ /** @format group-index */
266
+ group?: number
265
267
  /** @format block-hash */
266
268
  targetBlockHash?: string
267
269
  }
268
270
 
269
271
  /** BuildDeployContractTxResult */
270
- export interface BuildDeployContractTxResult {
271
- /** @format int32 */
272
- fromGroup: number
273
- /** @format int32 */
274
- toGroup: number
275
- unsignedTx: string
276
- /** @format gas */
277
- gasAmount: number
278
- /** @format uint256 */
279
- gasPrice: string
280
- /** @format 32-byte-hash */
281
- txId: string
282
- /** @format address */
283
- contractAddress: string
284
- }
272
+ export type BuildDeployContractTxResult = BuildGrouplessDeployContractTxResult | BuildSimpleDeployContractTxResult
285
273
 
286
274
  /** BuildExecuteScriptTx */
287
275
  export interface BuildExecuteScriptTx {
@@ -300,80 +288,34 @@ export interface BuildExecuteScriptTx {
300
288
  gasPrice?: string
301
289
  /** @format block-hash */
302
290
  targetBlockHash?: string
291
+ /** @format group-index */
292
+ group?: number
303
293
  /** @format double */
304
294
  gasEstimationMultiplier?: number
305
295
  }
306
296
 
307
297
  /** BuildExecuteScriptTxResult */
308
- export interface BuildExecuteScriptTxResult {
309
- /** @format int32 */
310
- fromGroup: number
311
- /** @format int32 */
312
- toGroup: number
313
- unsignedTx: string
314
- /** @format gas */
315
- gasAmount: number
316
- /** @format uint256 */
317
- gasPrice: string
318
- /** @format 32-byte-hash */
319
- txId: string
320
- simulationResult: SimulationResult
321
- }
322
-
323
- /** BuildGrouplessDeployContractTx */
324
- export interface BuildGrouplessDeployContractTx {
325
- fromAddress: string
326
- /** @format hex-string */
327
- bytecode: string
328
- /** @format uint256 */
329
- initialAttoAlphAmount?: string
330
- initialTokenAmounts?: Token[]
331
- /** @format uint256 */
332
- issueTokenAmount?: string
333
- /** @format address */
334
- issueTokenTo?: string
335
- /** @format uint256 */
336
- gasPrice?: string
337
- /** @format block-hash */
338
- targetBlockHash?: string
339
- }
298
+ export type BuildExecuteScriptTxResult = BuildGrouplessExecuteScriptTxResult | BuildSimpleExecuteScriptTxResult
340
299
 
341
300
  /** BuildGrouplessDeployContractTxResult */
342
301
  export interface BuildGrouplessDeployContractTxResult {
343
- transferTxs: BuildTransferTxResult[]
344
- deployContractTx: BuildDeployContractTxResult
345
- }
346
-
347
- /** BuildGrouplessExecuteScriptTx */
348
- export interface BuildGrouplessExecuteScriptTx {
349
- fromAddress: string
350
- /** @format hex-string */
351
- bytecode: string
352
- /** @format uint256 */
353
- attoAlphAmount?: string
354
- tokens?: Token[]
355
- /** @format uint256 */
356
- gasPrice?: string
357
- /** @format block-hash */
358
- targetBlockHash?: string
359
- /** @format double */
360
- gasEstimationMultiplier?: number
302
+ transferTxs: BuildSimpleTransferTxResult[]
303
+ deployContractTx: BuildSimpleDeployContractTxResult
304
+ type: string
361
305
  }
362
306
 
363
307
  /** BuildGrouplessExecuteScriptTxResult */
364
308
  export interface BuildGrouplessExecuteScriptTxResult {
365
- transferTxs: BuildTransferTxResult[]
366
- executeScriptTx: BuildExecuteScriptTxResult
309
+ transferTxs: BuildSimpleTransferTxResult[]
310
+ executeScriptTx: BuildSimpleExecuteScriptTxResult
311
+ type: string
367
312
  }
368
313
 
369
- /** BuildGrouplessTransferTx */
370
- export interface BuildGrouplessTransferTx {
371
- fromAddress: string
372
- destinations: Destination[]
373
- /** @format uint256 */
374
- gasPrice?: string
375
- /** @format block-hash */
376
- targetBlockHash?: string
314
+ /** BuildGrouplessTransferTxResult */
315
+ export interface BuildGrouplessTransferTxResult {
316
+ transferTxs: BuildSimpleTransferTxResult[]
317
+ transferTx: BuildSimpleTransferTxResult
318
+ type: string
377
319
  }
378
320
 
379
321
  /** BuildInfo */
@@ -416,6 +358,57 @@ export interface BuildMultisigAddressResult {
416
358
  address: string
417
359
  }
418
360
 
361
+ /** BuildSimpleDeployContractTxResult */
362
+ export interface BuildSimpleDeployContractTxResult {
363
+ /** @format int32 */
364
+ fromGroup: number
365
+ /** @format int32 */
366
+ toGroup: number
367
+ unsignedTx: string
368
+ /** @format gas */
369
+ gasAmount: number
370
+ /** @format uint256 */
371
+ gasPrice: string
372
+ /** @format 32-byte-hash */
373
+ txId: string
374
+ /** @format address */
375
+ contractAddress: string
376
+ type: string
377
+ }
378
+
379
+ /** BuildSimpleExecuteScriptTxResult */
380
+ export interface BuildSimpleExecuteScriptTxResult {
381
+ /** @format int32 */
382
+ fromGroup: number
383
+ /** @format int32 */
384
+ toGroup: number
385
+ unsignedTx: string
386
+ /** @format gas */
387
+ gasAmount: number
388
+ /** @format uint256 */
389
+ gasPrice: string
390
+ /** @format 32-byte-hash */
391
+ txId: string
392
+ simulationResult: SimulationResult
393
+ type: string
394
+ }
395
+
396
+ /** BuildSimpleTransferTxResult */
397
+ export interface BuildSimpleTransferTxResult {
398
+ unsignedTx: string
399
+ /** @format gas */
400
+ gasAmount: number
401
+ /** @format uint256 */
402
+ gasPrice: string
403
+ /** @format 32-byte-hash */
404
+ txId: string
405
+ /** @format int32 */
406
+ fromGroup: number
407
+ /** @format int32 */
408
+ toGroup: number
409
+ type: string
410
+ }
411
+
419
412
  /** BuildSweepAddressTransactions */
420
413
  export interface BuildSweepAddressTransactions {
421
414
  /** @format public-key */
@@ -478,24 +471,14 @@ export interface BuildTransferTx {
478
471
  gasAmount?: number
479
472
  /** @format uint256 */
480
473
  gasPrice?: string
474
+ /** @format group-index */
475
+ group?: number
481
476
  /** @format block-hash */
482
477
  targetBlockHash?: string
483
478
  }
484
479
 
485
480
  /** BuildTransferTxResult */
486
- export interface BuildTransferTxResult {
487
- unsignedTx: string
488
- /** @format gas */
489
- gasAmount: number
490
- /** @format uint256 */
491
- gasPrice: string
492
- /** @format 32-byte-hash */
493
- txId: string
494
- /** @format int32 */
495
- fromGroup: number
496
- /** @format int32 */
497
- toGroup: number
498
- }
481
+ export type BuildTransferTxResult = BuildGrouplessTransferTxResult | BuildSimpleTransferTxResult
499
482
 
500
483
  /** CallContract */
501
484
  export interface CallContract {
@@ -1281,6 +1264,7 @@ export interface TestContract {
1281
1264
  args?: Val[]
1282
1265
  existingContracts?: ContractState[]
1283
1266
  inputAssets?: TestInputAsset[]
1267
+ dustAmount?: string
1284
1268
  }
1285
1269
 
1286
1270
  /** TestContractResult */
@@ -1620,8 +1604,8 @@ export class HttpClient<SecurityDataType = unknown> {
1620
1604
  property instanceof Blob
1621
1605
  ? property
1622
1606
  : typeof property === 'object' && property !== null
1623
- ? JSON.stringify(property)
1624
- : `${property}`
1607
+ ? JSON.stringify(property)
1608
+ : `${property}`
1625
1609
  )
1626
1610
  return formData
1627
1611
  }, new FormData()),
@@ -1701,18 +1685,18 @@ export class HttpClient<SecurityDataType = unknown> {
1701
1685
  const data = !responseFormat
1702
1686
  ? r
1703
1687
  : await response[responseFormat]()
1704
- .then((data) => {
1705
- if (r.ok) {
1706
- r.data = data
1707
- } else {
1708
- r.error = data
1709
- }
1710
- return r
1711
- })
1712
- .catch((e) => {
1713
- r.error = e
1714
- return r
1715
- })
1688
+ .then((data) => {
1689
+ if (r.ok) {
1690
+ r.data = data
1691
+ } else {
1692
+ r.error = data
1693
+ }
1694
+ return r
1695
+ })
1696
+ .catch((e) => {
1697
+ r.error = e
1698
+ return r
1699
+ })
1716
1700
 
1717
1701
  if (cancelToken) {
1718
1702
  this.abortControllers.delete(cancelToken)
@@ -2797,7 +2781,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2797
2781
  */
2798
2782
  postTransactionsBuildTransferFromOneToManyGroups: (data: BuildTransferTx, params: RequestParams = {}) =>
2799
2783
  this.request<
2800
- BuildTransferTxResult[],
2784
+ BuildSimpleTransferTxResult[],
2801
2785
  BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
2802
2786
  >({
2803
2787
  path: `/transactions/build-transfer-from-one-to-many-groups`,
@@ -2818,7 +2802,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2818
2802
  */
2819
2803
  postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params: RequestParams = {}) =>
2820
2804
  this.request<
2821
- BuildTransferTxResult,
2805
+ BuildSimpleTransferTxResult,
2822
2806
  BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
2823
2807
  >({
2824
2808
  path: `/transactions/build-multi-addresses`,
@@ -3466,7 +3450,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
3466
3450
  */
3467
3451
  postMultisigBuild: (data: BuildMultisig, params: RequestParams = {}) =>
3468
3452
  this.request<
3469
- BuildTransferTxResult,
3453
+ BuildSimpleTransferTxResult,
3470
3454
  BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
3471
3455
  >({
3472
3456
  path: `/multisig/build`,
@@ -3778,68 +3762,4 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
3778
3762
  ...params
3779
3763
  }).then(convertHttpResponse)
3780
3764
  }
3781
- groupless = {
3782
- /**
3783
- * No description
3784
- *
3785
- * @tags Groupless
3786
- * @name PostGrouplessTransfer
3787
- * @summary Build unsigned transfer transactions from a groupless address
3788
- * @request POST:/groupless/transfer
3789
- */
3790
- postGrouplessTransfer: (data: BuildGrouplessTransferTx, params: RequestParams = {}) =>
3791
- this.request<
3792
- BuildTransferTxResult[],
3793
- BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
3794
- >({
3795
- path: `/groupless/transfer`,
3796
- method: 'POST',
3797
- body: data,
3798
- type: ContentType.Json,
3799
- format: 'json',
3800
- ...params
3801
- }).then(convertHttpResponse),
3802
-
3803
- /**
3804
- * No description
3805
- *
3806
- * @tags Groupless
3807
- * @name PostGrouplessExecuteScript
3808
- * @summary Build an unsigned execute script transaction from a groupless address
3809
- * @request POST:/groupless/execute-script
3810
- */
3811
- postGrouplessExecuteScript: (data: BuildGrouplessExecuteScriptTx, params: RequestParams = {}) =>
3812
- this.request<
3813
- BuildGrouplessExecuteScriptTxResult,
3814
- BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
3815
- >({
3816
- path: `/groupless/execute-script`,
3817
- method: 'POST',
3818
- body: data,
3819
- type: ContentType.Json,
3820
- format: 'json',
3821
- ...params
3822
- }).then(convertHttpResponse),
3823
-
3824
- /**
3825
- * No description
3826
- *
3827
- * @tags Groupless
3828
- * @name PostGrouplessDeployContract
3829
- * @summary Build an unsigned deploy contract transaction from a groupless address
3830
- * @request POST:/groupless/deploy-contract
3831
- */
3832
- postGrouplessDeployContract: (data: BuildGrouplessDeployContractTx, params: RequestParams = {}) =>
3833
- this.request<
3834
- BuildGrouplessDeployContractTxResult,
3835
- BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable | GatewayTimeout
3836
- >({
3837
- path: `/groupless/deploy-contract`,
3838
- method: 'POST',
3839
- body: data,
3840
- type: ContentType.Json,
3841
- format: 'json',
3842
- ...params
3843
- }).then(convertHttpResponse)
3844
- }
3845
3765
  }
@@ -55,7 +55,6 @@ interface NodeProviderApis {
55
55
  utils: NodeApi<string>['utils']
56
56
  miners: NodeApi<string>['miners']
57
57
  events: NodeApi<string>['events']
58
- groupless: NodeApi<string>['groupless']
59
58
  }
60
59
 
61
60
  export class NodeProvider implements NodeProviderApis {
@@ -70,7 +69,6 @@ export class NodeProvider implements NodeProviderApis {
70
69
  readonly utils: NodeApi<string>['utils']
71
70
  readonly miners: NodeApi<string>['miners']
72
71
  readonly events: NodeApi<string>['events']
73
- readonly groupless: NodeApi<string>['groupless']
74
72
 
75
73
  constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch)
76
74
  constructor(provider: NodeProvider)
@@ -97,7 +95,6 @@ export class NodeProvider implements NodeProviderApis {
97
95
  this.utils = { ...nodeApi.utils }
98
96
  this.miners = { ...nodeApi.miners }
99
97
  this.events = { ...nodeApi.events }
100
- this.groupless = { ...nodeApi.groupless }
101
98
  requestWithLog(this)
102
99
  }
103
100