@getpara/web-sdk 1.4.4 → 1.5.1

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.
@@ -1,4 +1,24 @@
1
1
  "use client";
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
2
22
 
3
23
  // src/wasm/wasm_exec.js
4
24
  (() => {
@@ -473,71 +493,73 @@
473
493
  }
474
494
  };
475
495
  }
476
- async run(instance) {
477
- if (!(instance instanceof WebAssembly.Instance)) {
478
- throw new Error("Go.run: WebAssembly.Instance expected");
479
- }
480
- this._inst = instance;
481
- this.mem = new DataView(this._inst.exports.mem.buffer);
482
- this._values = [
483
- // JS values that Go currently has references to, indexed by reference id
484
- NaN,
485
- 0,
486
- null,
487
- true,
488
- false,
489
- globalThis,
490
- this
491
- ];
492
- this._goRefCounts = new Array(this._values.length).fill(Infinity);
493
- this._ids = /* @__PURE__ */ new Map([
494
- // mapping from JS values to reference ids
495
- [0, 1],
496
- [null, 2],
497
- [true, 3],
498
- [false, 4],
499
- [globalThis, 5],
500
- [this, 6]
501
- ]);
502
- this._idPool = [];
503
- this.exited = false;
504
- let offset = 4096;
505
- const strPtr = (str) => {
506
- const ptr = offset;
507
- const bytes = encoder.encode(str + "\0");
508
- new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
509
- offset += bytes.length;
510
- if (offset % 8 !== 0) {
511
- offset += 8 - offset % 8;
496
+ run(instance) {
497
+ return __async(this, null, function* () {
498
+ if (!(instance instanceof WebAssembly.Instance)) {
499
+ throw new Error("Go.run: WebAssembly.Instance expected");
512
500
  }
513
- return ptr;
514
- };
515
- const argc = this.argv.length;
516
- const argvPtrs = [];
517
- this.argv.forEach((arg) => {
518
- argvPtrs.push(strPtr(arg));
519
- });
520
- argvPtrs.push(0);
521
- const keys = Object.keys(this.env).sort();
522
- keys.forEach((key) => {
523
- argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
524
- });
525
- argvPtrs.push(0);
526
- const argv = offset;
527
- argvPtrs.forEach((ptr) => {
528
- this.mem.setUint32(offset, ptr, true);
529
- this.mem.setUint32(offset + 4, 0, true);
530
- offset += 8;
501
+ this._inst = instance;
502
+ this.mem = new DataView(this._inst.exports.mem.buffer);
503
+ this._values = [
504
+ // JS values that Go currently has references to, indexed by reference id
505
+ NaN,
506
+ 0,
507
+ null,
508
+ true,
509
+ false,
510
+ globalThis,
511
+ this
512
+ ];
513
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
514
+ this._ids = /* @__PURE__ */ new Map([
515
+ // mapping from JS values to reference ids
516
+ [0, 1],
517
+ [null, 2],
518
+ [true, 3],
519
+ [false, 4],
520
+ [globalThis, 5],
521
+ [this, 6]
522
+ ]);
523
+ this._idPool = [];
524
+ this.exited = false;
525
+ let offset = 4096;
526
+ const strPtr = (str) => {
527
+ const ptr = offset;
528
+ const bytes = encoder.encode(str + "\0");
529
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
530
+ offset += bytes.length;
531
+ if (offset % 8 !== 0) {
532
+ offset += 8 - offset % 8;
533
+ }
534
+ return ptr;
535
+ };
536
+ const argc = this.argv.length;
537
+ const argvPtrs = [];
538
+ this.argv.forEach((arg) => {
539
+ argvPtrs.push(strPtr(arg));
540
+ });
541
+ argvPtrs.push(0);
542
+ const keys = Object.keys(this.env).sort();
543
+ keys.forEach((key) => {
544
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
545
+ });
546
+ argvPtrs.push(0);
547
+ const argv = offset;
548
+ argvPtrs.forEach((ptr) => {
549
+ this.mem.setUint32(offset, ptr, true);
550
+ this.mem.setUint32(offset + 4, 0, true);
551
+ offset += 8;
552
+ });
553
+ const wasmMinDataAddr = 4096 + 8192;
554
+ if (offset >= wasmMinDataAddr) {
555
+ throw new Error("total length of command line and environment variables exceeds limit");
556
+ }
557
+ this._inst.exports.run(argc, argv);
558
+ if (this.exited) {
559
+ this._resolveExitPromise();
560
+ }
561
+ yield this._exitPromise;
531
562
  });
532
- const wasmMinDataAddr = 4096 + 8192;
533
- if (offset >= wasmMinDataAddr) {
534
- throw new Error("total length of command line and environment variables exceeds limit");
535
- }
536
- this._inst.exports.run(argc, argv);
537
- if (this.exited) {
538
- this._resolveExitPromise();
539
- }
540
- await this._exitPromise;
541
563
  }
542
564
  _resume() {
543
565
  if (this.exited) {
@@ -564,297 +586,323 @@
564
586
  import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
565
587
  var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
566
588
  var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
567
- async function keygenRequest(ctx, userId, walletId, protocolId) {
568
- const { data } = await ctx.mpcComputationClient.post("/wallets", {
569
- userId,
570
- walletId,
571
- protocolId
589
+ function keygenRequest(ctx, userId, walletId, protocolId) {
590
+ return __async(this, null, function* () {
591
+ const { data } = yield ctx.mpcComputationClient.post("/wallets", {
592
+ userId,
593
+ walletId,
594
+ protocolId
595
+ });
596
+ return data;
572
597
  });
573
- return data;
574
598
  }
575
- async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
576
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
577
- userId,
578
- protocolId,
579
- message,
580
- signer
599
+ function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
600
+ return __async(this, null, function* () {
601
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
602
+ userId,
603
+ protocolId,
604
+ message,
605
+ signer
606
+ });
607
+ return data;
581
608
  });
582
- return data;
583
609
  }
584
- async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
585
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
586
- userId,
587
- protocolId,
588
- transaction,
589
- signer,
590
- chainId
610
+ function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
611
+ return __async(this, null, function* () {
612
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
613
+ userId,
614
+ protocolId,
615
+ transaction,
616
+ signer,
617
+ chainId
618
+ });
619
+ return data;
591
620
  });
592
- return data;
593
- }
594
- async function ed25519Keygen(ctx, userId) {
595
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
596
- scheme: WalletScheme.ED25519,
597
- type: WalletType.SOLANA
598
- });
599
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
600
- try {
601
- const newSigner = await new Promise(
602
- (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
603
- if (err) {
604
- reject(err);
605
- }
606
- resolve(result);
607
- })
608
- );
609
- return { signer: newSigner, walletId };
610
- } catch (e) {
611
- throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
612
- }
613
621
  }
614
- async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
615
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
616
- pregenIdentifier,
617
- pregenIdentifierType,
618
- scheme: WalletScheme.ED25519,
619
- type: WalletType.SOLANA
622
+ function ed25519Keygen(ctx, userId) {
623
+ return __async(this, null, function* () {
624
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
625
+ scheme: WalletScheme.ED25519,
626
+ type: WalletType.SOLANA
627
+ });
628
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
629
+ try {
630
+ const newSigner = yield new Promise(
631
+ (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
632
+ if (err) {
633
+ reject(err);
634
+ }
635
+ resolve(result);
636
+ })
637
+ );
638
+ return { signer: newSigner, walletId };
639
+ } catch (e) {
640
+ throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
641
+ }
620
642
  });
621
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
622
- try {
623
- const newSigner = await new Promise(
624
- (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
625
- if (err) {
626
- reject(err);
627
- }
628
- resolve(result);
629
- })
630
- );
631
- return { signer: newSigner, walletId };
632
- } catch (e) {
633
- throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
634
- }
635
- }
636
- async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
637
- const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
638
- try {
639
- const base64Sig = await new Promise(
640
- (resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
641
- if (err) {
642
- reject(err);
643
- }
644
- resolve(result);
645
- })
646
- );
647
- return { signature: base64Sig };
648
- } catch (e) {
649
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
650
- }
651
643
  }
652
- async function keygen(ctx, userId, type, secretKey) {
653
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
654
- useTwoSigners: true,
655
- scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
656
- type,
657
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
658
- });
659
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
660
- return {
661
- signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
662
- walletId
663
- };
664
- }
665
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
666
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
667
- const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
668
- try {
669
- const newSigner = await new Promise(
670
- (resolve, reject) => createAccountFn(
671
- signerConfigUser,
672
- serverUrl,
673
- protocolId,
674
- secretKey,
675
- () => {
676
- },
677
- // no-op for deprecated callback to update progress percentage
678
- (err, result) => {
644
+ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
645
+ return __async(this, null, function* () {
646
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
647
+ pregenIdentifier,
648
+ pregenIdentifierType,
649
+ scheme: WalletScheme.ED25519,
650
+ type: WalletType.SOLANA
651
+ });
652
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
653
+ try {
654
+ const newSigner = yield new Promise(
655
+ (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
679
656
  if (err) {
680
657
  reject(err);
681
658
  }
682
659
  resolve(result);
683
- }
684
- )
685
- );
686
- return { signer: newSigner, walletId };
687
- } catch (e) {
688
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
689
- }
690
- }
691
- async function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
692
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
693
- pregenIdentifier,
694
- pregenIdentifierType,
695
- type,
696
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
660
+ })
661
+ );
662
+ return { signer: newSigner, walletId };
663
+ } catch (e) {
664
+ throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
665
+ }
697
666
  });
698
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
699
- const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
700
- try {
701
- const newSigner = await new Promise(
702
- (resolve, reject) => globalThis.dklsCreateAccount(
703
- signerConfigUser,
704
- serverUrl,
705
- protocolId,
706
- secretKey,
707
- () => {
708
- },
709
- // no-op for deprecated callback to update progress percentage
710
- (err, result) => {
667
+ }
668
+ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
669
+ return __async(this, null, function* () {
670
+ const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
671
+ try {
672
+ const base64Sig = yield new Promise(
673
+ (resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
711
674
  if (err) {
712
675
  reject(err);
713
676
  }
714
677
  resolve(result);
715
- }
716
- )
717
- );
718
- return { signer: newSigner, walletId };
719
- } catch (e) {
720
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
721
- }
678
+ })
679
+ );
680
+ return { signature: base64Sig };
681
+ } catch (e) {
682
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
683
+ }
684
+ });
722
685
  }
723
- async function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
724
- const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(
725
- userId,
726
- walletId,
727
- message,
728
- null,
729
- cosmosSignDoc
730
- );
731
- if (pendingTransactionId) {
732
- return { pendingTransactionId };
733
- }
734
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
735
- return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
736
- }
737
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
738
- const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
739
- const parsedShare = JSON.parse(share);
740
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
741
- parsedShare.disableWebSockets = ctx.disableWebSockets;
742
- }
743
- share = JSON.stringify(parsedShare);
744
- try {
745
- return await new Promise(
746
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
747
- if (err) {
748
- reject(err);
749
- }
750
- resolve({ signature: result });
751
- })
752
- );
753
- } catch (e) {
754
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
755
- }
686
+ function keygen(ctx, userId, type, secretKey) {
687
+ return __async(this, null, function* () {
688
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
689
+ useTwoSigners: true,
690
+ scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
691
+ type,
692
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
693
+ });
694
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
695
+ return {
696
+ signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
697
+ walletId
698
+ };
699
+ }
700
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
701
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
702
+ const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
703
+ try {
704
+ const newSigner = yield new Promise(
705
+ (resolve, reject) => createAccountFn(
706
+ signerConfigUser,
707
+ serverUrl,
708
+ protocolId,
709
+ secretKey,
710
+ () => {
711
+ },
712
+ // no-op for deprecated callback to update progress percentage
713
+ (err, result) => {
714
+ if (err) {
715
+ reject(err);
716
+ }
717
+ resolve(result);
718
+ }
719
+ )
720
+ );
721
+ return { signer: newSigner, walletId };
722
+ } catch (e) {
723
+ throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
724
+ }
725
+ });
756
726
  }
757
- async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
758
- const {
759
- data: { protocolId, pendingTransactionId }
760
- } = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
761
- if (pendingTransactionId) {
762
- return { pendingTransactionId };
763
- }
764
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
765
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
766
- }
767
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
768
- const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
769
- const parsedShare = JSON.parse(share);
770
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
771
- parsedShare.disableWebSockets = ctx.disableWebSockets;
772
- }
773
- share = JSON.stringify(parsedShare);
774
- try {
775
- return await new Promise(
776
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
777
- if (err) {
778
- reject(err);
779
- }
780
- resolve({ signature: result });
781
- })
782
- );
783
- } catch (e) {
784
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
785
- }
727
+ function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
728
+ return __async(this, null, function* () {
729
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
730
+ pregenIdentifier,
731
+ pregenIdentifierType,
732
+ type,
733
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
734
+ });
735
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
736
+ const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
737
+ try {
738
+ const newSigner = yield new Promise(
739
+ (resolve, reject) => globalThis.dklsCreateAccount(
740
+ signerConfigUser,
741
+ serverUrl,
742
+ protocolId,
743
+ secretKey,
744
+ () => {
745
+ },
746
+ // no-op for deprecated callback to update progress percentage
747
+ (err, result) => {
748
+ if (err) {
749
+ reject(err);
750
+ }
751
+ resolve(result);
752
+ }
753
+ )
754
+ );
755
+ return { signer: newSigner, walletId };
756
+ } catch (e) {
757
+ throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
758
+ }
759
+ });
786
760
  }
787
- async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
788
- const {
789
- data: { protocolId, pendingTransactionId }
790
- } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
791
- if (pendingTransactionId) {
792
- return { pendingTransactionId };
793
- }
794
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
795
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
796
- }
797
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
798
- const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
799
- const parsedShare = JSON.parse(share);
800
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
801
- parsedShare.disableWebSockets = ctx.disableWebSockets;
802
- }
803
- share = JSON.stringify(parsedShare);
804
- try {
805
- return await new Promise(
806
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
807
- if (err) {
808
- reject(err);
809
- }
810
- resolve({ signature: result });
811
- })
761
+ function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
762
+ return __async(this, null, function* () {
763
+ const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(
764
+ userId,
765
+ walletId,
766
+ message,
767
+ null,
768
+ cosmosSignDoc
812
769
  );
813
- } catch (e) {
814
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
815
- }
770
+ if (pendingTransactionId) {
771
+ return { pendingTransactionId };
772
+ }
773
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
774
+ return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
775
+ }
776
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
777
+ const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
778
+ const parsedShare = JSON.parse(share);
779
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
780
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
781
+ }
782
+ share = JSON.stringify(parsedShare);
783
+ try {
784
+ return yield new Promise(
785
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
786
+ if (err) {
787
+ reject(err);
788
+ }
789
+ resolve({ signature: result });
790
+ })
791
+ );
792
+ } catch (e) {
793
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
794
+ }
795
+ });
816
796
  }
817
- async function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
818
- const {
819
- data: { protocolId }
820
- } = await ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
821
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
822
- const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
823
- const parsedShare = JSON.parse(share);
824
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
825
- parsedShare.disableWebSockets = ctx.disableWebSockets;
826
- }
827
- share = JSON.stringify(parsedShare);
828
- try {
829
- return await new Promise(
830
- (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
831
- if (err) {
832
- reject(err);
833
- }
834
- resolve({ protocolId, signer: result });
835
- })
836
- );
837
- } catch (e) {
838
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
839
- }
797
+ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
798
+ return __async(this, null, function* () {
799
+ const {
800
+ data: { protocolId, pendingTransactionId }
801
+ } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
802
+ if (pendingTransactionId) {
803
+ return { pendingTransactionId };
804
+ }
805
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
806
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
807
+ }
808
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
809
+ const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
810
+ const parsedShare = JSON.parse(share);
811
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
812
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
813
+ }
814
+ share = JSON.stringify(parsedShare);
815
+ try {
816
+ return yield new Promise(
817
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
818
+ if (err) {
819
+ reject(err);
820
+ }
821
+ resolve({ signature: result });
822
+ })
823
+ );
824
+ } catch (e) {
825
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
826
+ }
827
+ });
840
828
  }
841
- async function getPrivateKey(ctx, share, walletId, userId) {
842
- const paraShare = await ctx.client.getParaShare(userId, walletId);
843
- if (!paraShare) {
844
- return "";
845
- }
846
- try {
847
- return await new Promise(
848
- (resolve, reject) => globalThis.getPrivateKey(share, paraShare, (err, result) => {
849
- if (err) {
850
- reject(err);
851
- }
852
- resolve(result);
853
- })
854
- );
855
- } catch (e) {
856
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
857
- }
829
+ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
830
+ return __async(this, null, function* () {
831
+ const {
832
+ data: { protocolId, pendingTransactionId }
833
+ } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
834
+ if (pendingTransactionId) {
835
+ return { pendingTransactionId };
836
+ }
837
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
838
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
839
+ }
840
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
841
+ const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
842
+ const parsedShare = JSON.parse(share);
843
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
844
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
845
+ }
846
+ share = JSON.stringify(parsedShare);
847
+ try {
848
+ return yield new Promise(
849
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
850
+ if (err) {
851
+ reject(err);
852
+ }
853
+ resolve({ signature: result });
854
+ })
855
+ );
856
+ } catch (e) {
857
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
858
+ }
859
+ });
860
+ }
861
+ function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
862
+ return __async(this, null, function* () {
863
+ const {
864
+ data: { protocolId }
865
+ } = yield ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
866
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
867
+ const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
868
+ const parsedShare = JSON.parse(share);
869
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
870
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
871
+ }
872
+ share = JSON.stringify(parsedShare);
873
+ try {
874
+ return yield new Promise(
875
+ (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
876
+ if (err) {
877
+ reject(err);
878
+ }
879
+ resolve({ protocolId, signer: result });
880
+ })
881
+ );
882
+ } catch (e) {
883
+ throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
884
+ }
885
+ });
886
+ }
887
+ function getPrivateKey(ctx, share, walletId, userId) {
888
+ return __async(this, null, function* () {
889
+ const paraShare = yield ctx.client.getParaShare(userId, walletId);
890
+ if (!paraShare) {
891
+ return "";
892
+ }
893
+ try {
894
+ return yield new Promise(
895
+ (resolve, reject) => globalThis.getPrivateKey(share, paraShare, (err, result) => {
896
+ if (err) {
897
+ reject(err);
898
+ }
899
+ resolve(result);
900
+ })
901
+ );
902
+ } catch (e) {
903
+ throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
904
+ }
905
+ });
858
906
  }
859
907
 
860
908
  // src/workers/worker.ts
@@ -865,129 +913,135 @@ import {
865
913
  paraVersion,
866
914
  WalletType as WalletType2
867
915
  } from "@getpara/core-sdk";
868
- async function loadWasm(ctx, wasmOverride) {
869
- if (typeof self === "undefined") {
870
- return;
871
- }
872
- const goWasm = new self.Go();
873
- let wasmArrayBuffer = wasmOverride;
874
- if (!wasmArrayBuffer) {
875
- if (process.env.DISABLE_WASM_FETCH === "true") {
876
- throw new Error("fetching wasm file is disabled");
877
- }
878
- const fetchedWasm = await fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
879
- wasmArrayBuffer = await fetchedWasm.arrayBuffer();
880
- }
881
- const newRes = await WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
882
- goWasm.run(newRes.instance);
883
- }
884
- async function executeMessage(ctx, message) {
885
- const { functionType, params, returnObject } = message;
886
- switch (functionType) {
887
- case "KEYGEN": {
888
- const { userId, secretKey, type = WalletType2.EVM } = params;
889
- const keygenRes = await keygen(ctx, userId, type, secretKey);
890
- return keygenRes;
891
- }
892
- case "SIGN_TRANSACTION": {
893
- const { share, walletId, userId, tx, chainId } = params;
894
- return signTransaction(ctx, share, walletId, userId, tx, chainId);
895
- }
896
- case "SEND_TRANSACTION": {
897
- const { share, walletId, userId, tx, chainId } = params;
898
- return sendTransaction(ctx, share, walletId, userId, tx, chainId);
916
+ function loadWasm(ctx, wasmOverride) {
917
+ return __async(this, null, function* () {
918
+ if (typeof self === "undefined") {
919
+ return;
899
920
  }
900
- case "SIGN_MESSAGE": {
901
- const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
902
- return signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
903
- }
904
- case "REFRESH": {
905
- const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
906
- const { protocolId, signer } = await refresh(
907
- ctx,
908
- share,
909
- walletId,
910
- userId,
911
- oldPartnerId,
912
- newPartnerId,
913
- keyShareProtocolId
914
- );
915
- return returnObject ? { protocolId, signer } : signer;
916
- }
917
- case "PREKEYGEN": {
918
- const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
919
- let { pregenIdentifier, pregenIdentifierType } = params;
920
- if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
921
- pregenIdentifier = email;
922
- pregenIdentifierType = "EMAIL";
921
+ const goWasm = new self.Go();
922
+ let wasmArrayBuffer = wasmOverride;
923
+ if (!wasmArrayBuffer) {
924
+ if (process.env.DISABLE_WASM_FETCH === "true") {
925
+ throw new Error("fetching wasm file is disabled");
923
926
  }
924
- const keygenRes = await preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
925
- return keygenRes;
926
- }
927
- case "GET_PRIVATE_KEY": {
928
- const { share, walletId, userId } = params;
929
- return await getPrivateKey(ctx, share, walletId, userId);
930
- }
931
- case "ED25519_KEYGEN": {
932
- const { userId } = params;
933
- return ed25519Keygen(ctx, userId);
934
- }
935
- case "ED25519_SIGN": {
936
- const { share, walletId, userId, base64Bytes } = params;
937
- return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
927
+ const fetchedWasm = yield fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
928
+ wasmArrayBuffer = yield fetchedWasm.arrayBuffer();
938
929
  }
939
- case "ED25519_PREKEYGEN": {
940
- const { email } = params;
941
- let { pregenIdentifier, pregenIdentifierType } = params;
942
- if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
943
- pregenIdentifier = email;
944
- pregenIdentifierType = "EMAIL";
930
+ const newRes = yield WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
931
+ goWasm.run(newRes.instance);
932
+ });
933
+ }
934
+ function executeMessage(ctx, message) {
935
+ return __async(this, null, function* () {
936
+ const { functionType, params, returnObject } = message;
937
+ switch (functionType) {
938
+ case "KEYGEN": {
939
+ const { userId, secretKey, type = WalletType2.EVM } = params;
940
+ const keygenRes = yield keygen(ctx, userId, type, secretKey);
941
+ return keygenRes;
942
+ }
943
+ case "SIGN_TRANSACTION": {
944
+ const { share, walletId, userId, tx, chainId } = params;
945
+ return signTransaction(ctx, share, walletId, userId, tx, chainId);
946
+ }
947
+ case "SEND_TRANSACTION": {
948
+ const { share, walletId, userId, tx, chainId } = params;
949
+ return sendTransaction(ctx, share, walletId, userId, tx, chainId);
950
+ }
951
+ case "SIGN_MESSAGE": {
952
+ const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
953
+ return signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
954
+ }
955
+ case "REFRESH": {
956
+ const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
957
+ const { protocolId, signer } = yield refresh(
958
+ ctx,
959
+ share,
960
+ walletId,
961
+ userId,
962
+ oldPartnerId,
963
+ newPartnerId,
964
+ keyShareProtocolId
965
+ );
966
+ return returnObject ? { protocolId, signer } : signer;
967
+ }
968
+ case "PREKEYGEN": {
969
+ const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
970
+ let { pregenIdentifier, pregenIdentifierType } = params;
971
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
972
+ pregenIdentifier = email;
973
+ pregenIdentifierType = "EMAIL";
974
+ }
975
+ const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
976
+ return keygenRes;
977
+ }
978
+ case "GET_PRIVATE_KEY": {
979
+ const { share, walletId, userId } = params;
980
+ return yield getPrivateKey(ctx, share, walletId, userId);
981
+ }
982
+ case "ED25519_KEYGEN": {
983
+ const { userId } = params;
984
+ return ed25519Keygen(ctx, userId);
985
+ }
986
+ case "ED25519_SIGN": {
987
+ const { share, walletId, userId, base64Bytes } = params;
988
+ return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
989
+ }
990
+ case "ED25519_PREKEYGEN": {
991
+ const { email } = params;
992
+ let { pregenIdentifier, pregenIdentifierType } = params;
993
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
994
+ pregenIdentifier = email;
995
+ pregenIdentifierType = "EMAIL";
996
+ }
997
+ return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
998
+ }
999
+ default: {
1000
+ throw new Error(`functionType: ${functionType} not supported`);
945
1001
  }
946
- return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
947
- }
948
- default: {
949
- throw new Error(`functionType: ${functionType} not supported`);
950
1002
  }
951
- }
1003
+ });
952
1004
  }
953
- async function handleMessage(e, postMessage, useFetchAdapter) {
954
- const {
955
- env,
956
- apiKey,
957
- cosmosPrefix = "cosmos",
958
- offloadMPCComputationURL,
959
- disableWorkers,
960
- sessionCookie,
961
- useDKLS,
962
- disableWebSockets,
963
- wasmOverride
964
- } = e.data;
965
- if (!env) {
966
- return true;
967
- }
968
- const ctx = {
969
- env,
970
- apiKey,
971
- cosmosPrefix,
972
- client: initClient({
1005
+ function handleMessage(e, postMessage, useFetchAdapter) {
1006
+ return __async(this, null, function* () {
1007
+ const {
973
1008
  env,
974
- version: paraVersion,
975
1009
  apiKey,
976
- useFetchAdapter,
977
- retrieveSessionCookie: () => sessionCookie
978
- }),
979
- offloadMPCComputationURL,
980
- mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
981
- useDKLS,
982
- disableWebSockets: !!disableWebSockets,
983
- wasmOverride
984
- };
985
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
986
- await loadWasm(ctx, wasmOverride);
987
- }
988
- const result = await executeMessage(ctx, e.data);
989
- postMessage(result);
990
- return false;
1010
+ cosmosPrefix = "cosmos",
1011
+ offloadMPCComputationURL,
1012
+ disableWorkers,
1013
+ sessionCookie,
1014
+ useDKLS,
1015
+ disableWebSockets,
1016
+ wasmOverride
1017
+ } = e.data;
1018
+ if (!env) {
1019
+ return true;
1020
+ }
1021
+ const ctx = {
1022
+ env,
1023
+ apiKey,
1024
+ cosmosPrefix,
1025
+ client: initClient({
1026
+ env,
1027
+ version: paraVersion,
1028
+ apiKey,
1029
+ useFetchAdapter,
1030
+ retrieveSessionCookie: () => sessionCookie
1031
+ }),
1032
+ offloadMPCComputationURL,
1033
+ mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
1034
+ useDKLS,
1035
+ disableWebSockets: !!disableWebSockets,
1036
+ wasmOverride
1037
+ };
1038
+ if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
1039
+ yield loadWasm(ctx, wasmOverride);
1040
+ }
1041
+ const result = yield executeMessage(ctx, e.data);
1042
+ postMessage(result);
1043
+ return false;
1044
+ });
991
1045
  }
992
1046
  export {
993
1047
  handleMessage