@getpara/web-sdk 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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/index.ts
4
24
  export * from "@getpara/core-sdk";
@@ -552,71 +572,73 @@ import { getPortalBaseURL as getPortalBaseURL2 } from "@getpara/core-sdk";
552
572
  }
553
573
  };
554
574
  }
555
- async run(instance) {
556
- if (!(instance instanceof WebAssembly.Instance)) {
557
- throw new Error("Go.run: WebAssembly.Instance expected");
558
- }
559
- this._inst = instance;
560
- this.mem = new DataView(this._inst.exports.mem.buffer);
561
- this._values = [
562
- // JS values that Go currently has references to, indexed by reference id
563
- NaN,
564
- 0,
565
- null,
566
- true,
567
- false,
568
- globalThis,
569
- this
570
- ];
571
- this._goRefCounts = new Array(this._values.length).fill(Infinity);
572
- this._ids = /* @__PURE__ */ new Map([
573
- // mapping from JS values to reference ids
574
- [0, 1],
575
- [null, 2],
576
- [true, 3],
577
- [false, 4],
578
- [globalThis, 5],
579
- [this, 6]
580
- ]);
581
- this._idPool = [];
582
- this.exited = false;
583
- let offset = 4096;
584
- const strPtr = (str) => {
585
- const ptr = offset;
586
- const bytes = encoder.encode(str + "\0");
587
- new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
588
- offset += bytes.length;
589
- if (offset % 8 !== 0) {
590
- offset += 8 - offset % 8;
575
+ run(instance) {
576
+ return __async(this, null, function* () {
577
+ if (!(instance instanceof WebAssembly.Instance)) {
578
+ throw new Error("Go.run: WebAssembly.Instance expected");
591
579
  }
592
- return ptr;
593
- };
594
- const argc = this.argv.length;
595
- const argvPtrs = [];
596
- this.argv.forEach((arg) => {
597
- argvPtrs.push(strPtr(arg));
598
- });
599
- argvPtrs.push(0);
600
- const keys = Object.keys(this.env).sort();
601
- keys.forEach((key) => {
602
- argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
603
- });
604
- argvPtrs.push(0);
605
- const argv = offset;
606
- argvPtrs.forEach((ptr) => {
607
- this.mem.setUint32(offset, ptr, true);
608
- this.mem.setUint32(offset + 4, 0, true);
609
- offset += 8;
580
+ this._inst = instance;
581
+ this.mem = new DataView(this._inst.exports.mem.buffer);
582
+ this._values = [
583
+ // JS values that Go currently has references to, indexed by reference id
584
+ NaN,
585
+ 0,
586
+ null,
587
+ true,
588
+ false,
589
+ globalThis,
590
+ this
591
+ ];
592
+ this._goRefCounts = new Array(this._values.length).fill(Infinity);
593
+ this._ids = /* @__PURE__ */ new Map([
594
+ // mapping from JS values to reference ids
595
+ [0, 1],
596
+ [null, 2],
597
+ [true, 3],
598
+ [false, 4],
599
+ [globalThis, 5],
600
+ [this, 6]
601
+ ]);
602
+ this._idPool = [];
603
+ this.exited = false;
604
+ let offset = 4096;
605
+ const strPtr = (str) => {
606
+ const ptr = offset;
607
+ const bytes = encoder.encode(str + "\0");
608
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
609
+ offset += bytes.length;
610
+ if (offset % 8 !== 0) {
611
+ offset += 8 - offset % 8;
612
+ }
613
+ return ptr;
614
+ };
615
+ const argc = this.argv.length;
616
+ const argvPtrs = [];
617
+ this.argv.forEach((arg) => {
618
+ argvPtrs.push(strPtr(arg));
619
+ });
620
+ argvPtrs.push(0);
621
+ const keys = Object.keys(this.env).sort();
622
+ keys.forEach((key) => {
623
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
624
+ });
625
+ argvPtrs.push(0);
626
+ const argv = offset;
627
+ argvPtrs.forEach((ptr) => {
628
+ this.mem.setUint32(offset, ptr, true);
629
+ this.mem.setUint32(offset + 4, 0, true);
630
+ offset += 8;
631
+ });
632
+ const wasmMinDataAddr = 4096 + 8192;
633
+ if (offset >= wasmMinDataAddr) {
634
+ throw new Error("total length of command line and environment variables exceeds limit");
635
+ }
636
+ this._inst.exports.run(argc, argv);
637
+ if (this.exited) {
638
+ this._resolveExitPromise();
639
+ }
640
+ yield this._exitPromise;
610
641
  });
611
- const wasmMinDataAddr = 4096 + 8192;
612
- if (offset >= wasmMinDataAddr) {
613
- throw new Error("total length of command line and environment variables exceeds limit");
614
- }
615
- this._inst.exports.run(argc, argv);
616
- if (this.exited) {
617
- this._resolveExitPromise();
618
- }
619
- await this._exitPromise;
620
642
  }
621
643
  _resume() {
622
644
  if (this.exited) {
@@ -643,297 +665,323 @@ import { getPortalBaseURL as getPortalBaseURL2 } from "@getpara/core-sdk";
643
665
  import { getBaseMPCNetworkUrl, WalletScheme, WalletType } from "@getpara/core-sdk";
644
666
  var configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
645
667
  var configDKLSBase = (walletId, id, disableWebSockets) => `{"walletId": "${walletId}", "id":"${id}", "otherId":"CAPSULE", "isReceiver": false, "disableWebSockets": ${disableWebSockets}}`;
646
- async function keygenRequest(ctx, userId, walletId, protocolId) {
647
- const { data } = await ctx.mpcComputationClient.post("/wallets", {
648
- userId,
649
- walletId,
650
- protocolId
651
- });
652
- return data;
653
- }
654
- async function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
655
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
656
- userId,
657
- protocolId,
658
- message,
659
- signer
668
+ function keygenRequest(ctx, userId, walletId, protocolId) {
669
+ return __async(this, null, function* () {
670
+ const { data } = yield ctx.mpcComputationClient.post("/wallets", {
671
+ userId,
672
+ walletId,
673
+ protocolId
674
+ });
675
+ return data;
660
676
  });
661
- return data;
662
677
  }
663
- async function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
664
- const { data } = await ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
665
- userId,
666
- protocolId,
667
- transaction,
668
- signer,
669
- chainId
678
+ function signMessageRequest(ctx, userId, walletId, protocolId, message, signer) {
679
+ return __async(this, null, function* () {
680
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/messages/sign`, {
681
+ userId,
682
+ protocolId,
683
+ message,
684
+ signer
685
+ });
686
+ return data;
670
687
  });
671
- return data;
672
688
  }
673
- async function ed25519Keygen(ctx, userId) {
674
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
675
- scheme: WalletScheme.ED25519,
676
- type: WalletType.SOLANA
689
+ function sendTransactionRequest(ctx, userId, walletId, protocolId, transaction, signer, chainId) {
690
+ return __async(this, null, function* () {
691
+ const { data } = yield ctx.mpcComputationClient.post(`/wallets/${walletId}/transactions/send`, {
692
+ userId,
693
+ protocolId,
694
+ transaction,
695
+ signer,
696
+ chainId
697
+ });
698
+ return data;
677
699
  });
678
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
679
- try {
680
- const newSigner = await new Promise(
681
- (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
682
- if (err) {
683
- reject(err);
684
- }
685
- resolve(result);
686
- })
687
- );
688
- return { signer: newSigner, walletId };
689
- } catch (e) {
690
- throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
691
- }
692
700
  }
693
- async function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
694
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
695
- pregenIdentifier,
696
- pregenIdentifierType,
697
- scheme: WalletScheme.ED25519,
698
- type: WalletType.SOLANA
701
+ function ed25519Keygen(ctx, userId) {
702
+ return __async(this, null, function* () {
703
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
704
+ scheme: WalletScheme.ED25519,
705
+ type: WalletType.SOLANA
706
+ });
707
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
708
+ try {
709
+ const newSigner = yield new Promise(
710
+ (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
711
+ if (err) {
712
+ reject(err);
713
+ }
714
+ resolve(result);
715
+ })
716
+ );
717
+ return { signer: newSigner, walletId };
718
+ } catch (e) {
719
+ throw new Error(`error creating account of type SOLANA with userId ${userId} and walletId ${walletId}`);
720
+ }
699
721
  });
700
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
701
- try {
702
- const newSigner = await new Promise(
703
- (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
704
- if (err) {
705
- reject(err);
706
- }
707
- resolve(result);
708
- })
709
- );
710
- return { signer: newSigner, walletId };
711
- } catch (e) {
712
- throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
713
- }
714
- }
715
- async function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
716
- const { protocolId } = await ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
717
- try {
718
- const base64Sig = await new Promise(
719
- (resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
720
- if (err) {
721
- reject(err);
722
- }
723
- resolve(result);
724
- })
725
- );
726
- return { signature: base64Sig };
727
- } catch (e) {
728
- throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
729
- }
730
722
  }
731
- async function keygen(ctx, userId, type, secretKey) {
732
- const { walletId, protocolId } = await ctx.client.createWallet(userId, {
733
- useTwoSigners: true,
734
- scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
735
- type,
736
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
737
- });
738
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
739
- return {
740
- signer: (await keygenRequest(ctx, userId, walletId, protocolId)).signer,
741
- walletId
742
- };
743
- }
744
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
745
- const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
746
- const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
747
- try {
748
- const newSigner = await new Promise(
749
- (resolve, reject) => createAccountFn(
750
- signerConfigUser,
751
- serverUrl,
752
- protocolId,
753
- secretKey,
754
- () => {
755
- },
756
- // no-op for deprecated callback to update progress percentage
757
- (err, result) => {
723
+ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType) {
724
+ return __async(this, null, function* () {
725
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
726
+ pregenIdentifier,
727
+ pregenIdentifierType,
728
+ scheme: WalletScheme.ED25519,
729
+ type: WalletType.SOLANA
730
+ });
731
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
732
+ try {
733
+ const newSigner = yield new Promise(
734
+ (resolve, reject) => globalThis.ed25519CreateAccount(serverUrl, walletId, protocolId, (err, result) => {
758
735
  if (err) {
759
736
  reject(err);
760
737
  }
761
738
  resolve(result);
762
- }
763
- )
764
- );
765
- return { signer: newSigner, walletId };
766
- } catch (e) {
767
- throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
768
- }
769
- }
770
- async function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
771
- const { walletId, protocolId } = await ctx.client.createPregenWallet({
772
- pregenIdentifier,
773
- pregenIdentifierType,
774
- type,
775
- cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
739
+ })
740
+ );
741
+ return { signer: newSigner, walletId };
742
+ } catch (e) {
743
+ throw new Error(`error creating account of type SOLANA with walletId ${walletId}`);
744
+ }
776
745
  });
777
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
778
- const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
779
- try {
780
- const newSigner = await new Promise(
781
- (resolve, reject) => globalThis.dklsCreateAccount(
782
- signerConfigUser,
783
- serverUrl,
784
- protocolId,
785
- secretKey,
786
- () => {
787
- },
788
- // no-op for deprecated callback to update progress percentage
789
- (err, result) => {
746
+ }
747
+ function ed25519Sign(ctx, share, userId, walletId, base64Bytes) {
748
+ return __async(this, null, function* () {
749
+ const { protocolId } = yield ctx.client.preSignMessage(userId, walletId, base64Bytes, WalletScheme.ED25519);
750
+ try {
751
+ const base64Sig = yield new Promise(
752
+ (resolve, reject) => globalThis.ed25519Sign(share, protocolId, base64Bytes, (err, result) => {
790
753
  if (err) {
791
754
  reject(err);
792
755
  }
793
756
  resolve(result);
794
- }
795
- )
796
- );
797
- return { signer: newSigner, walletId };
798
- } catch (e) {
799
- throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
800
- }
757
+ })
758
+ );
759
+ return { signature: base64Sig };
760
+ } catch (e) {
761
+ throw new Error(`error signing for account of type SOLANA with userId ${userId} and walletId ${walletId}`);
762
+ }
763
+ });
801
764
  }
802
- async function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
803
- const { protocolId, pendingTransactionId } = await ctx.client.preSignMessage(
804
- userId,
805
- walletId,
806
- message,
807
- null,
808
- cosmosSignDoc
809
- );
810
- if (pendingTransactionId) {
811
- return { pendingTransactionId };
812
- }
813
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
814
- return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
815
- }
816
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
817
- const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
818
- const parsedShare = JSON.parse(share);
819
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
820
- parsedShare.disableWebSockets = ctx.disableWebSockets;
821
- }
822
- share = JSON.stringify(parsedShare);
823
- try {
824
- return await new Promise(
825
- (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
826
- if (err) {
827
- reject(err);
828
- }
829
- resolve({ signature: result });
830
- })
831
- );
832
- } catch (e) {
833
- throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
834
- }
765
+ function keygen(ctx, userId, type, secretKey) {
766
+ return __async(this, null, function* () {
767
+ const { walletId, protocolId } = yield ctx.client.createWallet(userId, {
768
+ useTwoSigners: true,
769
+ scheme: ctx.useDKLS ? WalletScheme.DKLS : WalletScheme.CGGMP,
770
+ type,
771
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
772
+ });
773
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
774
+ return {
775
+ signer: (yield keygenRequest(ctx, userId, walletId, protocolId)).signer,
776
+ walletId
777
+ };
778
+ }
779
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
780
+ const signerConfigUser = ctx.useDKLS ? configDKLSBase(walletId, "USER", ctx.disableWebSockets) : configCGGMPBase(serverUrl, walletId, "USER");
781
+ const createAccountFn = ctx.useDKLS ? globalThis.dklsCreateAccount : globalThis.createAccountV2;
782
+ try {
783
+ const newSigner = yield new Promise(
784
+ (resolve, reject) => createAccountFn(
785
+ signerConfigUser,
786
+ serverUrl,
787
+ protocolId,
788
+ secretKey,
789
+ () => {
790
+ },
791
+ // no-op for deprecated callback to update progress percentage
792
+ (err, result) => {
793
+ if (err) {
794
+ reject(err);
795
+ }
796
+ resolve(result);
797
+ }
798
+ )
799
+ );
800
+ return { signer: newSigner, walletId };
801
+ } catch (e) {
802
+ throw new Error(`error creating account of type ${type} with userId ${userId} and walletId ${walletId}`);
803
+ }
804
+ });
835
805
  }
836
- async function signTransaction(ctx, share, walletId, userId, tx, chainId) {
837
- const {
838
- data: { protocolId, pendingTransactionId }
839
- } = await ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
840
- if (pendingTransactionId) {
841
- return { pendingTransactionId };
842
- }
843
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
844
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
845
- }
846
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
847
- const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
848
- const parsedShare = JSON.parse(share);
849
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
850
- parsedShare.disableWebSockets = ctx.disableWebSockets;
851
- }
852
- share = JSON.stringify(parsedShare);
853
- try {
854
- return await new Promise(
855
- (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
856
- if (err) {
857
- reject(err);
858
- }
859
- resolve({ signature: result });
860
- })
861
- );
862
- } catch (e) {
863
- throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
864
- }
806
+ function preKeygen(ctx, _partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey) {
807
+ return __async(this, null, function* () {
808
+ const { walletId, protocolId } = yield ctx.client.createPregenWallet({
809
+ pregenIdentifier,
810
+ pregenIdentifierType,
811
+ type,
812
+ cosmosPrefix: type === WalletType.COSMOS ? ctx.cosmosPrefix : void 0
813
+ });
814
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
815
+ const signerConfigUser = configDKLSBase(walletId, "USER", ctx.disableWebSockets);
816
+ try {
817
+ const newSigner = yield new Promise(
818
+ (resolve, reject) => globalThis.dklsCreateAccount(
819
+ signerConfigUser,
820
+ serverUrl,
821
+ protocolId,
822
+ secretKey,
823
+ () => {
824
+ },
825
+ // no-op for deprecated callback to update progress percentage
826
+ (err, result) => {
827
+ if (err) {
828
+ reject(err);
829
+ }
830
+ resolve(result);
831
+ }
832
+ )
833
+ );
834
+ return { signer: newSigner, walletId };
835
+ } catch (e) {
836
+ throw new Error(`error creating account of type ${type} with walletId ${walletId}`);
837
+ }
838
+ });
865
839
  }
866
- async function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
867
- const {
868
- data: { protocolId, pendingTransactionId }
869
- } = await ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
870
- if (pendingTransactionId) {
871
- return { pendingTransactionId };
872
- }
873
- if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
874
- return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
875
- }
876
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
877
- const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
878
- const parsedShare = JSON.parse(share);
879
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
880
- parsedShare.disableWebSockets = ctx.disableWebSockets;
881
- }
882
- share = JSON.stringify(parsedShare);
883
- try {
884
- return await new Promise(
885
- (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
886
- if (err) {
887
- reject(err);
888
- }
889
- resolve({ signature: result });
890
- })
840
+ function signMessage(ctx, share, walletId, userId, message, cosmosSignDoc) {
841
+ return __async(this, null, function* () {
842
+ const { protocolId, pendingTransactionId } = yield ctx.client.preSignMessage(
843
+ userId,
844
+ walletId,
845
+ message,
846
+ null,
847
+ cosmosSignDoc
891
848
  );
892
- } catch (e) {
893
- throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
894
- }
849
+ if (pendingTransactionId) {
850
+ return { pendingTransactionId };
851
+ }
852
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
853
+ return signMessageRequest(ctx, userId, walletId, protocolId, message, share);
854
+ }
855
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
856
+ const signMessageFn = ctx.useDKLS ? globalThis.dklsSignMessage : globalThis.signMessage;
857
+ const parsedShare = JSON.parse(share);
858
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
859
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
860
+ }
861
+ share = JSON.stringify(parsedShare);
862
+ try {
863
+ return yield new Promise(
864
+ (resolve, reject) => signMessageFn(share, serverUrl, message, protocolId, (err, result) => {
865
+ if (err) {
866
+ reject(err);
867
+ }
868
+ resolve({ signature: result });
869
+ })
870
+ );
871
+ } catch (e) {
872
+ throw new Error(`error signing for account with userId ${userId} and walletId ${walletId}`);
873
+ }
874
+ });
895
875
  }
896
- async function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
897
- const {
898
- data: { protocolId }
899
- } = await ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
900
- const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
901
- const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
902
- const parsedShare = JSON.parse(share);
903
- if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
904
- parsedShare.disableWebSockets = ctx.disableWebSockets;
905
- }
906
- share = JSON.stringify(parsedShare);
907
- try {
908
- return await new Promise(
909
- (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
910
- if (err) {
911
- reject(err);
912
- }
913
- resolve({ protocolId, signer: result });
914
- })
915
- );
916
- } catch (e) {
917
- throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
918
- }
876
+ function signTransaction(ctx, share, walletId, userId, tx, chainId) {
877
+ return __async(this, null, function* () {
878
+ const {
879
+ data: { protocolId, pendingTransactionId }
880
+ } = yield ctx.client.signTransaction(userId, walletId, { transaction: tx, chainId });
881
+ if (pendingTransactionId) {
882
+ return { pendingTransactionId };
883
+ }
884
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
885
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
886
+ }
887
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
888
+ const signTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
889
+ const parsedShare = JSON.parse(share);
890
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
891
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
892
+ }
893
+ share = JSON.stringify(parsedShare);
894
+ try {
895
+ return yield new Promise(
896
+ (resolve, reject) => signTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
897
+ if (err) {
898
+ reject(err);
899
+ }
900
+ resolve({ signature: result });
901
+ })
902
+ );
903
+ } catch (e) {
904
+ throw new Error(`error signing transaction for account with userId ${userId} and walletId ${walletId}`);
905
+ }
906
+ });
919
907
  }
920
- async function getPrivateKey(ctx, share, walletId, userId) {
921
- const paraShare = await ctx.client.getParaShare(userId, walletId);
922
- if (!paraShare) {
923
- return "";
924
- }
925
- try {
926
- return await new Promise(
927
- (resolve, reject) => globalThis.getPrivateKey(share, paraShare, (err, result) => {
928
- if (err) {
929
- reject(err);
930
- }
931
- resolve(result);
932
- })
933
- );
934
- } catch (e) {
935
- throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
936
- }
908
+ function sendTransaction(ctx, share, walletId, userId, tx, chainId) {
909
+ return __async(this, null, function* () {
910
+ const {
911
+ data: { protocolId, pendingTransactionId }
912
+ } = yield ctx.client.sendTransaction(userId, walletId, { transaction: tx, chainId });
913
+ if (pendingTransactionId) {
914
+ return { pendingTransactionId };
915
+ }
916
+ if (ctx.offloadMPCComputationURL && !ctx.useDKLS) {
917
+ return sendTransactionRequest(ctx, userId, walletId, protocolId, tx, share, chainId);
918
+ }
919
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
920
+ const sendTransactionFn = ctx.useDKLS ? globalThis.dklsSendTransaction : globalThis.sendTransaction;
921
+ const parsedShare = JSON.parse(share);
922
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
923
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
924
+ }
925
+ share = JSON.stringify(parsedShare);
926
+ try {
927
+ return yield new Promise(
928
+ (resolve, reject) => sendTransactionFn(share, serverUrl, tx, chainId, protocolId, (err, result) => {
929
+ if (err) {
930
+ reject(err);
931
+ }
932
+ resolve({ signature: result });
933
+ })
934
+ );
935
+ } catch (e) {
936
+ throw new Error(`error signing transaction to send for account with userId ${userId} and walletId ${walletId}`);
937
+ }
938
+ });
939
+ }
940
+ function refresh(ctx, share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId) {
941
+ return __async(this, null, function* () {
942
+ const {
943
+ data: { protocolId }
944
+ } = yield ctx.client.refreshKeys(userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId);
945
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
946
+ const refreshFn = ctx.useDKLS ? globalThis.dklsRefresh : globalThis.refresh;
947
+ const parsedShare = JSON.parse(share);
948
+ if (!parsedShare.disableWebSockets !== !ctx.disableWebSockets) {
949
+ parsedShare.disableWebSockets = ctx.disableWebSockets;
950
+ }
951
+ share = JSON.stringify(parsedShare);
952
+ try {
953
+ return yield new Promise(
954
+ (resolve, reject) => refreshFn(share, serverUrl, protocolId, (err, result) => {
955
+ if (err) {
956
+ reject(err);
957
+ }
958
+ resolve({ protocolId, signer: result });
959
+ })
960
+ );
961
+ } catch (e) {
962
+ throw new Error(`error refreshing keys for account with userId ${userId} and walletId ${walletId}`);
963
+ }
964
+ });
965
+ }
966
+ function getPrivateKey(ctx, share, walletId, userId) {
967
+ return __async(this, null, function* () {
968
+ const paraShare = yield ctx.client.getParaShare(userId, walletId);
969
+ if (!paraShare) {
970
+ return "";
971
+ }
972
+ try {
973
+ return yield new Promise(
974
+ (resolve, reject) => globalThis.getPrivateKey(share, paraShare, (err, result) => {
975
+ if (err) {
976
+ reject(err);
977
+ }
978
+ resolve(result);
979
+ })
980
+ );
981
+ } catch (e) {
982
+ throw new Error(`error getting private key for account with userId ${userId} and walletId ${walletId}`);
983
+ }
984
+ });
937
985
  }
938
986
 
939
987
  // src/workers/worker.ts
@@ -944,185 +992,203 @@ import {
944
992
  paraVersion,
945
993
  WalletType as WalletType2
946
994
  } from "@getpara/core-sdk";
947
- async function loadWasm(ctx, wasmOverride) {
948
- if (typeof self === "undefined") {
949
- return;
950
- }
951
- const goWasm = new self.Go();
952
- let wasmArrayBuffer = wasmOverride;
953
- if (!wasmArrayBuffer) {
954
- if (process.env.DISABLE_WASM_FETCH === "true") {
955
- throw new Error("fetching wasm file is disabled");
956
- }
957
- const fetchedWasm = await fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
958
- wasmArrayBuffer = await fetchedWasm.arrayBuffer();
959
- }
960
- const newRes = await WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
961
- goWasm.run(newRes.instance);
962
- }
963
- async function executeMessage(ctx, message) {
964
- const { functionType, params, returnObject } = message;
965
- switch (functionType) {
966
- case "KEYGEN": {
967
- const { userId, secretKey, type = WalletType2.EVM } = params;
968
- const keygenRes = await keygen(ctx, userId, type, secretKey);
969
- return keygenRes;
970
- }
971
- case "SIGN_TRANSACTION": {
972
- const { share, walletId, userId, tx, chainId } = params;
973
- return signTransaction(ctx, share, walletId, userId, tx, chainId);
974
- }
975
- case "SEND_TRANSACTION": {
976
- const { share, walletId, userId, tx, chainId } = params;
977
- return sendTransaction(ctx, share, walletId, userId, tx, chainId);
978
- }
979
- case "SIGN_MESSAGE": {
980
- const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
981
- return signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
982
- }
983
- case "REFRESH": {
984
- const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
985
- const { protocolId, signer } = await refresh(
986
- ctx,
987
- share,
988
- walletId,
989
- userId,
990
- oldPartnerId,
991
- newPartnerId,
992
- keyShareProtocolId
993
- );
994
- return returnObject ? { protocolId, signer } : signer;
995
+ function loadWasm(ctx, wasmOverride) {
996
+ return __async(this, null, function* () {
997
+ if (typeof self === "undefined") {
998
+ return;
995
999
  }
996
- case "PREKEYGEN": {
997
- const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
998
- let { pregenIdentifier, pregenIdentifierType } = params;
999
- if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
1000
- pregenIdentifier = email;
1001
- pregenIdentifierType = "EMAIL";
1000
+ const goWasm = new self.Go();
1001
+ let wasmArrayBuffer = wasmOverride;
1002
+ if (!wasmArrayBuffer) {
1003
+ if (process.env.DISABLE_WASM_FETCH === "true") {
1004
+ throw new Error("fetching wasm file is disabled");
1002
1005
  }
1003
- const keygenRes = await preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
1004
- return keygenRes;
1006
+ const fetchedWasm = yield fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
1007
+ wasmArrayBuffer = yield fetchedWasm.arrayBuffer();
1005
1008
  }
1006
- case "GET_PRIVATE_KEY": {
1007
- const { share, walletId, userId } = params;
1008
- return await getPrivateKey(ctx, share, walletId, userId);
1009
- }
1010
- case "ED25519_KEYGEN": {
1011
- const { userId } = params;
1012
- return ed25519Keygen(ctx, userId);
1013
- }
1014
- case "ED25519_SIGN": {
1015
- const { share, walletId, userId, base64Bytes } = params;
1016
- return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
1017
- }
1018
- case "ED25519_PREKEYGEN": {
1019
- const { email } = params;
1020
- let { pregenIdentifier, pregenIdentifierType } = params;
1021
- if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
1022
- pregenIdentifier = email;
1023
- pregenIdentifierType = "EMAIL";
1009
+ const newRes = yield WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
1010
+ goWasm.run(newRes.instance);
1011
+ });
1012
+ }
1013
+ function executeMessage(ctx, message) {
1014
+ return __async(this, null, function* () {
1015
+ const { functionType, params, returnObject } = message;
1016
+ switch (functionType) {
1017
+ case "KEYGEN": {
1018
+ const { userId, secretKey, type = WalletType2.EVM } = params;
1019
+ const keygenRes = yield keygen(ctx, userId, type, secretKey);
1020
+ return keygenRes;
1021
+ }
1022
+ case "SIGN_TRANSACTION": {
1023
+ const { share, walletId, userId, tx, chainId } = params;
1024
+ return signTransaction(ctx, share, walletId, userId, tx, chainId);
1025
+ }
1026
+ case "SEND_TRANSACTION": {
1027
+ const { share, walletId, userId, tx, chainId } = params;
1028
+ return sendTransaction(ctx, share, walletId, userId, tx, chainId);
1029
+ }
1030
+ case "SIGN_MESSAGE": {
1031
+ const { share, walletId, userId, message: message2, cosmosSignDoc } = params;
1032
+ return signMessage(ctx, share, walletId, userId, message2, cosmosSignDoc);
1033
+ }
1034
+ case "REFRESH": {
1035
+ const { share, walletId, userId, oldPartnerId, newPartnerId, keyShareProtocolId } = params;
1036
+ const { protocolId, signer } = yield refresh(
1037
+ ctx,
1038
+ share,
1039
+ walletId,
1040
+ userId,
1041
+ oldPartnerId,
1042
+ newPartnerId,
1043
+ keyShareProtocolId
1044
+ );
1045
+ return returnObject ? { protocolId, signer } : signer;
1046
+ }
1047
+ case "PREKEYGEN": {
1048
+ const { email, partnerId, secretKey, type = WalletType2.EVM } = params;
1049
+ let { pregenIdentifier, pregenIdentifierType } = params;
1050
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
1051
+ pregenIdentifier = email;
1052
+ pregenIdentifierType = "EMAIL";
1053
+ }
1054
+ const keygenRes = yield preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey);
1055
+ return keygenRes;
1056
+ }
1057
+ case "GET_PRIVATE_KEY": {
1058
+ const { share, walletId, userId } = params;
1059
+ return yield getPrivateKey(ctx, share, walletId, userId);
1060
+ }
1061
+ case "ED25519_KEYGEN": {
1062
+ const { userId } = params;
1063
+ return ed25519Keygen(ctx, userId);
1064
+ }
1065
+ case "ED25519_SIGN": {
1066
+ const { share, walletId, userId, base64Bytes } = params;
1067
+ return ed25519Sign(ctx, share, userId, walletId, base64Bytes);
1068
+ }
1069
+ case "ED25519_PREKEYGEN": {
1070
+ const { email } = params;
1071
+ let { pregenIdentifier, pregenIdentifierType } = params;
1072
+ if (email !== "null" && email !== "undefined" && email !== "" && email != null) {
1073
+ pregenIdentifier = email;
1074
+ pregenIdentifierType = "EMAIL";
1075
+ }
1076
+ return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
1077
+ }
1078
+ default: {
1079
+ throw new Error(`functionType: ${functionType} not supported`);
1024
1080
  }
1025
- return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType);
1026
- }
1027
- default: {
1028
- throw new Error(`functionType: ${functionType} not supported`);
1029
1081
  }
1030
- }
1082
+ });
1031
1083
  }
1032
- async function handleMessage(e, postMessage, useFetchAdapter) {
1033
- const {
1034
- env,
1035
- apiKey,
1036
- cosmosPrefix = "cosmos",
1037
- offloadMPCComputationURL,
1038
- disableWorkers,
1039
- sessionCookie,
1040
- useDKLS,
1041
- disableWebSockets,
1042
- wasmOverride
1043
- } = e.data;
1044
- if (!env) {
1045
- return true;
1046
- }
1047
- const ctx = {
1048
- env,
1049
- apiKey,
1050
- cosmosPrefix,
1051
- client: initClient({
1084
+ function handleMessage(e, postMessage, useFetchAdapter) {
1085
+ return __async(this, null, function* () {
1086
+ const {
1052
1087
  env,
1053
- version: paraVersion,
1054
1088
  apiKey,
1055
- useFetchAdapter,
1056
- retrieveSessionCookie: () => sessionCookie
1057
- }),
1058
- offloadMPCComputationURL,
1059
- mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
1060
- useDKLS,
1061
- disableWebSockets: !!disableWebSockets,
1062
- wasmOverride
1063
- };
1064
- if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
1065
- await loadWasm(ctx, wasmOverride);
1066
- }
1067
- const result = await executeMessage(ctx, e.data);
1068
- postMessage(result);
1069
- return false;
1089
+ cosmosPrefix = "cosmos",
1090
+ offloadMPCComputationURL,
1091
+ disableWorkers,
1092
+ sessionCookie,
1093
+ useDKLS,
1094
+ disableWebSockets,
1095
+ wasmOverride
1096
+ } = e.data;
1097
+ if (!env) {
1098
+ return true;
1099
+ }
1100
+ const ctx = {
1101
+ env,
1102
+ apiKey,
1103
+ cosmosPrefix,
1104
+ client: initClient({
1105
+ env,
1106
+ version: paraVersion,
1107
+ apiKey,
1108
+ useFetchAdapter,
1109
+ retrieveSessionCookie: () => sessionCookie
1110
+ }),
1111
+ offloadMPCComputationURL,
1112
+ mpcComputationClient: offloadMPCComputationURL ? mpcComputationClient.initClient(offloadMPCComputationURL, !!disableWorkers) : void 0,
1113
+ useDKLS,
1114
+ disableWebSockets: !!disableWebSockets,
1115
+ wasmOverride
1116
+ };
1117
+ if (!ctx.offloadMPCComputationURL || ctx.useDKLS) {
1118
+ yield loadWasm(ctx, wasmOverride);
1119
+ }
1120
+ const result = yield executeMessage(ctx, e.data);
1121
+ postMessage(result);
1122
+ return false;
1123
+ });
1070
1124
  }
1071
1125
 
1072
1126
  // src/workers/workerWrapper.ts
1073
- async function setupWorker(ctx, resFunction) {
1074
- const onmessage = (event) => {
1075
- if (event.data.functionType === "CUSTOM") {
1076
- return;
1077
- }
1078
- resFunction(event.data);
1079
- };
1080
- if (ctx.disableWorkers) {
1081
- const syncWorker = {
1082
- postMessage: function(message) {
1083
- (async function() {
1084
- await handleMessage({ data: message }, (data) => onmessage({ data }), ctx.disableWorkers);
1085
- })();
1086
- },
1087
- terminate: () => {
1127
+ function setupWorker(ctx, resFunction) {
1128
+ return __async(this, null, function* () {
1129
+ const onmessage = (event) => {
1130
+ if (event.data.functionType === "CUSTOM") {
1088
1131
  return;
1089
1132
  }
1133
+ resFunction(event.data);
1090
1134
  };
1091
- return syncWorker;
1092
- }
1093
- let worker;
1094
- if (ctx.useLocalFiles) {
1095
- throw new Error("useLocalFiles only supported locally");
1096
- } else {
1097
- const workerRes = await fetch(`${getPortalBaseURL2(ctx)}/static/js/mpcWorker-bundle.js`);
1098
- const workerBlob = new Blob([await workerRes.text()], { type: "application/javascript" });
1099
- const workerScriptURL = URL.createObjectURL(workerBlob);
1100
- worker = new Worker(workerScriptURL);
1101
- }
1102
- worker.onmessage = onmessage;
1103
- return worker;
1135
+ if (ctx.disableWorkers) {
1136
+ const syncWorker = {
1137
+ postMessage: function(message) {
1138
+ (function() {
1139
+ return __async(this, null, function* () {
1140
+ yield handleMessage({ data: message }, (data) => onmessage({ data }), ctx.disableWorkers);
1141
+ });
1142
+ })();
1143
+ },
1144
+ terminate: () => {
1145
+ return;
1146
+ }
1147
+ };
1148
+ return syncWorker;
1149
+ }
1150
+ let worker;
1151
+ if (ctx.useLocalFiles) {
1152
+ throw new Error("useLocalFiles only supported locally");
1153
+ } else {
1154
+ const workerRes = yield fetch(`${getPortalBaseURL2(ctx)}/static/js/mpcWorker-bundle.js`);
1155
+ const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
1156
+ const workerScriptURL = URL.createObjectURL(workerBlob);
1157
+ worker = new Worker(workerScriptURL);
1158
+ }
1159
+ worker.onmessage = onmessage;
1160
+ return worker;
1161
+ });
1104
1162
  }
1105
1163
 
1106
1164
  // src/wallet/keygen.ts
1107
1165
  import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
1108
- async function isKeygenComplete(ctx, userId, walletId) {
1109
- const wallets = await ctx.client.getWallets(userId);
1110
- const wallet = wallets.data.wallets.find((w) => w.id === walletId);
1111
- return !!wallet.address;
1166
+ function isKeygenComplete(ctx, userId, walletId) {
1167
+ return __async(this, null, function* () {
1168
+ const wallets = yield ctx.client.getWallets(userId);
1169
+ const wallet = wallets.data.wallets.find((w) => w.id === walletId);
1170
+ return !!wallet.address;
1171
+ });
1112
1172
  }
1113
- async function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
1114
- const { isDone } = await ctx.client.isRefreshDone(userId, walletId, partnerId, protocolId);
1115
- return isDone;
1173
+ function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
1174
+ return __async(this, null, function* () {
1175
+ const { isDone } = yield ctx.client.isRefreshDone(userId, walletId, partnerId, protocolId);
1176
+ return isDone;
1177
+ });
1116
1178
  }
1117
- async function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
1118
- const wallets = await ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
1119
- const wallet = wallets.wallets.find((w) => w.id === walletId);
1120
- return !!wallet.address;
1179
+ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
1180
+ return __async(this, null, function* () {
1181
+ const wallets = yield ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
1182
+ const wallet = wallets.wallets.find((w) => w.id === walletId);
1183
+ return !!wallet.address;
1184
+ });
1121
1185
  }
1122
1186
  function keygen2(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
1123
- return new Promise(async (resolve) => {
1124
- const worker = await setupWorker(ctx, async (res) => {
1125
- await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
1187
+ return new Promise((resolve) => __async(this, null, function* () {
1188
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1189
+ yield waitUntilTrue(() => __async(this, null, function* () {
1190
+ return isKeygenComplete(ctx, userId, res.walletId);
1191
+ }), 15e3, 1e3);
1126
1192
  if (skipDistribute) {
1127
1193
  resolve({
1128
1194
  signer: res.signer,
@@ -1132,7 +1198,7 @@ function keygen2(ctx, userId, type, secretKey, skipDistribute = false, sessionCo
1132
1198
  worker.terminate();
1133
1199
  return;
1134
1200
  }
1135
- const recoveryShare = await distributeNewShare({
1201
+ const recoveryShare = yield distributeNewShare({
1136
1202
  ctx,
1137
1203
  userId,
1138
1204
  walletId: res.walletId,
@@ -1145,7 +1211,7 @@ function keygen2(ctx, userId, type, secretKey, skipDistribute = false, sessionCo
1145
1211
  recoveryShare
1146
1212
  });
1147
1213
  worker.terminate();
1148
- });
1214
+ }));
1149
1215
  worker.postMessage({
1150
1216
  env: ctx.env,
1151
1217
  apiKey: ctx.apiKey,
@@ -1159,13 +1225,15 @@ function keygen2(ctx, userId, type, secretKey, skipDistribute = false, sessionCo
1159
1225
  disableWebSockets: ctx.disableWebSockets,
1160
1226
  wasmOverride: ctx.wasmOverride
1161
1227
  });
1162
- });
1228
+ }));
1163
1229
  }
1164
1230
  function preKeygen2(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
1165
- return new Promise(async (resolve) => {
1166
- const worker = await setupWorker(ctx, async (res) => {
1167
- await waitUntilTrue(
1168
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
1231
+ return new Promise((resolve) => __async(this, null, function* () {
1232
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1233
+ yield waitUntilTrue(
1234
+ () => __async(this, null, function* () {
1235
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
1236
+ }),
1169
1237
  15e3,
1170
1238
  1e3
1171
1239
  );
@@ -1175,7 +1243,7 @@ function preKeygen2(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey
1175
1243
  recoveryShare: null
1176
1244
  });
1177
1245
  worker.terminate();
1178
- });
1246
+ }));
1179
1247
  const email = void 0;
1180
1248
  const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
1181
1249
  if (pregenIdentifierType === "EMAIL") {
@@ -1194,12 +1262,14 @@ function preKeygen2(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey
1194
1262
  disableWebSockets: ctx.disableWebSockets,
1195
1263
  wasmOverride: ctx.wasmOverride
1196
1264
  });
1197
- });
1265
+ }));
1198
1266
  }
1199
1267
  function refresh2(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
1200
- return new Promise(async (resolve) => {
1201
- const worker = await setupWorker(ctx, async (res) => {
1202
- if (!await waitUntilTrue(async () => isRefreshComplete(ctx, userId, walletId, newPartnerId), 15e3, 1e3)) {
1268
+ return new Promise((resolve) => __async(this, null, function* () {
1269
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1270
+ if (!(yield waitUntilTrue(() => __async(this, null, function* () {
1271
+ return isRefreshComplete(ctx, userId, walletId, newPartnerId);
1272
+ }), 15e3, 1e3))) {
1203
1273
  throw new Error("refresh failed");
1204
1274
  }
1205
1275
  const { protocolId, signer } = res;
@@ -1208,7 +1278,7 @@ function refresh2(ctx, sessionCookie, userId, walletId, share, oldPartnerId, new
1208
1278
  protocolId
1209
1279
  });
1210
1280
  worker.terminate();
1211
- });
1281
+ }));
1212
1282
  worker.postMessage({
1213
1283
  env: ctx.env,
1214
1284
  apiKey: ctx.apiKey,
@@ -1221,19 +1291,21 @@ function refresh2(ctx, sessionCookie, userId, walletId, share, oldPartnerId, new
1221
1291
  wasmOverride: ctx.wasmOverride,
1222
1292
  returnObject: true
1223
1293
  });
1224
- });
1294
+ }));
1225
1295
  }
1226
1296
  function ed25519Keygen2(ctx, userId, sessionCookie, _emailProps = {}) {
1227
- return new Promise(async (resolve) => {
1228
- const worker = await setupWorker(ctx, async (res) => {
1229
- await waitUntilTrue(async () => isKeygenComplete(ctx, userId, res.walletId), 15e3, 1e3);
1297
+ return new Promise((resolve) => __async(this, null, function* () {
1298
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1299
+ yield waitUntilTrue(() => __async(this, null, function* () {
1300
+ return isKeygenComplete(ctx, userId, res.walletId);
1301
+ }), 15e3, 1e3);
1230
1302
  resolve({
1231
1303
  signer: res.signer,
1232
1304
  walletId: res.walletId,
1233
1305
  recoveryShare: null
1234
1306
  });
1235
1307
  worker.terminate();
1236
- });
1308
+ }));
1237
1309
  worker.postMessage({
1238
1310
  env: ctx.env,
1239
1311
  apiKey: ctx.apiKey,
@@ -1245,13 +1317,15 @@ function ed25519Keygen2(ctx, userId, sessionCookie, _emailProps = {}) {
1245
1317
  disableWebSockets: ctx.disableWebSockets,
1246
1318
  wasmOverride: ctx.wasmOverride
1247
1319
  });
1248
- });
1320
+ }));
1249
1321
  }
1250
1322
  function ed25519PreKeygen2(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
1251
- return new Promise(async (resolve) => {
1252
- const worker = await setupWorker(ctx, async (res) => {
1253
- await waitUntilTrue(
1254
- async () => isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId),
1323
+ return new Promise((resolve) => __async(this, null, function* () {
1324
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1325
+ yield waitUntilTrue(
1326
+ () => __async(this, null, function* () {
1327
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
1328
+ }),
1255
1329
  15e3,
1256
1330
  1e3
1257
1331
  );
@@ -1261,7 +1335,7 @@ function ed25519PreKeygen2(ctx, pregenIdentifier, pregenIdentifierType, sessionC
1261
1335
  recoveryShare: null
1262
1336
  });
1263
1337
  worker.terminate();
1264
- });
1338
+ }));
1265
1339
  const email = void 0;
1266
1340
  const params = { pregenIdentifier, pregenIdentifierType, email };
1267
1341
  if (pregenIdentifierType === "EMAIL") {
@@ -1278,113 +1352,123 @@ function ed25519PreKeygen2(ctx, pregenIdentifier, pregenIdentifierType, sessionC
1278
1352
  disableWebSockets: ctx.disableWebSockets,
1279
1353
  wasmOverride: ctx.wasmOverride
1280
1354
  });
1281
- });
1355
+ }));
1282
1356
  }
1283
1357
 
1284
1358
  // src/wallet/signing.ts
1285
- async function signTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
1286
- return await new Promise(async (resolve) => {
1287
- const worker = await setupWorker(ctx, async (sendTransactionRes) => {
1288
- resolve(sendTransactionRes);
1289
- worker.terminate();
1290
- });
1291
- worker.postMessage({
1292
- env: ctx.env,
1293
- apiKey: ctx.apiKey,
1294
- cosmosPrefix: ctx.cosmosPrefix,
1295
- params: { share, walletId, userId, tx, chainId },
1296
- functionType: "SIGN_TRANSACTION",
1297
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1298
- disableWorkers: ctx.disableWorkers,
1299
- sessionCookie,
1300
- useDKLS: isDKLS,
1301
- disableWebSockets: ctx.disableWebSockets,
1302
- wasmOverride: ctx.wasmOverride
1303
- });
1359
+ function signTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
1360
+ return __async(this, null, function* () {
1361
+ return yield new Promise((resolve) => __async(this, null, function* () {
1362
+ const worker = yield setupWorker(ctx, (sendTransactionRes) => __async(this, null, function* () {
1363
+ resolve(sendTransactionRes);
1364
+ worker.terminate();
1365
+ }));
1366
+ worker.postMessage({
1367
+ env: ctx.env,
1368
+ apiKey: ctx.apiKey,
1369
+ cosmosPrefix: ctx.cosmosPrefix,
1370
+ params: { share, walletId, userId, tx, chainId },
1371
+ functionType: "SIGN_TRANSACTION",
1372
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1373
+ disableWorkers: ctx.disableWorkers,
1374
+ sessionCookie,
1375
+ useDKLS: isDKLS,
1376
+ disableWebSockets: ctx.disableWebSockets,
1377
+ wasmOverride: ctx.wasmOverride
1378
+ });
1379
+ }));
1304
1380
  });
1305
1381
  }
1306
- async function sendTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
1307
- return await new Promise(async (resolve) => {
1308
- const worker = await setupWorker(ctx, async (sendTransactionRes) => {
1309
- resolve(sendTransactionRes);
1310
- worker.terminate();
1311
- });
1312
- worker.postMessage({
1313
- env: ctx.env,
1314
- apiKey: ctx.apiKey,
1315
- cosmosPrefix: ctx.cosmosPrefix,
1316
- params: { share, walletId, userId, tx, chainId },
1317
- functionType: "SEND_TRANSACTION",
1318
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1319
- disableWorkers: ctx.disableWorkers,
1320
- sessionCookie,
1321
- useDKLS: isDKLS,
1322
- disableWebSockets: ctx.disableWebSockets,
1323
- wasmOverride: ctx.wasmOverride
1324
- });
1382
+ function sendTransaction2(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
1383
+ return __async(this, null, function* () {
1384
+ return yield new Promise((resolve) => __async(this, null, function* () {
1385
+ const worker = yield setupWorker(ctx, (sendTransactionRes) => __async(this, null, function* () {
1386
+ resolve(sendTransactionRes);
1387
+ worker.terminate();
1388
+ }));
1389
+ worker.postMessage({
1390
+ env: ctx.env,
1391
+ apiKey: ctx.apiKey,
1392
+ cosmosPrefix: ctx.cosmosPrefix,
1393
+ params: { share, walletId, userId, tx, chainId },
1394
+ functionType: "SEND_TRANSACTION",
1395
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1396
+ disableWorkers: ctx.disableWorkers,
1397
+ sessionCookie,
1398
+ useDKLS: isDKLS,
1399
+ disableWebSockets: ctx.disableWebSockets,
1400
+ wasmOverride: ctx.wasmOverride
1401
+ });
1402
+ }));
1325
1403
  });
1326
1404
  }
1327
- async function signMessage2(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
1328
- return await new Promise(async (resolve) => {
1329
- const worker = await setupWorker(ctx, async (signMessageRes) => {
1330
- resolve(signMessageRes);
1331
- worker.terminate();
1332
- });
1333
- worker.postMessage({
1334
- env: ctx.env,
1335
- apiKey: ctx.apiKey,
1336
- cosmosPrefix: ctx.cosmosPrefix,
1337
- params: { share, walletId, userId, message, cosmosSignDoc },
1338
- functionType: "SIGN_MESSAGE",
1339
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1340
- disableWorkers: ctx.disableWorkers,
1341
- sessionCookie,
1342
- useDKLS: isDKLS,
1343
- disableWebSockets: ctx.disableWebSockets,
1344
- wasmOverride: ctx.wasmOverride
1345
- });
1405
+ function signMessage2(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
1406
+ return __async(this, null, function* () {
1407
+ return yield new Promise((resolve) => __async(this, null, function* () {
1408
+ const worker = yield setupWorker(ctx, (signMessageRes) => __async(this, null, function* () {
1409
+ resolve(signMessageRes);
1410
+ worker.terminate();
1411
+ }));
1412
+ worker.postMessage({
1413
+ env: ctx.env,
1414
+ apiKey: ctx.apiKey,
1415
+ cosmosPrefix: ctx.cosmosPrefix,
1416
+ params: { share, walletId, userId, message, cosmosSignDoc },
1417
+ functionType: "SIGN_MESSAGE",
1418
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1419
+ disableWorkers: ctx.disableWorkers,
1420
+ sessionCookie,
1421
+ useDKLS: isDKLS,
1422
+ disableWebSockets: ctx.disableWebSockets,
1423
+ wasmOverride: ctx.wasmOverride
1424
+ });
1425
+ }));
1346
1426
  });
1347
1427
  }
1348
- async function ed25519Sign2(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
1349
- return await new Promise(async (resolve) => {
1350
- const worker = await setupWorker(ctx, async (signMessageRes) => {
1351
- resolve(signMessageRes);
1352
- worker.terminate();
1353
- });
1354
- worker.postMessage({
1355
- env: ctx.env,
1356
- apiKey: ctx.apiKey,
1357
- cosmosPrefix: ctx.cosmosPrefix,
1358
- params: { share, walletId, userId, base64Bytes },
1359
- functionType: "ED25519_SIGN",
1360
- disableWorkers: ctx.disableWorkers,
1361
- sessionCookie,
1362
- disableWebSockets: ctx.disableWebSockets,
1363
- wasmOverride: ctx.wasmOverride
1364
- });
1428
+ function ed25519Sign2(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
1429
+ return __async(this, null, function* () {
1430
+ return yield new Promise((resolve) => __async(this, null, function* () {
1431
+ const worker = yield setupWorker(ctx, (signMessageRes) => __async(this, null, function* () {
1432
+ resolve(signMessageRes);
1433
+ worker.terminate();
1434
+ }));
1435
+ worker.postMessage({
1436
+ env: ctx.env,
1437
+ apiKey: ctx.apiKey,
1438
+ cosmosPrefix: ctx.cosmosPrefix,
1439
+ params: { share, walletId, userId, base64Bytes },
1440
+ functionType: "ED25519_SIGN",
1441
+ disableWorkers: ctx.disableWorkers,
1442
+ sessionCookie,
1443
+ disableWebSockets: ctx.disableWebSockets,
1444
+ wasmOverride: ctx.wasmOverride
1445
+ });
1446
+ }));
1365
1447
  });
1366
1448
  }
1367
1449
 
1368
1450
  // src/wallet/privateKey.ts
1369
- async function getPrivateKey2(ctx, userId, walletId, share, sessionCookie) {
1370
- return await new Promise(async (resolve) => {
1371
- const worker = await setupWorker(ctx, async (res) => {
1372
- resolve(res);
1373
- worker.terminate();
1374
- });
1375
- worker.postMessage({
1376
- env: ctx.env,
1377
- apiKey: ctx.apiKey,
1378
- cosmosPrefix: ctx.cosmosPrefix,
1379
- params: { share, walletId, userId },
1380
- functionType: "GET_PRIVATE_KEY",
1381
- offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1382
- disableWorkers: ctx.disableWorkers,
1383
- sessionCookie,
1384
- useDKLS: ctx.useDKLS,
1385
- disableWebSockets: ctx.disableWebSockets,
1386
- wasmOverride: ctx.wasmOverride
1387
- });
1451
+ function getPrivateKey2(ctx, userId, walletId, share, sessionCookie) {
1452
+ return __async(this, null, function* () {
1453
+ return yield new Promise((resolve) => __async(this, null, function* () {
1454
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
1455
+ resolve(res);
1456
+ worker.terminate();
1457
+ }));
1458
+ worker.postMessage({
1459
+ env: ctx.env,
1460
+ apiKey: ctx.apiKey,
1461
+ cosmosPrefix: ctx.cosmosPrefix,
1462
+ params: { share, walletId, userId },
1463
+ functionType: "GET_PRIVATE_KEY",
1464
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
1465
+ disableWorkers: ctx.disableWorkers,
1466
+ sessionCookie,
1467
+ useDKLS: ctx.useDKLS,
1468
+ disableWebSockets: ctx.disableWebSockets,
1469
+ wasmOverride: ctx.wasmOverride
1470
+ });
1471
+ }));
1388
1472
  });
1389
1473
  }
1390
1474
 
@@ -1518,7 +1602,7 @@ import { getPortalDomain } from "@getpara/core-sdk";
1518
1602
  var ES256_ALGORITHM = -7;
1519
1603
  var RS256_ALGORITHM = -257;
1520
1604
  function publicKeyCredentialToJSON(pubKeyCred) {
1521
- if (pubKeyCred instanceof ArrayBuffer) {
1605
+ if (pubKeyCred instanceof ArrayBuffer || ArrayBuffer.isView(pubKeyCred)) {
1522
1606
  return base64url.encode(pubKeyCred);
1523
1607
  } else if (pubKeyCred instanceof Array) {
1524
1608
  return pubKeyCred.map(publicKeyCredentialToJSON);
@@ -1602,63 +1686,67 @@ function generateUserHandle() {
1602
1686
  window.crypto.getRandomValues(userHandle);
1603
1687
  return userHandle;
1604
1688
  }
1605
- async function createCredential(env, userId, identifier, isE2E) {
1606
- if (typeof navigator === "undefined") {
1607
- return;
1608
- }
1609
- const userHandle = generateUserHandle();
1610
- const createCredentialDefaultArgs = {
1611
- publicKey: {
1612
- authenticatorSelection: {
1613
- authenticatorAttachment: "platform",
1614
- requireResidentKey: true,
1615
- residentKey: "required",
1616
- userVerification: "required"
1617
- },
1618
- rp: {
1619
- id: getPortalDomain(env, isE2E),
1620
- name: "Para"
1621
- },
1622
- user: {
1623
- id: userHandle,
1624
- name: identifier,
1625
- displayName: identifier
1626
- },
1627
- pubKeyCredParams: [
1628
- { type: "public-key", alg: ES256_ALGORITHM },
1629
- // RS256_ALGORITHM should only be needed for windows hello
1630
- { type: "public-key", alg: RS256_ALGORITHM }
1631
- ],
1632
- attestation: "direct",
1633
- timeout: 6e4,
1634
- // TODO: don't think we really get value from verifying this, but should revisit
1635
- challenge: Buffer.from(userId, "utf-8")
1689
+ function createCredential(env, userId, identifier, isE2E) {
1690
+ return __async(this, null, function* () {
1691
+ if (typeof navigator === "undefined") {
1692
+ return;
1636
1693
  }
1637
- };
1638
- const credential = await navigator.credentials.create(createCredentialDefaultArgs);
1639
- const algorithm = credential.response.getPublicKeyAlgorithm ? credential.response.getPublicKeyAlgorithm() : ES256_ALGORITHM;
1640
- const userHandleEncoded = base64url.encode(Buffer.from(userHandle));
1641
- return {
1642
- creds: publicKeyCredentialToJSON(credential),
1643
- userHandle: userHandleEncoded,
1644
- algorithm
1645
- };
1694
+ const userHandle = generateUserHandle();
1695
+ const createCredentialDefaultArgs = {
1696
+ publicKey: {
1697
+ authenticatorSelection: {
1698
+ authenticatorAttachment: "platform",
1699
+ requireResidentKey: true,
1700
+ residentKey: "required",
1701
+ userVerification: "required"
1702
+ },
1703
+ rp: {
1704
+ id: getPortalDomain(env, isE2E),
1705
+ name: "Para"
1706
+ },
1707
+ user: {
1708
+ id: userHandle,
1709
+ name: identifier,
1710
+ displayName: identifier
1711
+ },
1712
+ pubKeyCredParams: [
1713
+ { type: "public-key", alg: ES256_ALGORITHM },
1714
+ // RS256_ALGORITHM should only be needed for windows hello
1715
+ { type: "public-key", alg: RS256_ALGORITHM }
1716
+ ],
1717
+ attestation: "direct",
1718
+ timeout: 6e4,
1719
+ // TODO: don't think we really get value from verifying this, but should revisit
1720
+ challenge: Buffer.from(userId, "utf-8")
1721
+ }
1722
+ };
1723
+ const credential = yield navigator.credentials.create(createCredentialDefaultArgs);
1724
+ const algorithm = credential.response.getPublicKeyAlgorithm ? credential.response.getPublicKeyAlgorithm() : ES256_ALGORITHM;
1725
+ const userHandleEncoded = base64url.encode(Buffer.from(userHandle));
1726
+ return {
1727
+ creds: publicKeyCredentialToJSON(credential),
1728
+ userHandle: userHandleEncoded,
1729
+ algorithm
1730
+ };
1731
+ });
1646
1732
  }
1647
- async function generateSignature(env, challenge, allowedPublicKeys, isE2E) {
1648
- const getCredentialDefaultArgs = {
1649
- publicKey: {
1650
- timeout: 6e4,
1651
- challenge: Buffer.from(challenge, "base64"),
1652
- allowCredentials: allowedPublicKeys.map((key) => ({
1653
- id: base64url.toBuffer(key),
1654
- type: "public-key"
1655
- })),
1656
- userVerification: "required",
1657
- rpId: getPortalDomain(env, isE2E)
1658
- }
1659
- };
1660
- const assertation = await navigator.credentials.get(getCredentialDefaultArgs);
1661
- return publicKeyCredentialToJSON(assertation);
1733
+ function generateSignature(env, challenge, allowedPublicKeys, isE2E) {
1734
+ return __async(this, null, function* () {
1735
+ const getCredentialDefaultArgs = {
1736
+ publicKey: {
1737
+ timeout: 6e4,
1738
+ challenge: Buffer.from(challenge, "base64"),
1739
+ allowCredentials: allowedPublicKeys.map((key) => ({
1740
+ id: base64url.toBuffer(key),
1741
+ type: "public-key"
1742
+ })),
1743
+ userVerification: "required",
1744
+ rpId: getPortalDomain(env, isE2E)
1745
+ }
1746
+ };
1747
+ const assertation = yield navigator.credentials.get(getCredentialDefaultArgs);
1748
+ return publicKeyCredentialToJSON(assertation);
1749
+ });
1662
1750
  }
1663
1751
 
1664
1752
  // src/utils/truncateEthAddress.ts
@@ -1671,10 +1759,15 @@ var truncateEthAddress = (address) => {
1671
1759
 
1672
1760
  // src/utils/isPasskeySupported.ts
1673
1761
  import { UAParser } from "ua-parser-js";
1674
- var isPasskeySupported = (userAgent) => {
1675
- const osName = new UAParser(userAgent).getOS().name?.toLowerCase();
1762
+ var isPasskeySupported = (userAgent) => __async(void 0, null, function* () {
1763
+ var _a, _b, _c;
1764
+ const directPasskeyCheck = yield (_b = (_a = window == null ? void 0 : window.PublicKeyCredential) == null ? void 0 : _a.isUserVerifyingPlatformAuthenticatorAvailable) == null ? void 0 : _b.call(_a);
1765
+ if (directPasskeyCheck === true || directPasskeyCheck === false) {
1766
+ return directPasskeyCheck;
1767
+ }
1768
+ const osName = (_c = new UAParser(userAgent).getOS().name) == null ? void 0 : _c.toLowerCase();
1676
1769
  return !!osName && !["linux", "chrome os"].includes(osName);
1677
- };
1770
+ });
1678
1771
 
1679
1772
  // src/utils/isMobile.ts
1680
1773
  function isAndroid() {