@algorandfoundation/algokit-utils 10.0.0-alpha.37 → 10.0.0-alpha.38
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/_virtual/_rolldown/runtime.js +0 -2
- package/algorand-client-transaction-creator.d.ts +6 -6
- package/algorand-client-transaction-sender.d.ts +6 -6
- package/app-client.d.ts +20 -20
- package/app-factory.d.ts +47 -47
- package/package.json +3 -1
- package/packages/abi/src/abi-method.js +3 -2
- package/packages/abi/src/abi-method.js.map +1 -1
- package/packages/abi/src/abi-method.mjs +1 -1
- package/packages/common/src/address.js +3 -3
- package/packages/common/src/address.js.map +1 -1
- package/packages/common/src/address.mjs +1 -1
- package/packages/crypto/src/ed25519.js +9 -7
- package/packages/crypto/src/ed25519.js.map +1 -1
- package/packages/crypto/src/ed25519.mjs +7 -7
- package/packages/crypto/src/ed25519.mjs.map +1 -1
- package/packages/crypto/src/hash.js +3 -2
- package/packages/crypto/src/hash.js.map +1 -1
- package/packages/crypto/src/hash.mjs +1 -1
- package/packages/crypto/src/hd.js +12 -12
- package/packages/crypto/src/hd.js.map +1 -1
- package/packages/crypto/src/hd.mjs +1 -2
- package/packages/crypto/src/hd.mjs.map +1 -1
- package/_virtual/_rolldown/runtime.mjs +0 -33
|
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
8
|
var __copyProps = (to, from, except, desc) => {
|
|
10
9
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
10
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -27,5 +26,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
26
|
|
|
28
27
|
//#endregion
|
|
29
28
|
|
|
30
|
-
exports.__commonJSMin = __commonJSMin;
|
|
31
29
|
exports.__toESM = __toESM;
|
|
@@ -348,8 +348,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
348
348
|
* @returns The application create transaction
|
|
349
349
|
*/
|
|
350
350
|
appCreate: (params: {
|
|
351
|
-
sender: SendingAddress;
|
|
352
351
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
352
|
+
sender: SendingAddress;
|
|
353
353
|
rekeyTo?: ReadableAddress | undefined;
|
|
354
354
|
note?: (Uint8Array | string) | undefined;
|
|
355
355
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -359,8 +359,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
359
359
|
validityWindow?: number | bigint | undefined;
|
|
360
360
|
firstValidRound?: bigint | undefined;
|
|
361
361
|
lastValidRound?: bigint | undefined;
|
|
362
|
-
args?: Uint8Array[] | undefined;
|
|
363
362
|
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
363
|
+
args?: Uint8Array[] | undefined;
|
|
364
364
|
accountReferences?: ReadableAddress[] | undefined;
|
|
365
365
|
appReferences?: bigint[] | undefined;
|
|
366
366
|
assetReferences?: bigint[] | undefined;
|
|
@@ -569,8 +569,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
569
569
|
*/
|
|
570
570
|
appCreateMethodCall: (params: {
|
|
571
571
|
appId?: 0 | undefined;
|
|
572
|
-
sender: SendingAddress;
|
|
573
572
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
573
|
+
sender: SendingAddress;
|
|
574
574
|
rekeyTo?: ReadableAddress | undefined;
|
|
575
575
|
note?: (Uint8Array | string) | undefined;
|
|
576
576
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -650,8 +650,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
650
650
|
*/
|
|
651
651
|
appUpdateMethodCall: (params: {
|
|
652
652
|
appId: bigint;
|
|
653
|
-
sender: SendingAddress;
|
|
654
653
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
654
|
+
sender: SendingAddress;
|
|
655
655
|
rekeyTo?: ReadableAddress | undefined;
|
|
656
656
|
note?: (Uint8Array | string) | undefined;
|
|
657
657
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -722,8 +722,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
722
722
|
*/
|
|
723
723
|
appDeleteMethodCall: (params: {
|
|
724
724
|
appId: bigint;
|
|
725
|
-
sender: SendingAddress;
|
|
726
725
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
726
|
+
sender: SendingAddress;
|
|
727
727
|
rekeyTo?: ReadableAddress | undefined;
|
|
728
728
|
note?: (Uint8Array | string) | undefined;
|
|
729
729
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -792,8 +792,8 @@ declare class AlgorandClientTransactionCreator {
|
|
|
792
792
|
*/
|
|
793
793
|
appCallMethodCall: (params: {
|
|
794
794
|
appId: bigint;
|
|
795
|
-
sender: SendingAddress;
|
|
796
795
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
796
|
+
sender: SendingAddress;
|
|
797
797
|
rekeyTo?: ReadableAddress | undefined;
|
|
798
798
|
note?: (Uint8Array | string) | undefined;
|
|
799
799
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -473,8 +473,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
473
473
|
* @returns The result of the app create transaction and the transaction that was sent
|
|
474
474
|
*/
|
|
475
475
|
appCreate: (params: {
|
|
476
|
-
sender: SendingAddress;
|
|
477
476
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
477
|
+
sender: SendingAddress;
|
|
478
478
|
rekeyTo?: ReadableAddress | undefined;
|
|
479
479
|
note?: (Uint8Array | string) | undefined;
|
|
480
480
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -484,8 +484,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
484
484
|
validityWindow?: number | bigint | undefined;
|
|
485
485
|
firstValidRound?: bigint | undefined;
|
|
486
486
|
lastValidRound?: bigint | undefined;
|
|
487
|
-
args?: Uint8Array[] | undefined;
|
|
488
487
|
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
488
|
+
args?: Uint8Array[] | undefined;
|
|
489
489
|
accountReferences?: ReadableAddress[] | undefined;
|
|
490
490
|
appReferences?: bigint[] | undefined;
|
|
491
491
|
assetReferences?: bigint[] | undefined;
|
|
@@ -747,8 +747,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
747
747
|
*/
|
|
748
748
|
appCreateMethodCall: (params: {
|
|
749
749
|
appId?: 0 | undefined;
|
|
750
|
-
sender: SendingAddress;
|
|
751
750
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
751
|
+
sender: SendingAddress;
|
|
752
752
|
rekeyTo?: ReadableAddress | undefined;
|
|
753
753
|
note?: (Uint8Array | string) | undefined;
|
|
754
754
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -835,8 +835,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
835
835
|
*/
|
|
836
836
|
appUpdateMethodCall: (params: {
|
|
837
837
|
appId: bigint;
|
|
838
|
-
sender: SendingAddress;
|
|
839
838
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
839
|
+
sender: SendingAddress;
|
|
840
840
|
rekeyTo?: ReadableAddress | undefined;
|
|
841
841
|
note?: (Uint8Array | string) | undefined;
|
|
842
842
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -914,8 +914,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
914
914
|
*/
|
|
915
915
|
appDeleteMethodCall: (params: {
|
|
916
916
|
appId: bigint;
|
|
917
|
-
sender: SendingAddress;
|
|
918
917
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
918
|
+
sender: SendingAddress;
|
|
919
919
|
rekeyTo?: ReadableAddress | undefined;
|
|
920
920
|
note?: (Uint8Array | string) | undefined;
|
|
921
921
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -991,8 +991,8 @@ declare class AlgorandClientTransactionSender {
|
|
|
991
991
|
*/
|
|
992
992
|
appCallMethodCall: (params: {
|
|
993
993
|
appId: bigint;
|
|
994
|
-
sender: SendingAddress;
|
|
995
994
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
995
|
+
sender: SendingAddress;
|
|
996
996
|
rekeyTo?: ReadableAddress | undefined;
|
|
997
997
|
note?: (Uint8Array | string) | undefined;
|
|
998
998
|
lease?: (Uint8Array | string) | undefined;
|
package/app-client.d.ts
CHANGED
|
@@ -458,9 +458,9 @@ declare class AppClient {
|
|
|
458
458
|
signer: AddressWithTransactionSigner | TransactionSigner | undefined;
|
|
459
459
|
method: ABIMethod;
|
|
460
460
|
onComplete: OnApplicationComplete.UpdateApplication;
|
|
461
|
-
args: (
|
|
462
|
-
sender: SendingAddress;
|
|
461
|
+
args: (Transaction | TransactionWithSigner | ABIValue | AppMethodCall<{
|
|
463
462
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
463
|
+
sender: SendingAddress;
|
|
464
464
|
rekeyTo?: ReadableAddress | undefined;
|
|
465
465
|
note?: (Uint8Array | string) | undefined;
|
|
466
466
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -470,8 +470,7 @@ declare class AppClient {
|
|
|
470
470
|
validityWindow?: number | bigint | undefined;
|
|
471
471
|
firstValidRound?: bigint | undefined;
|
|
472
472
|
lastValidRound?: bigint | undefined;
|
|
473
|
-
|
|
474
|
-
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
473
|
+
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
475
474
|
args?: Uint8Array[] | undefined;
|
|
476
475
|
accountReferences?: ReadableAddress[] | undefined;
|
|
477
476
|
appReferences?: bigint[] | undefined;
|
|
@@ -479,9 +478,17 @@ declare class AppClient {
|
|
|
479
478
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
480
479
|
accessReferences?: ResourceReference[] | undefined;
|
|
481
480
|
rejectVersion?: number | undefined;
|
|
481
|
+
appId?: 0 | undefined;
|
|
482
482
|
approvalProgram: string | Uint8Array;
|
|
483
483
|
clearStateProgram: string | Uint8Array;
|
|
484
|
-
|
|
484
|
+
schema?: {
|
|
485
|
+
globalInts: number;
|
|
486
|
+
globalByteSlices: number;
|
|
487
|
+
localInts: number;
|
|
488
|
+
localByteSlices: number;
|
|
489
|
+
} | undefined;
|
|
490
|
+
extraProgramPages?: number | undefined;
|
|
491
|
+
}> | AppMethodCall<{
|
|
485
492
|
sender: SendingAddress;
|
|
486
493
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
487
494
|
rekeyTo?: ReadableAddress | undefined;
|
|
@@ -493,25 +500,18 @@ declare class AppClient {
|
|
|
493
500
|
validityWindow?: number | bigint | undefined;
|
|
494
501
|
firstValidRound?: bigint | undefined;
|
|
495
502
|
lastValidRound?: bigint | undefined;
|
|
503
|
+
appId: bigint;
|
|
504
|
+
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
496
505
|
args?: Uint8Array[] | undefined;
|
|
497
|
-
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
498
506
|
accountReferences?: ReadableAddress[] | undefined;
|
|
499
507
|
appReferences?: bigint[] | undefined;
|
|
500
508
|
assetReferences?: bigint[] | undefined;
|
|
501
509
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
502
510
|
accessReferences?: ResourceReference[] | undefined;
|
|
503
511
|
rejectVersion?: number | undefined;
|
|
504
|
-
appId?: 0 | undefined;
|
|
505
512
|
approvalProgram: string | Uint8Array;
|
|
506
513
|
clearStateProgram: string | Uint8Array;
|
|
507
|
-
|
|
508
|
-
globalInts: number;
|
|
509
|
-
globalByteSlices: number;
|
|
510
|
-
localInts: number;
|
|
511
|
-
localByteSlices: number;
|
|
512
|
-
} | undefined;
|
|
513
|
-
extraProgramPages?: number | undefined;
|
|
514
|
-
}> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
|
|
514
|
+
}> | AppMethodCall<AppMethodCallParams> | Promise<Transaction> | undefined)[] | undefined;
|
|
515
515
|
}>;
|
|
516
516
|
/**
|
|
517
517
|
* Return params for an opt-in ABI call
|
|
@@ -520,8 +520,8 @@ declare class AppClient {
|
|
|
520
520
|
*/
|
|
521
521
|
optIn: (params: AppClientMethodCallParams) => Promise<{
|
|
522
522
|
appId: bigint;
|
|
523
|
-
sender: SendingAddress;
|
|
524
523
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
524
|
+
sender: SendingAddress;
|
|
525
525
|
rekeyTo?: ReadableAddress | undefined;
|
|
526
526
|
note?: (Uint8Array | string) | undefined;
|
|
527
527
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -548,8 +548,8 @@ declare class AppClient {
|
|
|
548
548
|
*/
|
|
549
549
|
delete: (params: AppClientMethodCallParams) => Promise<{
|
|
550
550
|
appId: bigint;
|
|
551
|
-
sender: SendingAddress;
|
|
552
551
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
552
|
+
sender: SendingAddress;
|
|
553
553
|
rekeyTo?: ReadableAddress | undefined;
|
|
554
554
|
note?: (Uint8Array | string) | undefined;
|
|
555
555
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -575,8 +575,8 @@ declare class AppClient {
|
|
|
575
575
|
*/
|
|
576
576
|
closeOut: (params: AppClientMethodCallParams) => Promise<{
|
|
577
577
|
appId: bigint;
|
|
578
|
-
sender: SendingAddress;
|
|
579
578
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
579
|
+
sender: SendingAddress;
|
|
580
580
|
rekeyTo?: ReadableAddress | undefined;
|
|
581
581
|
note?: (Uint8Array | string) | undefined;
|
|
582
582
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -602,8 +602,8 @@ declare class AppClient {
|
|
|
602
602
|
*/
|
|
603
603
|
call: (params: AppClientMethodCallParams & CallOnComplete) => Promise<{
|
|
604
604
|
appId: bigint;
|
|
605
|
-
sender: SendingAddress;
|
|
606
605
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
606
|
+
sender: SendingAddress;
|
|
607
607
|
rekeyTo?: ReadableAddress | undefined;
|
|
608
608
|
note?: (Uint8Array | string) | undefined;
|
|
609
609
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -709,8 +709,8 @@ declare class AppClient {
|
|
|
709
709
|
update: (params: AppClientMethodCallParams & AppClientCompilationParams & SendParams) => Promise<{
|
|
710
710
|
compiledApproval?: CompiledTeal | undefined;
|
|
711
711
|
compiledClear?: CompiledTeal | undefined;
|
|
712
|
-
transactions: Transaction[];
|
|
713
712
|
confirmations: PendingTransactionResponse[];
|
|
713
|
+
transactions: Transaction[];
|
|
714
714
|
groupId: string | undefined;
|
|
715
715
|
txIds: string[];
|
|
716
716
|
returns?: ABIReturn[] | undefined;
|
package/app-factory.d.ts
CHANGED
|
@@ -211,9 +211,9 @@ declare class AppFactory {
|
|
|
211
211
|
sender: Address;
|
|
212
212
|
signer: AddressWithTransactionSigner | TransactionSigner | undefined;
|
|
213
213
|
method: ABIMethod;
|
|
214
|
-
args: (
|
|
215
|
-
sender: SendingAddress;
|
|
214
|
+
args: (Transaction | TransactionWithSigner | ABIValue | AppMethodCall<{
|
|
216
215
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
216
|
+
sender: SendingAddress;
|
|
217
217
|
rekeyTo?: ReadableAddress | undefined;
|
|
218
218
|
note?: (Uint8Array | string) | undefined;
|
|
219
219
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -223,8 +223,7 @@ declare class AppFactory {
|
|
|
223
223
|
validityWindow?: number | bigint | undefined;
|
|
224
224
|
firstValidRound?: bigint | undefined;
|
|
225
225
|
lastValidRound?: bigint | undefined;
|
|
226
|
-
|
|
227
|
-
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
226
|
+
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
228
227
|
args?: Uint8Array[] | undefined;
|
|
229
228
|
accountReferences?: ReadableAddress[] | undefined;
|
|
230
229
|
appReferences?: bigint[] | undefined;
|
|
@@ -232,9 +231,17 @@ declare class AppFactory {
|
|
|
232
231
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
233
232
|
accessReferences?: ResourceReference[] | undefined;
|
|
234
233
|
rejectVersion?: number | undefined;
|
|
234
|
+
appId?: 0 | undefined;
|
|
235
235
|
approvalProgram: string | Uint8Array;
|
|
236
236
|
clearStateProgram: string | Uint8Array;
|
|
237
|
-
|
|
237
|
+
schema?: {
|
|
238
|
+
globalInts: number;
|
|
239
|
+
globalByteSlices: number;
|
|
240
|
+
localInts: number;
|
|
241
|
+
localByteSlices: number;
|
|
242
|
+
} | undefined;
|
|
243
|
+
extraProgramPages?: number | undefined;
|
|
244
|
+
}> | AppMethodCall<{
|
|
238
245
|
sender: SendingAddress;
|
|
239
246
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
240
247
|
rekeyTo?: ReadableAddress | undefined;
|
|
@@ -246,25 +253,18 @@ declare class AppFactory {
|
|
|
246
253
|
validityWindow?: number | bigint | undefined;
|
|
247
254
|
firstValidRound?: bigint | undefined;
|
|
248
255
|
lastValidRound?: bigint | undefined;
|
|
256
|
+
appId: bigint;
|
|
257
|
+
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
249
258
|
args?: Uint8Array[] | undefined;
|
|
250
|
-
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
251
259
|
accountReferences?: ReadableAddress[] | undefined;
|
|
252
260
|
appReferences?: bigint[] | undefined;
|
|
253
261
|
assetReferences?: bigint[] | undefined;
|
|
254
262
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
255
263
|
accessReferences?: ResourceReference[] | undefined;
|
|
256
264
|
rejectVersion?: number | undefined;
|
|
257
|
-
appId?: 0 | undefined;
|
|
258
265
|
approvalProgram: string | Uint8Array;
|
|
259
266
|
clearStateProgram: string | Uint8Array;
|
|
260
|
-
|
|
261
|
-
globalInts: number;
|
|
262
|
-
globalByteSlices: number;
|
|
263
|
-
localInts: number;
|
|
264
|
-
localByteSlices: number;
|
|
265
|
-
} | undefined;
|
|
266
|
-
extraProgramPages?: number | undefined;
|
|
267
|
-
}> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
|
|
267
|
+
}> | AppMethodCall<AppMethodCallParams> | Promise<Transaction> | undefined)[] | undefined;
|
|
268
268
|
onComplete: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication;
|
|
269
269
|
}>;
|
|
270
270
|
/** Return params for a deployment update ABI call */
|
|
@@ -293,9 +293,9 @@ declare class AppFactory {
|
|
|
293
293
|
sender: Address;
|
|
294
294
|
signer: AddressWithTransactionSigner | TransactionSigner | undefined;
|
|
295
295
|
method: ABIMethod;
|
|
296
|
-
args: (
|
|
297
|
-
sender: SendingAddress;
|
|
296
|
+
args: (Transaction | TransactionWithSigner | ABIValue | AppMethodCall<{
|
|
298
297
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
298
|
+
sender: SendingAddress;
|
|
299
299
|
rekeyTo?: ReadableAddress | undefined;
|
|
300
300
|
note?: (Uint8Array | string) | undefined;
|
|
301
301
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -305,8 +305,7 @@ declare class AppFactory {
|
|
|
305
305
|
validityWindow?: number | bigint | undefined;
|
|
306
306
|
firstValidRound?: bigint | undefined;
|
|
307
307
|
lastValidRound?: bigint | undefined;
|
|
308
|
-
|
|
309
|
-
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
308
|
+
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
310
309
|
args?: Uint8Array[] | undefined;
|
|
311
310
|
accountReferences?: ReadableAddress[] | undefined;
|
|
312
311
|
appReferences?: bigint[] | undefined;
|
|
@@ -314,9 +313,17 @@ declare class AppFactory {
|
|
|
314
313
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
315
314
|
accessReferences?: ResourceReference[] | undefined;
|
|
316
315
|
rejectVersion?: number | undefined;
|
|
316
|
+
appId?: 0 | undefined;
|
|
317
317
|
approvalProgram: string | Uint8Array;
|
|
318
318
|
clearStateProgram: string | Uint8Array;
|
|
319
|
-
|
|
319
|
+
schema?: {
|
|
320
|
+
globalInts: number;
|
|
321
|
+
globalByteSlices: number;
|
|
322
|
+
localInts: number;
|
|
323
|
+
localByteSlices: number;
|
|
324
|
+
} | undefined;
|
|
325
|
+
extraProgramPages?: number | undefined;
|
|
326
|
+
}> | AppMethodCall<{
|
|
320
327
|
sender: SendingAddress;
|
|
321
328
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
322
329
|
rekeyTo?: ReadableAddress | undefined;
|
|
@@ -328,25 +335,18 @@ declare class AppFactory {
|
|
|
328
335
|
validityWindow?: number | bigint | undefined;
|
|
329
336
|
firstValidRound?: bigint | undefined;
|
|
330
337
|
lastValidRound?: bigint | undefined;
|
|
338
|
+
appId: bigint;
|
|
339
|
+
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
331
340
|
args?: Uint8Array[] | undefined;
|
|
332
|
-
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
333
341
|
accountReferences?: ReadableAddress[] | undefined;
|
|
334
342
|
appReferences?: bigint[] | undefined;
|
|
335
343
|
assetReferences?: bigint[] | undefined;
|
|
336
344
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
337
345
|
accessReferences?: ResourceReference[] | undefined;
|
|
338
346
|
rejectVersion?: number | undefined;
|
|
339
|
-
appId?: 0 | undefined;
|
|
340
347
|
approvalProgram: string | Uint8Array;
|
|
341
348
|
clearStateProgram: string | Uint8Array;
|
|
342
|
-
|
|
343
|
-
globalInts: number;
|
|
344
|
-
globalByteSlices: number;
|
|
345
|
-
localInts: number;
|
|
346
|
-
localByteSlices: number;
|
|
347
|
-
} | undefined;
|
|
348
|
-
extraProgramPages?: number | undefined;
|
|
349
|
-
}> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
|
|
349
|
+
}> | AppMethodCall<AppMethodCallParams> | Promise<Transaction> | undefined)[] | undefined;
|
|
350
350
|
onComplete: OnApplicationComplete.UpdateApplication;
|
|
351
351
|
};
|
|
352
352
|
/** Return params for a deployment delete ABI call */
|
|
@@ -375,9 +375,9 @@ declare class AppFactory {
|
|
|
375
375
|
sender: Address;
|
|
376
376
|
signer: AddressWithTransactionSigner | TransactionSigner | undefined;
|
|
377
377
|
method: ABIMethod;
|
|
378
|
-
args: (
|
|
379
|
-
sender: SendingAddress;
|
|
378
|
+
args: (Transaction | TransactionWithSigner | ABIValue | AppMethodCall<{
|
|
380
379
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
380
|
+
sender: SendingAddress;
|
|
381
381
|
rekeyTo?: ReadableAddress | undefined;
|
|
382
382
|
note?: (Uint8Array | string) | undefined;
|
|
383
383
|
lease?: (Uint8Array | string) | undefined;
|
|
@@ -387,8 +387,7 @@ declare class AppFactory {
|
|
|
387
387
|
validityWindow?: number | bigint | undefined;
|
|
388
388
|
firstValidRound?: bigint | undefined;
|
|
389
389
|
lastValidRound?: bigint | undefined;
|
|
390
|
-
|
|
391
|
-
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
390
|
+
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
392
391
|
args?: Uint8Array[] | undefined;
|
|
393
392
|
accountReferences?: ReadableAddress[] | undefined;
|
|
394
393
|
appReferences?: bigint[] | undefined;
|
|
@@ -396,9 +395,17 @@ declare class AppFactory {
|
|
|
396
395
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
397
396
|
accessReferences?: ResourceReference[] | undefined;
|
|
398
397
|
rejectVersion?: number | undefined;
|
|
398
|
+
appId?: 0 | undefined;
|
|
399
399
|
approvalProgram: string | Uint8Array;
|
|
400
400
|
clearStateProgram: string | Uint8Array;
|
|
401
|
-
|
|
401
|
+
schema?: {
|
|
402
|
+
globalInts: number;
|
|
403
|
+
globalByteSlices: number;
|
|
404
|
+
localInts: number;
|
|
405
|
+
localByteSlices: number;
|
|
406
|
+
} | undefined;
|
|
407
|
+
extraProgramPages?: number | undefined;
|
|
408
|
+
}> | AppMethodCall<{
|
|
402
409
|
sender: SendingAddress;
|
|
403
410
|
signer?: (TransactionSigner | AddressWithTransactionSigner) | undefined;
|
|
404
411
|
rekeyTo?: ReadableAddress | undefined;
|
|
@@ -410,25 +417,18 @@ declare class AppFactory {
|
|
|
410
417
|
validityWindow?: number | bigint | undefined;
|
|
411
418
|
firstValidRound?: bigint | undefined;
|
|
412
419
|
lastValidRound?: bigint | undefined;
|
|
420
|
+
appId: bigint;
|
|
421
|
+
onComplete?: OnApplicationComplete.UpdateApplication | undefined;
|
|
413
422
|
args?: Uint8Array[] | undefined;
|
|
414
|
-
onComplete?: OnApplicationComplete.NoOp | OnApplicationComplete.OptIn | OnApplicationComplete.CloseOut | OnApplicationComplete.UpdateApplication | OnApplicationComplete.DeleteApplication | undefined;
|
|
415
423
|
accountReferences?: ReadableAddress[] | undefined;
|
|
416
424
|
appReferences?: bigint[] | undefined;
|
|
417
425
|
assetReferences?: bigint[] | undefined;
|
|
418
426
|
boxReferences?: (BoxReference | BoxIdentifier)[] | undefined;
|
|
419
427
|
accessReferences?: ResourceReference[] | undefined;
|
|
420
428
|
rejectVersion?: number | undefined;
|
|
421
|
-
appId?: 0 | undefined;
|
|
422
429
|
approvalProgram: string | Uint8Array;
|
|
423
430
|
clearStateProgram: string | Uint8Array;
|
|
424
|
-
|
|
425
|
-
globalInts: number;
|
|
426
|
-
globalByteSlices: number;
|
|
427
|
-
localInts: number;
|
|
428
|
-
localByteSlices: number;
|
|
429
|
-
} | undefined;
|
|
430
|
-
extraProgramPages?: number | undefined;
|
|
431
|
-
}> | AppMethodCall<AppMethodCallParams> | undefined)[] | undefined;
|
|
431
|
+
}> | AppMethodCall<AppMethodCallParams> | Promise<Transaction> | undefined)[] | undefined;
|
|
432
432
|
onComplete: OnApplicationComplete.DeleteApplication;
|
|
433
433
|
};
|
|
434
434
|
bare: {
|
|
@@ -653,6 +653,7 @@ declare class AppFactory {
|
|
|
653
653
|
compiledApproval?: CompiledTeal | undefined;
|
|
654
654
|
compiledClear?: CompiledTeal | undefined;
|
|
655
655
|
operationPerformed: "create";
|
|
656
|
+
version: string;
|
|
656
657
|
updatable?: boolean | undefined;
|
|
657
658
|
deletable?: boolean | undefined;
|
|
658
659
|
createdRound: bigint;
|
|
@@ -660,7 +661,6 @@ declare class AppFactory {
|
|
|
660
661
|
createdMetadata: AppDeployMetadata;
|
|
661
662
|
deleted: boolean;
|
|
662
663
|
name: string;
|
|
663
|
-
version: string;
|
|
664
664
|
groupId: string | undefined;
|
|
665
665
|
txIds: string[];
|
|
666
666
|
returns?: ABIReturn[] | undefined;
|
|
@@ -699,6 +699,7 @@ declare class AppFactory {
|
|
|
699
699
|
compiledApproval?: CompiledTeal | undefined;
|
|
700
700
|
compiledClear?: CompiledTeal | undefined;
|
|
701
701
|
operationPerformed: "replace";
|
|
702
|
+
version: string;
|
|
702
703
|
updatable?: boolean | undefined;
|
|
703
704
|
deletable?: boolean | undefined;
|
|
704
705
|
createdRound: bigint;
|
|
@@ -706,7 +707,6 @@ declare class AppFactory {
|
|
|
706
707
|
createdMetadata: AppDeployMetadata;
|
|
707
708
|
deleted: boolean;
|
|
708
709
|
name: string;
|
|
709
|
-
version: string;
|
|
710
710
|
groupId: string | undefined;
|
|
711
711
|
txIds: string[];
|
|
712
712
|
returns?: ABIReturn[] | undefined;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"**"
|
|
7
7
|
],
|
|
8
8
|
"name": "@algorandfoundation/algokit-utils",
|
|
9
|
-
"version": "10.0.0-alpha.
|
|
9
|
+
"version": "10.0.0-alpha.38",
|
|
10
10
|
"private": false,
|
|
11
11
|
"description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
|
|
12
12
|
"author": "Algorand Foundation",
|
|
@@ -93,6 +93,8 @@
|
|
|
93
93
|
"esbuild": "0.25.0"
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
+
"@algorandfoundation/xhd-wallet-api": "2.0.0-canary.1",
|
|
97
|
+
"@noble/ed25519": "^3.0.0",
|
|
96
98
|
"@noble/hashes": "^2.0.1",
|
|
97
99
|
"algorand-msgpack": "^1.1.0",
|
|
98
100
|
"buffer": "^6.0.3",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
2
|
const require_abi_type = require('./abi-type.js');
|
|
3
|
+
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
3
4
|
|
|
4
5
|
//#region packages/abi/src/abi-method.ts
|
|
5
6
|
let ABITransactionType = /* @__PURE__ */ function(ABITransactionType) {
|
|
@@ -49,7 +50,7 @@ var ABIMethod = class ABIMethod {
|
|
|
49
50
|
* @returns The 4-byte method selector
|
|
50
51
|
*/
|
|
51
52
|
getSelector() {
|
|
52
|
-
const hash =
|
|
53
|
+
const hash = (0, _noble_hashes_sha2_js.sha512_256)(new TextEncoder().encode(this.getSignature()));
|
|
53
54
|
return new Uint8Array(hash.slice(0, 4));
|
|
54
55
|
}
|
|
55
56
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi-method.js","names":["sha512_256","parseTupleContent","ABIType","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import { sha512_256 } from '@noble/hashes/sha2.js'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512_256(new TextEncoder().encode(this.getSignature()))\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n description: method.returns.desc,\n } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;AAMA,IAAY,kEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,8DAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG,KAAK,GADZ,KAAK,QAAQ,SAAS,SAAS,SAAS,KAAK,QAAQ,KAAK;;;;;;CAQ5E,cAA0B;EACxB,MAAM,OAAOA,wBAAW,IAAI,aAAa,CAAC,OAAO,KAAK,cAAc,CAAC,CAAC;AACtE,SAAO,IAAI,WAAW,KAAK,MAAM,GAAG,EAAE,CAAC;;;;;;;;CASzC,OAAO,cAAc,WAA8B;EACjD,MAAM,YAAY,UAAU,QAAQ,IAAI;AACxC,MAAI,cAAc,GAChB,OAAM,IAAI,MAAM,6BAA6B,YAAY;EAG3D,IAAI,UAAU;EACd,IAAI,QAAQ;AACZ,OAAK,IAAI,IAAI,WAAW,IAAI,UAAU,QAAQ,KAAK;GACjD,MAAM,OAAO,UAAU;AAEvB,OAAI,SAAS,IACX,UAAS;YACA,SAAS,KAAK;AACvB,Q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,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"abi-method.js","names":["parseTupleContent","ABIType","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import { sha512_256 } from '@noble/hashes/sha2.js'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512_256(new TextEncoder().encode(this.getSignature()))\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n description: method.returns.desc,\n } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;;AAMA,IAAY,kEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,8DAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,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KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAOA,yBAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,eAAe,SAAkB,OAA6B;AAC5E,SAAQ,SAAR;EACE,KAAK,YACH,QAAOA,yBAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;EAC7C,KAAK;AACH,OAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK,OAAO,QAAQ;AACjE,OAAI,OAAO,UAAU,YAAY,EAAE,iBAAiB,YAClD,OAAM,IAAI,MAAM,8CAA8C,QAAQ;AACxE,UAAO;EACT,KAAK,YACH,QAAOA,yBAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,UAAU,MAAgC;AACxD,QAAO,OAAO,SAAS,aAAa,SAAS,eAAe,SAAS,cAAc,SAAS;;AAG9F,SAAgB,mBAAmB,MAA4C,OAA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAIE,6BAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAIC,iCAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sha512_256 } from "../../../node_modules/@noble/hashes/sha2.mjs";
|
|
2
1
|
import { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from "./abi-type.mjs";
|
|
2
|
+
import { sha512_256 } from "@noble/hashes/sha2.js";
|
|
3
3
|
|
|
4
4
|
//#region packages/abi/src/abi-method.ts
|
|
5
5
|
let ABITransactionType = /* @__PURE__ */ function(ABITransactionType) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
|
-
const require_sha2 = require('../../../node_modules/@noble/hashes/sha2.js');
|
|
3
2
|
const require_array = require('./array.js');
|
|
4
3
|
const require_constants = require('./constants.js');
|
|
5
4
|
let hi_base32 = require("hi-base32");
|
|
6
5
|
hi_base32 = require_runtime.__toESM(hi_base32);
|
|
6
|
+
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
7
7
|
|
|
8
8
|
//#region packages/common/src/address.ts
|
|
9
9
|
const ALGORAND_ADDRESS_BYTE_LENGTH = 36;
|
|
@@ -13,7 +13,7 @@ const ALGORAND_ZERO_ADDRESS_STRING = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
|
|
13
13
|
const MALFORMED_ADDRESS_ERROR_MSG = "address seems to be malformed";
|
|
14
14
|
const CHECKSUM_ADDRESS_ERROR_MSG = "wrong checksum for address";
|
|
15
15
|
function checksumFromPublicKey(publicKey) {
|
|
16
|
-
return Uint8Array.from(
|
|
16
|
+
return Uint8Array.from((0, _noble_hashes_sha2_js.sha512_256)(publicKey).slice(require_constants.HASH_BYTES_LENGTH - require_constants.CHECKSUM_BYTE_LENGTH, require_constants.HASH_BYTES_LENGTH));
|
|
17
17
|
}
|
|
18
18
|
function bytesToHex(bytes) {
|
|
19
19
|
return Buffer.from(bytes).toString("hex");
|
|
@@ -119,7 +119,7 @@ const APP_ID_PREFIX = new TextEncoder().encode("appID");
|
|
|
119
119
|
* @returns The address corresponding to that application's escrow account.
|
|
120
120
|
*/
|
|
121
121
|
function getApplicationAddress(appID) {
|
|
122
|
-
return new Address(
|
|
122
|
+
return new Address((0, _noble_hashes_sha2_js.sha512_256)(require_array.concatArrays(APP_ID_PREFIX, encodeUint64(appID))));
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* decodeAddress takes an Algorand address in string form and decodes it into a Uint8Array.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","names":["
|
|
1
|
+
{"version":3,"file":"address.js","names":["HASH_BYTES_LENGTH","CHECKSUM_BYTE_LENGTH","arrayEqual","base32","concatArrays"],"sources":["../../../../packages/common/src/address.ts"],"sourcesContent":["import base32 from 'hi-base32'\nimport { sha512_256 } from '@noble/hashes/sha2.js'\nimport { arrayEqual, concatArrays } from './array'\nimport { CHECKSUM_BYTE_LENGTH, HASH_BYTES_LENGTH } from './constants'\n\nexport const ALGORAND_ADDRESS_BYTE_LENGTH = 36\nexport const ALGORAND_CHECKSUM_BYTE_LENGTH = 4\nexport const ALGORAND_ADDRESS_LENGTH = 58\nexport const ALGORAND_ZERO_ADDRESS_STRING = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ'\n\nexport const MALFORMED_ADDRESS_ERROR_MSG = 'address seems to be malformed'\nexport const CHECKSUM_ADDRESS_ERROR_MSG = 'wrong checksum for address'\n\nexport function checksumFromPublicKey(publicKey: Uint8Array): Uint8Array {\n return Uint8Array.from(sha512_256(publicKey).slice(HASH_BYTES_LENGTH - CHECKSUM_BYTE_LENGTH, HASH_BYTES_LENGTH))\n}\n\nfunction bytesToHex(bytes: Uint8Array): string {\n return Buffer.from(bytes).toString('hex')\n}\n\nexport function encodeUint64(num: number | bigint) {\n const isInteger = typeof num === 'bigint' || Number.isInteger(num)\n\n if (!isInteger || num < 0 || num > BigInt('0xffffffffffffffff')) {\n throw new Error('Input is not a 64-bit unsigned integer')\n }\n\n const encoding = new Uint8Array(8)\n const view = new DataView(encoding.buffer)\n view.setBigUint64(0, BigInt(num))\n\n return encoding\n}\n\n/** Symbol used for instanceof checks across packages (CJS/ESM) */\nconst ADDR_SYMBOL = Symbol.for('algokit_common:Address')\n\n/**\n * Represents an Algorand address\n */\nexport class Address {\n /**\n * The binary form of the address. For standard accounts, this is the public key.\n */\n public readonly publicKey: Uint8Array;\n\n /** @internal */\n [ADDR_SYMBOL]: boolean\n\n /**\n * Create a new Address object from its binary form.\n * @param publicKey - The binary form of the address. Must be 32 bytes.\n */\n constructor(publicKey: Uint8Array) {\n this[ADDR_SYMBOL] = true\n if (publicKey.length !== ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH)\n throw new Error(`${MALFORMED_ADDRESS_ERROR_MSG}: 0x${bytesToHex(publicKey)}, length ${publicKey.length}`)\n this.publicKey = publicKey\n }\n\n /**\n * Check if the address is equal to another address.\n */\n equals(other: Address): boolean {\n return other instanceof Address && arrayEqual(this.publicKey, other.publicKey)\n }\n\n /**\n * Compute the 4 byte checksum of the address.\n */\n checksum(): Uint8Array {\n return checksumFromPublicKey(this.publicKey)\n }\n\n /**\n * Encode the address into a string form.\n */\n toString(): string {\n const addr = base32.encode(concatArrays(this.publicKey, this.checksum()))\n return addr.slice(0, ALGORAND_ADDRESS_LENGTH) // removing the extra '===='\n }\n\n /**\n * Decode an address from a string.\n * @param address - The address to decode. Must be 58 characters long.\n * @returns An Address object corresponding to the input string.\n */\n static fromString(address: string): Address {\n if (typeof address !== 'string') throw new Error(`${MALFORMED_ADDRESS_ERROR_MSG}: expected string, got ${typeof address}, ${address}`)\n if (address.length !== ALGORAND_ADDRESS_LENGTH)\n throw new Error(`${MALFORMED_ADDRESS_ERROR_MSG}: expected length ${ALGORAND_ADDRESS_LENGTH}, got ${address.length}: ${address}`)\n\n // try to decode\n const decoded = base32.decode.asBytes(address)\n // Sanity check\n if (decoded.length !== ALGORAND_ADDRESS_BYTE_LENGTH)\n throw new Error(`${MALFORMED_ADDRESS_ERROR_MSG}: expected byte length ${ALGORAND_ADDRESS_BYTE_LENGTH}, got ${decoded.length}`)\n\n // Find publickey and checksum\n const pk = new Uint8Array(decoded.slice(0, ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH))\n const cs = new Uint8Array(decoded.slice(ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH, ALGORAND_ADDRESS_BYTE_LENGTH))\n const checksum = checksumFromPublicKey(pk)\n // Check if the checksum and the address are equal\n if (!arrayEqual(checksum, cs)) throw new Error(`${CHECKSUM_ADDRESS_ERROR_MSG}: ${address} (${cs}, ${checksum})`)\n\n return new Address(pk)\n }\n\n /**\n * Get the zero address.\n */\n static zeroAddress(): Address {\n return new Address(new Uint8Array(ALGORAND_ADDRESS_BYTE_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH))\n }\n}\n\n// Define Symbol.hasInstance outside the class to avoid Metro/Hermes parser issues\n// with static computed property names like `static [Symbol.hasInstance]()`\n// Also must handle Babel's _classCallCheck which uses instanceof before ADDR_SYMBOL is set\nObject.defineProperty(Address, Symbol.hasInstance, {\n value: function (obj: unknown): boolean {\n // First check prototype chain (handles Babel's _classCallCheck and normal instances)\n if (obj instanceof Object && Object.getPrototypeOf(obj) === Address.prototype) {\n return true\n }\n // Then check for the brand symbol (handles cross-realm/serialized instances)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return Boolean(obj && typeof obj === 'object' && ADDR_SYMBOL in obj && (obj as any)[ADDR_SYMBOL])\n },\n})\n\nexport interface Addressable {\n addr: Readonly<Address>\n}\n\nexport type ReadableAddress = Addressable | Address | string\n\nexport function getAddress(addr: ReadableAddress): Address {\n if (typeof addr == 'string') {\n return Address.fromString(addr)\n } else if ('addr' in addr) {\n return addr.addr\n } else {\n return addr\n }\n}\n\nexport function getOptionalAddress(addr: ReadableAddress | undefined): Address | undefined {\n if (addr === undefined) {\n return undefined\n }\n return getAddress(addr)\n}\n\n/**\n * isValidAddress checks if a string is a valid Algorand address.\n * @param address - an Algorand address with checksum.\n * @returns true if valid, false otherwise\n */\nexport function isValidAddress(address: string): boolean {\n // Try to decode\n try {\n Address.fromString(address)\n } catch {\n return false\n }\n return true\n}\n\nconst APP_ID_PREFIX = new TextEncoder().encode('appID')\n\n/**\n * Get the escrow address of an application.\n * @param appID - The ID of the application.\n * @returns The address corresponding to that application's escrow account.\n */\nexport function getApplicationAddress(appID: number | bigint): Address {\n const toBeSigned = concatArrays(APP_ID_PREFIX, encodeUint64(appID))\n const hash = sha512_256(toBeSigned)\n return new Address(hash)\n}\n\n/**\n * decodeAddress takes an Algorand address in string form and decodes it into a Uint8Array.\n * @param address - an Algorand address with checksum.\n * @returns the decoded form of the address's public key and checksum\n */\nexport function decodeAddress(address: string): Address {\n return Address.fromString(address)\n}\n\n/**\n * encodeAddress takes an Algorand address as a Uint8Array and encodes it into a string with checksum.\n * @param address - a raw Algorand address\n * @returns the address and checksum encoded as a string.\n */\nexport function encodeAddress(address: Uint8Array): string {\n return new Address(address).toString()\n}\n"],"mappings":";;;;;;;;AAKA,MAAa,+BAA+B;AAC5C,MAAa,gCAAgC;AAC7C,MAAa,0BAA0B;AACvC,MAAa,+BAA+B;AAE5C,MAAa,8BAA8B;AAC3C,MAAa,6BAA6B;AAE1C,SAAgB,sBAAsB,WAAmC;AACvE,QAAO,WAAW,2CAAgB,UAAU,CAAC,MAAMA,sCAAoBC,wCAAsBD,oCAAkB,CAAC;;AAGlH,SAAS,WAAW,OAA2B;AAC7C,QAAO,OAAO,KAAK,MAAM,CAAC,SAAS,MAAM;;AAG3C,SAAgB,aAAa,KAAsB;AAGjD,KAAI,EAFc,OAAO,QAAQ,YAAY,OAAO,UAAU,IAAI,KAEhD,MAAM,KAAK,MAAM,OAAO,qBAAqB,CAC7D,OAAM,IAAI,MAAM,yCAAyC;CAG3D,MAAM,WAAW,IAAI,WAAW,EAAE;AAElC,CADa,IAAI,SAAS,SAAS,OAAO,CACrC,aAAa,GAAG,OAAO,IAAI,CAAC;AAEjC,QAAO;;;AAIT,MAAM,cAAc,OAAO,IAAI,yBAAyB;;;;AAKxD,IAAa,UAAb,MAAa,QAAQ;;;;CAInB,AAAgB;;CAGhB,CAAC;;;;;CAMD,YAAY,WAAuB;AACjC,OAAK,eAAe;AACpB,MAAI,UAAU,WAAW,+BAA+B,8BACtD,OAAM,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,KAAI,eAAe,UAAU,OAAO,eAAe,IAAI,KAAK,QAAQ,UAClE,QAAO;AAIT,QAAO,QAAQ,OAAO,OAAO,QAAQ,YAAY,eAAe,OAAQ,IAAY,aAAa;GAEpG,CAAC;AAQF,SAAgB,WAAW,MAAgC;AACzD,KAAI,OAAO,QAAQ,SACjB,QAAO,QAAQ,WAAW,KAAK;UACtB,UAAU,KACnB,QAAO,KAAK;KAEZ,QAAO;;AAIX,SAAgB,mBAAmB,MAAwD;AACzF,KAAI,SAAS,OACX;AAEF,QAAO,WAAW,KAAK;;;;;;;AAQzB,SAAgB,eAAe,SAA0B;AAEvD,KAAI;AACF,UAAQ,WAAW,QAAQ;SACrB;AACN,SAAO;;AAET,QAAO;;AAGT,MAAM,gBAAgB,IAAI,aAAa,CAAC,OAAO,QAAQ;;;;;;AAOvD,SAAgB,sBAAsB,OAAiC;AAGrE,QAAO,IAAI,8CAFQE,2BAAa,eAAe,aAAa,MAAM,CAAC,CAChC,CACX;;;;;;;AAQ1B,SAAgB,cAAc,SAA0B;AACtD,QAAO,QAAQ,WAAW,QAAQ;;;;;;;AAQpC,SAAgB,cAAc,SAA6B;AACzD,QAAO,IAAI,QAAQ,QAAQ,CAAC,UAAU"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { sha512_256 } from "../../../node_modules/@noble/hashes/sha2.mjs";
|
|
2
1
|
import { arrayEqual, concatArrays } from "./array.mjs";
|
|
3
2
|
import { CHECKSUM_BYTE_LENGTH, HASH_BYTES_LENGTH } from "./constants.mjs";
|
|
4
3
|
import base32 from "hi-base32";
|
|
4
|
+
import { sha512_256 } from "@noble/hashes/sha2.js";
|
|
5
5
|
|
|
6
6
|
//#region packages/common/src/address.ts
|
|
7
7
|
const ALGORAND_ADDRESS_BYTE_LENGTH = 36;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
|
+
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
3
|
+
let _noble_ed25519 = require("@noble/ed25519");
|
|
4
|
+
_noble_ed25519 = require_runtime.__toESM(_noble_ed25519);
|
|
3
5
|
|
|
4
6
|
//#region packages/crypto/src/ed25519.ts
|
|
5
7
|
/**
|
|
@@ -10,7 +12,7 @@ const require_index = require('../../../node_modules/@noble/ed25519/index.js');
|
|
|
10
12
|
* @returns A promise that resolves to true if the signature is valid, false otherwise.
|
|
11
13
|
*/
|
|
12
14
|
const nobleEd25519Verifier = async (signature, message, pubkey) => {
|
|
13
|
-
return
|
|
15
|
+
return _noble_ed25519.verifyAsync(signature, message, pubkey);
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* Verifies an ed25519 signature using the default ed25519 implementation (currently @noble/ed25519).
|
|
@@ -21,7 +23,7 @@ const nobleEd25519Verifier = async (signature, message, pubkey) => {
|
|
|
21
23
|
* @returns A promise that resolves to true if the signature is valid, false otherwise.
|
|
22
24
|
*/
|
|
23
25
|
const ed25519Verifier = nobleEd25519Verifier;
|
|
24
|
-
|
|
26
|
+
_noble_ed25519.hashes.sha512 = (msg) => (0, _noble_hashes_sha2_js.sha512)(msg);
|
|
25
27
|
/**
|
|
26
28
|
* Generates an ed25519 keypair and a raw signer function using the @noble/ed25519 implementation.
|
|
27
29
|
*
|
|
@@ -29,10 +31,10 @@ require_index.hashes.sha512 = (msg) => require_sha2.sha512(msg);
|
|
|
29
31
|
* @returns An object containing the ed25519 public key, secret key, and a raw signer function.
|
|
30
32
|
*/
|
|
31
33
|
const nobleEd25519Generator = (seed) => {
|
|
32
|
-
const ed25519SecretKey =
|
|
33
|
-
const ed25519Pubkey =
|
|
34
|
+
const ed25519SecretKey = _noble_ed25519.utils.randomSecretKey(seed);
|
|
35
|
+
const ed25519Pubkey = _noble_ed25519.getPublicKey(ed25519SecretKey);
|
|
34
36
|
const rawEd25519Signer = async (bytesToSign) => {
|
|
35
|
-
return
|
|
37
|
+
return _noble_ed25519.signAsync(bytesToSign, ed25519SecretKey);
|
|
36
38
|
};
|
|
37
39
|
return {
|
|
38
40
|
ed25519Pubkey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.js","names":["
|
|
1
|
+
{"version":3,"file":"ed25519.js","names":["ed"],"sources":["../../../../packages/crypto/src/ed25519.ts"],"sourcesContent":["import * as ed from '@noble/ed25519'\nimport { sha512 } from '@noble/hashes/sha2.js'\n\nexport type RawEd25519Verifier = (signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array) => Promise<boolean>\nexport type RawEd25519Signer = (bytesToSign: Uint8Array) => Promise<Uint8Array>\nexport type Ed25519Generator = (seed?: Uint8Array) => {\n ed25519Pubkey: Uint8Array\n ed25519SecretKey: Uint8Array\n rawEd25519Signer: RawEd25519Signer\n}\n\n/**\n * Verifies an ed25519 signature using the @noble/ed25519 implementation.\n *\n * @param message - The original message that was signed.\n * @param signature - The ed25519 signature to verify.\n * @returns A promise that resolves to true if the signature is valid, false otherwise.\n */\nexport const nobleEd25519Verifier: RawEd25519Verifier = async (\n signature: Uint8Array,\n message: Uint8Array,\n pubkey: Uint8Array,\n): Promise<boolean> => {\n return ed.verifyAsync(signature, message, pubkey)\n}\n\n/**\n * Verifies an ed25519 signature using the default ed25519 implementation (currently @noble/ed25519).\n * The implementation may change in the future. To explicitly use the @noble/ed25519 implementation, use `nobleEd25519Verifier`.\n *\n * @param message - The original message that was signed.\n * @param signature - The ed25519 signature to verify.\n * @returns A promise that resolves to true if the signature is valid, false otherwise.\n */\nexport const ed25519Verifier: RawEd25519Verifier = nobleEd25519Verifier\n\ned.hashes.sha512 = (msg: ed.Bytes) => sha512(msg)\n\n/**\n * Generates an ed25519 keypair and a raw signer function using the @noble/ed25519 implementation.\n *\n * @param seed - Optional seed for key generation. If not provided, a random seed will be used.\n * @returns An object containing the ed25519 public key, secret key, and a raw signer function.\n */\nexport const nobleEd25519Generator: Ed25519Generator = (seed?: Uint8Array) => {\n const ed25519SecretKey = ed.utils.randomSecretKey(seed)\n const ed25519Pubkey = ed.getPublicKey(ed25519SecretKey)\n\n const rawEd25519Signer: RawEd25519Signer = async (bytesToSign: Uint8Array): Promise<Uint8Array> => {\n return ed.signAsync(bytesToSign, ed25519SecretKey)\n }\n\n return { ed25519Pubkey, ed25519SecretKey, rawEd25519Signer }\n}\n\n/**\n * Generates an ed25519 keypair and a raw signer function using the default ed25519 implementation (currently @noble/ed25519).\n * The implementation may change in the future. To explicitly use the @noble/ed25519 implementation, use `nobleEd25519Generator`.\n *\n * @param seed - Optional seed for key generation. If not provided, a random seed will be used.\n * @returns An object containing the ed25519 public key, secret key, and a raw signer function.\n */\nexport const ed25519Generator: Ed25519Generator = nobleEd25519Generator\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAa,uBAA2C,OACtD,WACA,SACA,WACqB;AACrB,QAAOA,eAAG,YAAY,WAAW,SAAS,OAAO;;;;;;;;;;AAWnD,MAAa,kBAAsC;AAEnD,eAAG,OAAO,UAAU,0CAAyB,IAAI;;;;;;;AAQjD,MAAa,yBAA2C,SAAsB;CAC5E,MAAM,mBAAmBA,eAAG,MAAM,gBAAgB,KAAK;CACvD,MAAM,gBAAgBA,eAAG,aAAa,iBAAiB;CAEvD,MAAM,mBAAqC,OAAO,gBAAiD;AACjG,SAAOA,eAAG,UAAU,aAAa,iBAAiB;;AAGpD,QAAO;EAAE;EAAe;EAAkB;EAAkB;;;;;;;;;AAU9D,MAAa,mBAAqC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sha512 } from "
|
|
2
|
-
import
|
|
1
|
+
import { sha512 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import * as ed from "@noble/ed25519";
|
|
3
3
|
|
|
4
4
|
//#region packages/crypto/src/ed25519.ts
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ import { getPublicKey, hashes, signAsync, utils, verifyAsync } from "../../../no
|
|
|
10
10
|
* @returns A promise that resolves to true if the signature is valid, false otherwise.
|
|
11
11
|
*/
|
|
12
12
|
const nobleEd25519Verifier = async (signature, message, pubkey) => {
|
|
13
|
-
return verifyAsync(signature, message, pubkey);
|
|
13
|
+
return ed.verifyAsync(signature, message, pubkey);
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Verifies an ed25519 signature using the default ed25519 implementation (currently @noble/ed25519).
|
|
@@ -21,7 +21,7 @@ const nobleEd25519Verifier = async (signature, message, pubkey) => {
|
|
|
21
21
|
* @returns A promise that resolves to true if the signature is valid, false otherwise.
|
|
22
22
|
*/
|
|
23
23
|
const ed25519Verifier = nobleEd25519Verifier;
|
|
24
|
-
hashes.sha512 = (msg) => sha512(msg);
|
|
24
|
+
ed.hashes.sha512 = (msg) => sha512(msg);
|
|
25
25
|
/**
|
|
26
26
|
* Generates an ed25519 keypair and a raw signer function using the @noble/ed25519 implementation.
|
|
27
27
|
*
|
|
@@ -29,10 +29,10 @@ hashes.sha512 = (msg) => sha512(msg);
|
|
|
29
29
|
* @returns An object containing the ed25519 public key, secret key, and a raw signer function.
|
|
30
30
|
*/
|
|
31
31
|
const nobleEd25519Generator = (seed) => {
|
|
32
|
-
const ed25519SecretKey = utils.randomSecretKey(seed);
|
|
33
|
-
const ed25519Pubkey = getPublicKey(ed25519SecretKey);
|
|
32
|
+
const ed25519SecretKey = ed.utils.randomSecretKey(seed);
|
|
33
|
+
const ed25519Pubkey = ed.getPublicKey(ed25519SecretKey);
|
|
34
34
|
const rawEd25519Signer = async (bytesToSign) => {
|
|
35
|
-
return signAsync(bytesToSign, ed25519SecretKey);
|
|
35
|
+
return ed.signAsync(bytesToSign, ed25519SecretKey);
|
|
36
36
|
};
|
|
37
37
|
return {
|
|
38
38
|
ed25519Pubkey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.mjs","names":[
|
|
1
|
+
{"version":3,"file":"ed25519.mjs","names":[],"sources":["../../../../packages/crypto/src/ed25519.ts"],"sourcesContent":["import * as ed from '@noble/ed25519'\nimport { sha512 } from '@noble/hashes/sha2.js'\n\nexport type RawEd25519Verifier = (signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array) => Promise<boolean>\nexport type RawEd25519Signer = (bytesToSign: Uint8Array) => Promise<Uint8Array>\nexport type Ed25519Generator = (seed?: Uint8Array) => {\n ed25519Pubkey: Uint8Array\n ed25519SecretKey: Uint8Array\n rawEd25519Signer: RawEd25519Signer\n}\n\n/**\n * Verifies an ed25519 signature using the @noble/ed25519 implementation.\n *\n * @param message - The original message that was signed.\n * @param signature - The ed25519 signature to verify.\n * @returns A promise that resolves to true if the signature is valid, false otherwise.\n */\nexport const nobleEd25519Verifier: RawEd25519Verifier = async (\n signature: Uint8Array,\n message: Uint8Array,\n pubkey: Uint8Array,\n): Promise<boolean> => {\n return ed.verifyAsync(signature, message, pubkey)\n}\n\n/**\n * Verifies an ed25519 signature using the default ed25519 implementation (currently @noble/ed25519).\n * The implementation may change in the future. To explicitly use the @noble/ed25519 implementation, use `nobleEd25519Verifier`.\n *\n * @param message - The original message that was signed.\n * @param signature - The ed25519 signature to verify.\n * @returns A promise that resolves to true if the signature is valid, false otherwise.\n */\nexport const ed25519Verifier: RawEd25519Verifier = nobleEd25519Verifier\n\ned.hashes.sha512 = (msg: ed.Bytes) => sha512(msg)\n\n/**\n * Generates an ed25519 keypair and a raw signer function using the @noble/ed25519 implementation.\n *\n * @param seed - Optional seed for key generation. If not provided, a random seed will be used.\n * @returns An object containing the ed25519 public key, secret key, and a raw signer function.\n */\nexport const nobleEd25519Generator: Ed25519Generator = (seed?: Uint8Array) => {\n const ed25519SecretKey = ed.utils.randomSecretKey(seed)\n const ed25519Pubkey = ed.getPublicKey(ed25519SecretKey)\n\n const rawEd25519Signer: RawEd25519Signer = async (bytesToSign: Uint8Array): Promise<Uint8Array> => {\n return ed.signAsync(bytesToSign, ed25519SecretKey)\n }\n\n return { ed25519Pubkey, ed25519SecretKey, rawEd25519Signer }\n}\n\n/**\n * Generates an ed25519 keypair and a raw signer function using the default ed25519 implementation (currently @noble/ed25519).\n * The implementation may change in the future. To explicitly use the @noble/ed25519 implementation, use `nobleEd25519Generator`.\n *\n * @param seed - Optional seed for key generation. If not provided, a random seed will be used.\n * @returns An object containing the ed25519 public key, secret key, and a raw signer function.\n */\nexport const ed25519Generator: Ed25519Generator = nobleEd25519Generator\n"],"mappings":";;;;;;;;;;;AAkBA,MAAa,uBAA2C,OACtD,WACA,SACA,WACqB;AACrB,QAAO,GAAG,YAAY,WAAW,SAAS,OAAO;;;;;;;;;;AAWnD,MAAa,kBAAsC;AAEnD,GAAG,OAAO,UAAU,QAAkB,OAAO,IAAI;;;;;;;AAQjD,MAAa,yBAA2C,SAAsB;CAC5E,MAAM,mBAAmB,GAAG,MAAM,gBAAgB,KAAK;CACvD,MAAM,gBAAgB,GAAG,aAAa,iBAAiB;CAEvD,MAAM,mBAAqC,OAAO,gBAAiD;AACjG,SAAO,GAAG,UAAU,aAAa,iBAAiB;;AAGpD,QAAO;EAAE;EAAe;EAAkB;EAAkB;;;;;;;;;AAU9D,MAAa,mBAAqC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
2
|
const require_constants = require('../../common/src/constants.js');
|
|
3
|
+
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
3
4
|
|
|
4
5
|
//#region packages/crypto/src/hash.ts
|
|
5
6
|
/**
|
|
6
7
|
* Computes an Algorand-compatible SHA-512/256 hash.
|
|
7
8
|
*/
|
|
8
9
|
function hash(bytes) {
|
|
9
|
-
return
|
|
10
|
+
return (0, _noble_hashes_sha2_js.sha512_256)(bytes).slice(0, require_constants.HASH_BYTES_LENGTH);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","names":["
|
|
1
|
+
{"version":3,"file":"hash.js","names":["HASH_BYTES_LENGTH"],"sources":["../../../../packages/crypto/src/hash.ts"],"sourcesContent":["import { sha512_256 } from '@noble/hashes/sha2.js'\nimport { HASH_BYTES_LENGTH } from '@algorandfoundation/algokit-common'\n\n/**\n * Computes an Algorand-compatible SHA-512/256 hash.\n */\nexport function hash(bytes: Uint8Array): Uint8Array {\n return sha512_256(bytes).slice(0, HASH_BYTES_LENGTH)\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,KAAK,OAA+B;AAClD,8CAAkB,MAAM,CAAC,MAAM,GAAGA,oCAAkB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
|
+
let _algorandfoundation_xhd_wallet_api = require("@algorandfoundation/xhd-wallet-api");
|
|
3
3
|
|
|
4
4
|
//#region packages/crypto/src/hd.ts
|
|
5
5
|
const verifyPath = (bip44Path) => {
|
|
6
6
|
if (bip44Path.length !== 5) throw new Error("BIP44 path must have exactly 5 elements");
|
|
7
|
-
if (bip44Path[0] !==
|
|
8
|
-
if (bip44Path[1] !==
|
|
7
|
+
if (bip44Path[0] !== (0, _algorandfoundation_xhd_wallet_api.harden)(44)) throw new Error("BIP44 path must start with 44'");
|
|
8
|
+
if (bip44Path[1] !== (0, _algorandfoundation_xhd_wallet_api.harden)(283)) throw new Error("BIP44 path must have hardened coin type 283' for Algorand");
|
|
9
9
|
};
|
|
10
10
|
const getPathComponents = (bip44Path) => {
|
|
11
11
|
return {
|
|
@@ -13,15 +13,15 @@ const getPathComponents = (bip44Path) => {
|
|
|
13
13
|
index: bip44Path[4]
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
const xhd = new
|
|
16
|
+
const xhd = new _algorandfoundation_xhd_wallet_api.XHDWalletAPI();
|
|
17
17
|
const peikertXHdWalletGenerator = async (seed) => {
|
|
18
18
|
const seedArray = seed ?? new Uint8Array(32);
|
|
19
19
|
if (seed === void 0) crypto.getRandomValues(seedArray);
|
|
20
|
-
const rootKey =
|
|
20
|
+
const rootKey = (0, _algorandfoundation_xhd_wallet_api.fromSeed)(Buffer.from(seedArray));
|
|
21
21
|
const rawHdSigner = async (bytesToSign, bip44Path) => {
|
|
22
22
|
verifyPath(bip44Path);
|
|
23
23
|
const { account, index } = getPathComponents(bip44Path);
|
|
24
|
-
return xhd.signAlgoTransaction(rootKey,
|
|
24
|
+
return xhd.signAlgoTransaction(rootKey, _algorandfoundation_xhd_wallet_api.KeyContext.Address, account, index, bytesToSign, _algorandfoundation_xhd_wallet_api.BIP32DerivationType.Peikert);
|
|
25
25
|
};
|
|
26
26
|
return {
|
|
27
27
|
hdRootKey: rootKey,
|
|
@@ -29,17 +29,17 @@ const peikertXHdWalletGenerator = async (seed) => {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
const peikertXHdAccountGenerator = async (rootKey, account, index) => {
|
|
32
|
-
const ed25519Pubkey = await xhd.keyGen(rootKey,
|
|
32
|
+
const ed25519Pubkey = await xhd.keyGen(rootKey, _algorandfoundation_xhd_wallet_api.KeyContext.Address, account, index, _algorandfoundation_xhd_wallet_api.BIP32DerivationType.Peikert);
|
|
33
33
|
const rawEd25519Signer = async (bytesToSign) => {
|
|
34
|
-
return xhd.signAlgoTransaction(rootKey,
|
|
34
|
+
return xhd.signAlgoTransaction(rootKey, _algorandfoundation_xhd_wallet_api.KeyContext.Address, account, index, bytesToSign, _algorandfoundation_xhd_wallet_api.BIP32DerivationType.Peikert);
|
|
35
35
|
};
|
|
36
36
|
return {
|
|
37
37
|
ed25519Pubkey,
|
|
38
38
|
rawEd25519Signer,
|
|
39
39
|
bip44Path: [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
(0, _algorandfoundation_xhd_wallet_api.harden)(44),
|
|
41
|
+
(0, _algorandfoundation_xhd_wallet_api.harden)(283),
|
|
42
|
+
(0, _algorandfoundation_xhd_wallet_api.harden)(account),
|
|
43
43
|
0,
|
|
44
44
|
index
|
|
45
45
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd.js","names":["
|
|
1
|
+
{"version":3,"file":"hd.js","names":["XHDWalletAPI","KeyContext","BIP32DerivationType"],"sources":["../../../../packages/crypto/src/hd.ts"],"sourcesContent":["import { BIP32DerivationType, fromSeed, KeyContext, XHDWalletAPI, harden } from '@algorandfoundation/xhd-wallet-api'\nimport { RawEd25519Signer } from './ed25519'\n\nexport type BIP44Path = [number, number, number, number, number]\n\nexport type RawHdWalletSigner = (bytesToSign: Uint8Array, bip44Path: BIP44Path) => Promise<Uint8Array>\n\nexport type HdWalletGenerator = (seed?: Uint8Array) => Promise<{\n hdRootKey: Uint8Array\n rawHdSigner: RawHdWalletSigner\n}>\n\nexport type HdAccountGenerator = (\n rootKey: Uint8Array,\n account: number,\n index: number,\n) => Promise<{\n ed25519Pubkey: Uint8Array\n bip44Path: BIP44Path\n rawEd25519Signer: RawEd25519Signer\n}>\n\nconst verifyPath = (bip44Path: BIP44Path) => {\n if (bip44Path.length !== 5) {\n throw new Error('BIP44 path must have exactly 5 elements')\n }\n if (bip44Path[0] !== harden(44)) {\n throw new Error(\"BIP44 path must start with 44'\")\n }\n if (bip44Path[1] !== harden(283)) {\n throw new Error(\"BIP44 path must have hardened coin type 283' for Algorand\")\n }\n}\n\nconst getPathComponents = (bip44Path: BIP44Path) => {\n const account = bip44Path[2]\n const index = bip44Path[4]\n return { account, index }\n}\n\nconst xhd = new XHDWalletAPI()\n\nexport const peikertXHdWalletGenerator: HdWalletGenerator = async (seed?: Uint8Array) => {\n const seedArray = seed ?? new Uint8Array(32)\n if (seed === undefined) {\n crypto.getRandomValues(seedArray)\n }\n\n const rootKey = fromSeed(Buffer.from(seedArray))\n\n const rawHdSigner: RawHdWalletSigner = async (bytesToSign: Uint8Array, bip44Path: BIP44Path): Promise<Uint8Array> => {\n verifyPath(bip44Path)\n const { account, index } = getPathComponents(bip44Path)\n\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign, BIP32DerivationType.Peikert)\n }\n\n return { hdRootKey: rootKey, rawHdSigner }\n}\n\nexport const peikertXHdAccountGenerator: HdAccountGenerator = async (rootKey: Uint8Array, account: number, index: number) => {\n const ed25519Pubkey = await xhd.keyGen(rootKey, KeyContext.Address, account, index, BIP32DerivationType.Peikert)\n\n const rawEd25519Signer: RawEd25519Signer = async (bytesToSign: Uint8Array): Promise<Uint8Array> => {\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign, BIP32DerivationType.Peikert)\n }\n\n const bip44Path: BIP44Path = [harden(44), harden(283), harden(account), 0, index]\n\n return { ed25519Pubkey, rawEd25519Signer, bip44Path }\n}\n"],"mappings":";;;;AAsBA,MAAM,cAAc,cAAyB;AAC3C,KAAI,UAAU,WAAW,EACvB,OAAM,IAAI,MAAM,0CAA0C;AAE5D,KAAI,UAAU,sDAAc,GAAG,CAC7B,OAAM,IAAI,MAAM,iCAAiC;AAEnD,KAAI,UAAU,sDAAc,IAAI,CAC9B,OAAM,IAAI,MAAM,4DAA4D;;AAIhF,MAAM,qBAAqB,cAAyB;AAGlD,QAAO;EAAE,SAFO,UAAU;EAER,OADJ,UAAU;EACC;;AAG3B,MAAM,MAAM,IAAIA,iDAAc;AAE9B,MAAa,4BAA+C,OAAO,SAAsB;CACvF,MAAM,YAAY,QAAQ,IAAI,WAAW,GAAG;AAC5C,KAAI,SAAS,OACX,QAAO,gBAAgB,UAAU;CAGnC,MAAM,2DAAmB,OAAO,KAAK,UAAU,CAAC;CAEhD,MAAM,cAAiC,OAAO,aAAyB,cAA8C;AACnH,aAAW,UAAU;EACrB,MAAM,EAAE,SAAS,UAAU,kBAAkB,UAAU;AAEvD,SAAO,IAAI,oBAAoB,SAASC,8CAAW,SAAS,SAAS,OAAO,aAAaC,uDAAoB,QAAQ;;AAGvH,QAAO;EAAE,WAAW;EAAS;EAAa;;AAG5C,MAAa,6BAAiD,OAAO,SAAqB,SAAiB,UAAkB;CAC3H,MAAM,gBAAgB,MAAM,IAAI,OAAO,SAASD,8CAAW,SAAS,SAAS,OAAOC,uDAAoB,QAAQ;CAEhH,MAAM,mBAAqC,OAAO,gBAAiD;AACjG,SAAO,IAAI,oBAAoB,SAASD,8CAAW,SAAS,SAAS,OAAO,aAAaC,uDAAoB,QAAQ;;AAKvH,QAAO;EAAE;EAAe;EAAkB,WAFb;kDAAQ,GAAG;kDAAS,IAAI;kDAAS,QAAQ;GAAE;GAAG;GAAM;EAE5B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { fromSeed } from "
|
|
2
|
-
import { BIP32DerivationType, KeyContext, XHDWalletAPI, harden } from "../../../node_modules/@algorandfoundation/xhd-wallet-api/dist/x.hd.wallet.api.crypto.mjs";
|
|
1
|
+
import { BIP32DerivationType, KeyContext, XHDWalletAPI, fromSeed, harden } from "@algorandfoundation/xhd-wallet-api";
|
|
3
2
|
|
|
4
3
|
//#region packages/crypto/src/hd.ts
|
|
5
4
|
const verifyPath = (bip44Path) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd.mjs","names":[],"sources":["../../../../packages/crypto/src/hd.ts"],"sourcesContent":["import { BIP32DerivationType, fromSeed, KeyContext, XHDWalletAPI, harden } from '@algorandfoundation/xhd-wallet-api'\nimport { RawEd25519Signer } from './ed25519'\n\nexport type BIP44Path = [number, number, number, number, number]\n\nexport type RawHdWalletSigner = (bytesToSign: Uint8Array, bip44Path: BIP44Path) => Promise<Uint8Array>\n\nexport type HdWalletGenerator = (seed?: Uint8Array) => Promise<{\n hdRootKey: Uint8Array\n rawHdSigner: RawHdWalletSigner\n}>\n\nexport type HdAccountGenerator = (\n rootKey: Uint8Array,\n account: number,\n index: number,\n) => Promise<{\n ed25519Pubkey: Uint8Array\n bip44Path: BIP44Path\n rawEd25519Signer: RawEd25519Signer\n}>\n\nconst verifyPath = (bip44Path: BIP44Path) => {\n if (bip44Path.length !== 5) {\n throw new Error('BIP44 path must have exactly 5 elements')\n }\n if (bip44Path[0] !== harden(44)) {\n throw new Error(\"BIP44 path must start with 44'\")\n }\n if (bip44Path[1] !== harden(283)) {\n throw new Error(\"BIP44 path must have hardened coin type 283' for Algorand\")\n }\n}\n\nconst getPathComponents = (bip44Path: BIP44Path) => {\n const account = bip44Path[2]\n const index = bip44Path[4]\n return { account, index }\n}\n\nconst xhd = new XHDWalletAPI()\n\nexport const peikertXHdWalletGenerator: HdWalletGenerator = async (seed?: Uint8Array) => {\n const seedArray = seed ?? new Uint8Array(32)\n if (seed === undefined) {\n crypto.getRandomValues(seedArray)\n }\n\n const rootKey = fromSeed(Buffer.from(seedArray))\n\n const rawHdSigner: RawHdWalletSigner = async (bytesToSign: Uint8Array, bip44Path: BIP44Path): Promise<Uint8Array> => {\n verifyPath(bip44Path)\n const { account, index } = getPathComponents(bip44Path)\n\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign, BIP32DerivationType.Peikert)\n }\n\n return { hdRootKey: rootKey, rawHdSigner }\n}\n\nexport const peikertXHdAccountGenerator: HdAccountGenerator = async (rootKey: Uint8Array, account: number, index: number) => {\n const ed25519Pubkey = await xhd.keyGen(rootKey, KeyContext.Address, account, index, BIP32DerivationType.Peikert)\n\n const rawEd25519Signer: RawEd25519Signer = async (bytesToSign: Uint8Array): Promise<Uint8Array> => {\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign, BIP32DerivationType.Peikert)\n }\n\n const bip44Path: BIP44Path = [harden(44), harden(283), harden(account), 0, index]\n\n return { ed25519Pubkey, rawEd25519Signer, bip44Path }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hd.mjs","names":[],"sources":["../../../../packages/crypto/src/hd.ts"],"sourcesContent":["import { BIP32DerivationType, fromSeed, KeyContext, XHDWalletAPI, harden } from '@algorandfoundation/xhd-wallet-api'\nimport { RawEd25519Signer } from './ed25519'\n\nexport type BIP44Path = [number, number, number, number, number]\n\nexport type RawHdWalletSigner = (bytesToSign: Uint8Array, bip44Path: BIP44Path) => Promise<Uint8Array>\n\nexport type HdWalletGenerator = (seed?: Uint8Array) => Promise<{\n hdRootKey: Uint8Array\n rawHdSigner: RawHdWalletSigner\n}>\n\nexport type HdAccountGenerator = (\n rootKey: Uint8Array,\n account: number,\n index: number,\n) => Promise<{\n ed25519Pubkey: Uint8Array\n bip44Path: BIP44Path\n rawEd25519Signer: RawEd25519Signer\n}>\n\nconst verifyPath = (bip44Path: BIP44Path) => {\n if (bip44Path.length !== 5) {\n throw new Error('BIP44 path must have exactly 5 elements')\n }\n if (bip44Path[0] !== harden(44)) {\n throw new Error(\"BIP44 path must start with 44'\")\n }\n if (bip44Path[1] !== harden(283)) {\n throw new Error(\"BIP44 path must have hardened coin type 283' for Algorand\")\n }\n}\n\nconst getPathComponents = (bip44Path: BIP44Path) => {\n const account = bip44Path[2]\n const index = bip44Path[4]\n return { account, index }\n}\n\nconst xhd = new XHDWalletAPI()\n\nexport const peikertXHdWalletGenerator: HdWalletGenerator = async (seed?: Uint8Array) => {\n const seedArray = seed ?? new Uint8Array(32)\n if (seed === undefined) {\n crypto.getRandomValues(seedArray)\n }\n\n const rootKey = fromSeed(Buffer.from(seedArray))\n\n const rawHdSigner: RawHdWalletSigner = async (bytesToSign: Uint8Array, bip44Path: BIP44Path): Promise<Uint8Array> => {\n verifyPath(bip44Path)\n const { account, index } = getPathComponents(bip44Path)\n\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign, BIP32DerivationType.Peikert)\n }\n\n return { hdRootKey: rootKey, rawHdSigner }\n}\n\nexport const peikertXHdAccountGenerator: HdAccountGenerator = async (rootKey: Uint8Array, account: number, index: number) => {\n const ed25519Pubkey = await xhd.keyGen(rootKey, KeyContext.Address, account, index, BIP32DerivationType.Peikert)\n\n const rawEd25519Signer: RawEd25519Signer = async (bytesToSign: Uint8Array): Promise<Uint8Array> => {\n return xhd.signAlgoTransaction(rootKey, KeyContext.Address, account, index, bytesToSign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}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
-
value: mod,
|
|
25
|
-
enumerable: true
|
|
26
|
-
}) : target, mod));
|
|
27
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
28
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
29
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { __commonJSMin, __require, __toESM };
|