@crossmint/wallets-sdk 1.0.6 → 1.0.8
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/README.md +70 -19
- package/dist/api/__tests__/test-utils.cjs +1 -1
- package/dist/api/__tests__/test-utils.js +1 -1
- package/dist/api/client.cjs +1 -1
- package/dist/api/client.js +1 -1
- package/dist/api/index.cjs +1 -1
- package/dist/api/index.js +1 -1
- package/dist/chains/chains.cjs +1 -1
- package/dist/chains/chains.js +1 -1
- package/dist/{chunk-ILOLXAVX.cjs → chunk-35KMDPR5.cjs} +1 -1
- package/dist/{chunk-SYRVGFS7.js → chunk-5EBQUTRI.js} +1 -1
- package/dist/{chunk-U2NZDB37.js → chunk-7HGPAR7D.js} +1 -1
- package/dist/{chunk-FBFT2E6I.js → chunk-7TEUO6AH.js} +1 -1
- package/dist/{chunk-TTDWZ77O.cjs → chunk-BFM7DC5O.cjs} +1 -1
- package/dist/{chunk-SCPDMHCR.cjs → chunk-BFN7XMPW.cjs} +1 -1
- package/dist/{chunk-XC36Q76T.js → chunk-BNX5VMBS.js} +1 -1
- package/dist/{chunk-BEJRUYPR.cjs → chunk-DIPGRXL6.cjs} +1 -1
- package/dist/{chunk-EIM3O5OX.js → chunk-EDN5LPJV.js} +1 -1
- package/dist/{chunk-557V3TGD.js → chunk-FFLA7JWH.js} +1 -1
- package/dist/{chunk-RKO4OMNP.js → chunk-HCD56LQH.js} +1 -1
- package/dist/{chunk-IBEOC3PY.cjs → chunk-JX4QNRH6.cjs} +1 -1
- package/dist/{chunk-GYUYS75X.cjs → chunk-MBCVIGBE.cjs} +1 -1
- package/dist/{chunk-5GVNUIMB.cjs → chunk-NQUBP2T3.cjs} +1 -1
- package/dist/chunk-O4FUTA6J.js +1 -0
- package/dist/{chunk-MAK4BTYB.cjs → chunk-OMN4CFHL.cjs} +1 -1
- package/dist/{chunk-KBIPKX7J.cjs → chunk-OOE7AX5Y.cjs} +1 -1
- package/dist/{chunk-R4UIR4ME.js → chunk-P6RSAFSM.js} +1 -1
- package/dist/{chunk-GZP2JQ6P.cjs → chunk-RRFJMYA5.cjs} +1 -1
- package/dist/{chunk-BWI6HYAM.cjs → chunk-RYAJSQT2.cjs} +1 -1
- package/dist/{chunk-TQ3DHHDD.js → chunk-RYOHAEZ3.js} +1 -1
- package/dist/{chunk-AOEZBP4B.cjs → chunk-S6CJR7KA.cjs} +1 -1
- package/dist/{chunk-DVJ36LFS.cjs → chunk-TE2QAVEH.cjs} +2 -2
- package/dist/{chunk-WUUKSJZA.js → chunk-TEY5A2C6.js} +1 -1
- package/dist/{chunk-3NVAOKHU.js → chunk-U65RZL3N.js} +1 -1
- package/dist/{chunk-PLYNNPIO.js → chunk-UWJKV6PY.js} +2 -2
- package/dist/{chunk-CP4EOL72.cjs → chunk-XFCAYOAA.cjs} +1 -1
- package/dist/{chunk-JLQXK6OD.js → chunk-Y22U2RZ2.js} +1 -1
- package/dist/{chunk-EXQQQBO5.cjs → chunk-Y76OKATG.cjs} +1 -1
- package/dist/{chunk-IHXBHFSI.js → chunk-YA4NFTK7.js} +1 -1
- package/dist/{chunk-WE6YJGWF.js → chunk-YDNVYOOK.js} +1 -1
- package/dist/chunk-YXHWN6FD.js +1 -0
- package/dist/{chunk-IEW4QYEG.cjs → chunk-Z7NDWMHJ.cjs} +1 -1
- package/dist/{chunk-ZZBLGUBW.cjs → chunk-ZTIMDM5V.cjs} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/logger/index.cjs +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/logger/init.cjs +1 -1
- package/dist/logger/init.js +1 -1
- package/dist/sdk.cjs +1 -1
- package/dist/sdk.js +1 -1
- package/dist/signers/index.cjs +1 -1
- package/dist/signers/index.js +1 -1
- package/dist/signers/non-custodial/index.cjs +1 -1
- package/dist/signers/non-custodial/index.js +1 -1
- package/dist/signers/non-custodial/ncs-evm-signer.cjs +1 -1
- package/dist/signers/non-custodial/ncs-evm-signer.js +1 -1
- package/dist/signers/non-custodial/ncs-signer.cjs +1 -1
- package/dist/signers/non-custodial/ncs-signer.js +1 -1
- package/dist/signers/non-custodial/ncs-solana-signer.cjs +1 -1
- package/dist/signers/non-custodial/ncs-solana-signer.js +1 -1
- package/dist/signers/non-custodial/ncs-stellar-signer.cjs +1 -1
- package/dist/signers/non-custodial/ncs-stellar-signer.js +1 -1
- package/dist/signers/server/assemble-server-signer.cjs +1 -1
- package/dist/signers/server/assemble-server-signer.js +1 -1
- package/dist/signers/server/index.cjs +1 -1
- package/dist/signers/server/index.js +1 -1
- package/dist/utils/constants.cjs +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/device-signers/IframeDeviceSignerKeyStorage.cjs +1 -1
- package/dist/utils/device-signers/IframeDeviceSignerKeyStorage.js +1 -1
- package/dist/utils/device-signers/index.cjs +1 -1
- package/dist/utils/device-signers/index.js +1 -1
- package/dist/wallets/__tests__/test-helpers.cjs +1 -1
- package/dist/wallets/__tests__/test-helpers.js +1 -1
- package/dist/wallets/evm.cjs +1 -1
- package/dist/wallets/evm.js +1 -1
- package/dist/wallets/solana.cjs +1 -1
- package/dist/wallets/solana.js +1 -1
- package/dist/wallets/stellar.cjs +1 -1
- package/dist/wallets/stellar.js +1 -1
- package/dist/wallets/wallet-factory.cjs +1 -1
- package/dist/wallets/wallet-factory.js +1 -1
- package/dist/wallets/wallet.cjs +1 -1
- package/dist/wallets/wallet.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-6X5JEJD7.js +0 -1
- package/dist/chunk-FFEHHGVZ.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4DJWSV7Icjs = require('./chunk-4DJWSV7I.cjs');var _chunkYF5G4U6Lcjs = require('./chunk-YF5G4U6L.cjs');var _chunkENU3EKBGcjs = require('./chunk-ENU3EKBG.cjs');var _chunk3SVXPFSPcjs = require('./chunk-3SVXPFSP.cjs');function l(a,e){switch(_chunkENU3EKBGcjs.a.call(void 0, a)){case"evm":return new (0, _chunk3SVXPFSPcjs.a)(e);case"solana":return new (0, _chunk4DJWSV7Icjs.a)(e);case"stellar":return new (0, _chunkYF5G4U6Lcjs.a)(e)}}exports.a = l;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkK5TQ4QU3cjs = require('./chunk-K5TQ4QU3.cjs');var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkK5TQ4QU3cjs = require('./chunk-K5TQ4QU3.cjs');var _chunkTE2QAVEHcjs = require('./chunk-TE2QAVEH.cjs');var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunkNX256LAHcjs = require('./chunk-NX256LAH.cjs');var _chunk3VSFHDFHcjs = require('./chunk-3VSFHDFH.cjs');var _chunkZTIMDM5Vcjs = require('./chunk-ZTIMDM5V.cjs');var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var _chunkJX4QNRH6cjs = require('./chunk-JX4QNRH6.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _ox = require('ox');var D="When 'signers' is provided to a method that may fetch an existing wallet, each specified signer must exist in that wallet's configuration.",d= exports.a =class{constructor(t){this.apiClient=t}getWallet(t,e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let a,n;if(typeof t=="string"){if(!this.apiClient.isServerSide)throw new (0, _chunkT3U46LK3cjs.g)("getWallet with walletLocator is only available on the server side. Use getWallet(args) instead.");if(e==null)throw new (0, _chunkT3U46LK3cjs.g)("Wallet configuration is required when using walletLocator: https://docs.crossmint.com/sdk-reference/wallets/type-aliases/WalletArgsFor");a=t,n=e}else{if(this.apiClient.isServerSide)throw new (0, _chunkT3U46LK3cjs.g)("getWallet on server side requires a walletLocator parameter. Use getWallet(walletLocator, args) instead.");n=t,a=this.getWalletLocator(n)}let i=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},n),{chain:_chunkZTIMDM5Vcjs.f.call(void 0, n.chain,this.apiClient.environment)});_chunkJX4QNRH6cjs.a.info("walletFactory.getWallet.start");let r=yield this.apiClient.getWallet(a);if("error"in r)throw _chunkJX4QNRH6cjs.a.warn("walletFactory.getWallet.notFound",{error:r.error}),new (0, _chunkT3U46LK3cjs.e)(JSON.stringify(r));return _chunkJX4QNRH6cjs.a.info("walletFactory.getWallet.success",{address:r.address}),yield this.createWalletInstance(r,i)})}createWallet(t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,s,g,v,W,A,k,F;let e=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},t),{chain:_chunkZTIMDM5Vcjs.f.call(void 0, t.chain,this.apiClient.environment)});if(yield(g=(s=(o=e.options)==null?void 0:o.callbacks)==null?void 0:s.onWalletCreationStart)==null?void 0:g.call(s),_chunkJX4QNRH6cjs.a.info("walletFactory.createWallet.start"),!this.apiClient.isServerSide&&e.owner!=null)throw _chunkJX4QNRH6cjs.a.error("walletFactory.createWallet.error",{error:"Owner field cannot be specified in client-side createWallet calls"}),new (0, _chunkT3U46LK3cjs.g)("Owner field cannot be specified in client-side createWallet calls. Owner is determined from JWT authentication.");let a=((v=e.options)==null?void 0:v.deviceSignerKeyStorage)!=null?this.ensureDeviceSignerInSigners(e):(W=e.signers)!=null?W:[],n=yield this.registerSigners(a,e.chain,(A=e.options)==null?void 0:A.deviceSignerKeyStorage),i;if(e.recovery.type==="passkey"&&e.recovery.id==null)i=yield this.createPasskeySigner(e.recovery);else if(e.recovery.type==="server"){let{derivedAddress:$}=_chunk3VSFHDFHcjs.b.call(void 0, e.recovery,e.chain,this.apiClient.projectId,this.apiClient.environment);i={type:"server",address:$}}else i=e.recovery;let r=yield this.apiClient.createWallet({type:"smart",chainType:this.getChainType(e.chain),config:_chunk2GKPWQBQcjs.a.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {adminSigner:i},e.plugins?{plugins:e.plugins}:{}),n!=null?{delegatedSigners:n}:{}),owner:(k=e.owner)!=null?k:void 0,alias:(F=e.alias)!=null?F:void 0});if("error"in r)throw _chunkJX4QNRH6cjs.a.error("walletFactory.createWallet.error",{error:r.error}),new (0, _chunkT3U46LK3cjs.g)(JSON.stringify(r));return _chunkJX4QNRH6cjs.a.info("walletFactory.createWallet.success",{address:r.address}),yield this.createWalletInstance(r,e)})}createWalletInstance(t,e){var o,s;this.validateExistingWalletConfig(t,e);let a=e,n=t.config.adminSigner,i=((o=a.recovery)==null?void 0:o.type)==="server"||((s=a.recovery)==null?void 0:s.type)==="external-wallet"?a.recovery:n,r=t.config.delegatedSigners;return r!=null&&r.length===1&&(r[0].type==="server"||r[0].type==="external-wallet")&&(r=a.signers),new (0, _chunkTE2QAVEHcjs.a)({chain:e.chain,address:t.address,owner:t.owner,options:e.options,alias:e.alias,recovery:i,signers:r!=null?r:[]},this.apiClient)}getWalletLocator(t){return`me:${this.getChainType(t.chain)}:smart`+(t.alias!=null?`:alias:${t.alias}`:"")}createPasskeySigner(t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;if(t.type!=="passkey")throw new Error("Signer is not a passkey");let e=(n=t.name)!=null?n:`Crossmint Wallet ${Date.now()}`,a=t.onCreatePasskey?yield t.onCreatePasskey(e):yield _ox.WebAuthnP256.createCredential({name:e});return{type:"passkey",id:a.id,name:e,publicKey:{x:a.publicKey.x.toString(),y:a.publicKey.y.toString()}}})}ensureDeviceSignerInSigners(t){var n,i;if(t.chain==="solana")return(n=t.signers)!=null?n:[];let e=(i=t.signers)!=null?i:[];return e.some(r=>r.type==="device")?e:[...e,{type:"device"}]}validateExistingWalletConfig(t,e){if(e.owner!=null&&t.owner!=null&&_chunkK5TQ4QU3cjs.a.call(void 0, e.owner)!==_chunkK5TQ4QU3cjs.a.call(void 0, t.owner))throw new (0, _chunkT3U46LK3cjs.g)("Wallet owner does not match existing wallet's linked user");if(e.chain==="solana"&&t.chainType!=="solana"||e.chain!=="solana"&&t.chainType==="solana"||e.chain==="stellar"&&t.chainType!=="stellar"||e.chain!=="stellar"&&t.chainType==="stellar")throw new (0, _chunkT3U46LK3cjs.g)(`Wallet chain does not match existing wallet's chain. You must use chain: ${t.chainType}.`);if(t.type!=="smart")return;let a=e;if(a.recovery!=null||a.signers!=null){let n=t.config,i=n==null?void 0:n.adminSigner;if(a.recovery!=null&&i!=null){if(a.recovery.type!==i.type)throw new (0, _chunkT3U46LK3cjs.g)("The wallet recovery signer type does not match the existing wallet's recovery signer type");_chunkK5TQ4QU3cjs.b.call(void 0, a.recovery,i)}let r=a.signers;r!=null&&this.validateSigners(t,r,e.chain)}}validateSigners(t,e,a){let n=t.config,i=n==null?void 0:n.delegatedSigners;if(e.length!==0){if(i==null||i.length===0)throw new (0, _chunkT3U46LK3cjs.g)(`${e.length} signer(s) specified, but wallet "${t.address}" has no signers. ${D}`);for(let r of e){let o=i.find(s=>{if(this.isMatchingPasskeySigner(r,s,n)||s.type==="device"&&r.type==="device")return!0;if(r.type==="server"){let{derivedAddress:g}=_chunk3VSFHDFHcjs.b.call(void 0, r,a,this.apiClient.projectId,this.apiClient.environment);return s.locator===`server:${g}`}return s.locator===_chunkNX256LAHcjs.a.call(void 0, r)});if(o==null){let s=i.map(g=>g.locator).join(", ");throw new (0, _chunkT3U46LK3cjs.g)(`Signer '${r.type}' does not exist in wallet "${t.address}". Available signers: ${s}. ${D}`)}_chunkK5TQ4QU3cjs.b.call(void 0, r,o)}}}isMatchingPasskeySigner(t,e,a){var i,r;let n=((r=(i=a.delegatedSigners)==null?void 0:i.filter(o=>o.type==="passkey").length)!=null?r:0)+(a.adminSigner.type==="passkey"?1:0);if(t.type==="passkey"){if(t.id==null&&n===1)return e.type==="passkey";if(t.id==null&&n>1)throw new (0, _chunkT3U46LK3cjs.g)("When creating a wallet with multiple passkeys, you must provide the passkey ID for each passkey.")}return!1}registerSigners(t,e,a){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;return yield Promise.all((n=t==null?void 0:t.map(i=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(i.type==="passkey")return i.id==null?{signer:yield this.createPasskeySigner(i)}:{signer:i};if(i.type==="device"){if(e==="solana")throw new (0, _chunkT3U46LK3cjs.j)("Device signers are not currently supported for Solana wallets. Contact sales (https://www.crossmint.com/contact/sales) for access.");if(i.publicKey!=null)return{signer:{type:"device",publicKey:i.publicKey,name:i.name}};if(i.locator!=null)return{signer:i.locator};if(a==null)throw new (0, _chunkT3U46LK3cjs.g)("Device signer key storage is required for device signers");let r=yield _chunkYHV3672Rcjs.a.call(void 0, a);return{signer:{type:"device",publicKey:r.publicKey,name:r.name}}}if(i.type==="server"&&e!=null){let{derivedAddress:r}=_chunk3VSFHDFHcjs.b.call(void 0, i,e,this.apiClient.projectId,this.apiClient.environment);return{signer:`server:${r}`}}return{signer:_chunkNX256LAHcjs.a.call(void 0, i)}})))!=null?n:[])})}getChainType(t){return t==="solana"?"solana":t==="stellar"?"stellar":"evm"}};_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"walletFactory.getWallet",buildContext(t,e){if(typeof e[0]=="string"){let n=e[1];return{walletLocator:e[0],chain:n==null?void 0:n.chain}}let a=e[0];return{chain:a==null?void 0:a.chain}}})],d.prototype,"getWallet",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"walletFactory.createWallet",buildContext(t,e){return{chain:e[0].chain}}})],d.prototype,"createWallet",1);exports.a = d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b as g}from"./chunk-
|
|
1
|
+
import{a,b as g}from"./chunk-7HGPAR7D.js";import{a as s}from"./chunk-EDN5LPJV.js";import{g as t}from"./chunk-J3R36SGJ.js";import{PersonalMessage as u}from"ox";import{isHex as h,toHex as l}from"viem";var c=class p extends a{constructor(e){super(e)}signMessage(e){return t(this,null,function*(){let i=h(e)?e:l(e),r=u.getSignPayload(i);return yield this.sign(r)})}signTransaction(e){return t(this,null,function*(){return yield this.sign(e)})}sign(e){return t(this,null,function*(){var o;yield this.handleAuthRequired();let i=this.getJwtOrThrow(),r=e.replace("0x","");s.info("sign: sending request",{keyType:"secp256k1"});let y=Date.now(),n=yield(o=this.config.clientTEEConnection)==null?void 0:o.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:i,apiKey:this.config.crossmint.apiKey},data:{keyType:"secp256k1",bytes:r,encoding:"hex"}},options:g});if(s.info("sign: response received",{status:n==null?void 0:n.status,durationMs:Date.now()-y}),(n==null?void 0:n.status)==="error")throw new Error(n.error);if((n==null?void 0:n.signature)==null)throw new Error("Failed to sign transaction");return p.verifyPublicKeyFormat(n.publicKey),{signature:n.signature.bytes}})}static verifyPublicKeyFormat(e){if(e==null)throw new Error("No public key found");if(e.encoding!=="hex"||e.keyType!=="secp256k1"||e.bytes==null)throw new Error("Not supported. Expected public key to be in hex encoding and secp256k1 key type. Got: "+JSON.stringify(e))}getChainKeyParams(){return{scheme:"secp256k1",encoding:"hex"}}};export{c as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var _chunkJX4QNRH6cjs = require('./chunk-JX4QNRH6.cjs');var _chunkBFN7XMPWcjs = require('./chunk-BFN7XMPW.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var l=class extends _commonsdkbase.CrossmintApiClient{constructor(e){super(e,{internalConfig:{sdkMetadata:{name:_chunkBFN7XMPWcjs.c,version:_chunkBFN7XMPWcjs.b}}});this.apiPrefix="api/2025-06-09/wallets";this.unstableApiPrefix="api/unstable/wallets"}createWallet(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let s=this.isServerSide?`${this.apiPrefix}`:`${this.apiPrefix}/me`;_chunkJX4QNRH6cjs.a.info("wallets.api.createWallet",{chainType:e.chainType,walletType:e.type});let n=yield(yield this.post(s,{body:JSON.stringify(e),headers:this.headers})).json();return"error"in n?_chunkJX4QNRH6cjs.a.error("wallets.api.createWallet.error",{error:n.error,chainType:e.chainType}):"address"in n&&_chunkJX4QNRH6cjs.a.info("wallets.api.createWallet.success",{address:n.address,chainType:e.chainType}),n})}getWallet(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallets.api.getWallet",{locator:e});let r=yield(yield this.get(`${this.apiPrefix}/${e}`,{headers:this.headers})).json();return"error"in r?_chunkJX4QNRH6cjs.a.warn("wallets.api.getWallet.error",{locator:e,error:r.error}):"address"in r&&_chunkJX4QNRH6cjs.a.info("wallets.api.getWallet.success",{address:r.address,locator:e}),r})}createTransaction(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveTransaction(e,s,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getTransaction(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions/${s}`,{headers:this.headers})).json()})}createSignature(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveSignature(e,s,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getSignature(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/signatures/${s}`,{headers:this.headers})).json()})}getTransactions(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions`,{headers:this.headers})).json()})}getNfts(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let s=new URLSearchParams;s.append("page",e.page.toString()),s.append("perPage",e.perPage.toString());let r=`${e.chain}:${e.address}`;return(yield this.get(`${this.apiPrefix}/${r}/nfts?${s.toString()}`,{headers:this.headers})).json()})}getTransfers(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=new URLSearchParams;return r.append("chain",s.chain.toString()),s.tokens!=null&&r.append("tokens",s.tokens),s.status!=null&&r.append("status",s.status),(yield this.get(`${this.unstableApiPrefix}/${e}/transfers?${r.toString()}`,{headers:this.headers})).json()})}getBalance(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=new URLSearchParams;return r.append("tokens",s.tokens.join(",")),r.append("chains",s.chains.join(",")),(yield this.get(`${this.apiPrefix}/${e}/balances?${r.toString()}`,{headers:this.headers})).json()})}fundWallet(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(this.environment===_commonsdkbase.APIKeyEnvironmentPrefix.PRODUCTION)throw new Error("Funding wallets is only supported in staging environment");return(yield this.post(`api/v1-alpha2/wallets/${e}/balances`,{body:JSON.stringify(s),headers:this.headers})).json()})}registerSigner(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signers`,{body:JSON.stringify(s),headers:this.headers})).json()})}removeSigner(e,s,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let n=encodeURIComponent(s),i=new URLSearchParams;r.chain&&i.append("chain",r.chain);let h=`${this.apiPrefix}/${e}/signers/${n}${i.size>0?`?${i.toString()}`:""}`;return(yield this.delete(h,{headers:this.headers})).json()})}getSigner(e,s){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=encodeURIComponent(s);return(yield this.get(`${this.apiPrefix}/${e}/signers/${r}`,{headers:this.headers})).json()})}send(e,s,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallets.api.send",{walletLocator:e,tokenLocator:s,recipient:r.recipient});let i=yield(yield this.post(`${this.apiPrefix}/${e}/tokens/${s}/transfers`,{body:JSON.stringify(r),headers:this.headers})).json();return"error"in i?_chunkJX4QNRH6cjs.a.error("wallets.api.send.error",{walletLocator:e,tokenLocator:s,error:i.error}):"id"in i&&_chunkJX4QNRH6cjs.a.info("wallets.api.send.success",{walletLocator:e,transactionId:i.id}),i})}get isServerSide(){return this.parsedAPIKey.usageOrigin===_commonsdkbase.APIKeyUsageOrigin.SERVER}get environment(){if(!this.parsedAPIKey.isValid)throw new (0, _chunkT3U46LK3cjs.a)("Invalid API key");return this.parsedAPIKey.environment}get projectId(){if(!this.parsedAPIKey.isValid)throw new (0, _chunkT3U46LK3cjs.a)("Invalid API key");return this.parsedAPIKey.projectId}get headers(){return{"Content-Type":"application/json"}}};exports.a = l;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunkNX256LAHcjs = require('./chunk-NX256LAH.cjs');var _chunkD6SLJ5C2cjs = require('./chunk-D6SLJ5C2.cjs');var _chunkTTDWZ77Ocjs = require('./chunk-TTDWZ77O.cjs');var _chunk3VSFHDFHcjs = require('./chunk-3VSFHDFH.cjs');var _chunkEXQQQBO5cjs = require('./chunk-EXQQQBO5.cjs');var _chunkZZBLGUBWcjs = require('./chunk-ZZBLGUBW.cjs');var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var _chunkIBEOC3PYcjs = require('./chunk-IBEOC3PY.cjs');var _chunkSCPDMHCRcjs = require('./chunk-SCPDMHCR.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var S,m,u,b,x,T,N,D,F,A= exports.a =class{constructor(e,r){_chunk2GKPWQBQcjs.e.call(void 0, this,S);_chunk2GKPWQBQcjs.e.call(void 0, this,m);_chunk2GKPWQBQcjs.e.call(void 0, this,u);_chunk2GKPWQBQcjs.e.call(void 0, this,b);_chunk2GKPWQBQcjs.e.call(void 0, this,x);_chunk2GKPWQBQcjs.e.call(void 0, this,T,!1);_chunk2GKPWQBQcjs.e.call(void 0, this,N,!1);_chunk2GKPWQBQcjs.e.call(void 0, this,D);_chunk2GKPWQBQcjs.e.call(void 0, this,F,null);let{chain:t,address:n,owner:a,options:g,alias:d,recovery:o,signers:l,signer:h}=e;_chunk2GKPWQBQcjs.f.call(void 0, this,u,r),this.chain=t,this.address=n,this.owner=a,_chunk2GKPWQBQcjs.f.call(void 0, this,m,g),this.alias=d,_chunk2GKPWQBQcjs.f.call(void 0, this,b,o),_chunk2GKPWQBQcjs.f.call(void 0, this,x,l!=null?l:[]),_chunk2GKPWQBQcjs.f.call(void 0, this,S,h),_chunk2GKPWQBQcjs.f.call(void 0, this,D,this.initDefaultSigner())}get signer(){return _chunk2GKPWQBQcjs.d.call(void 0, this,S)}initDeviceSigner(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;let e=(n=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:n.deviceSignerKeyStorage;if(e==null||this.chain==="solana")return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(a){_chunkIBEOC3PYcjs.a.error("wallet.initDeviceSigner.error",{error:a}),_chunk2GKPWQBQcjs.f.call(void 0, this,T,!0);return}if(_chunk2GKPWQBQcjs.d.call(void 0, this,T))return;let t=this.buildInternalSignerConfig(r);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(t,e))})}initDefaultSigner(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null||(yield this.initDeviceSigner(),_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null||_chunk2GKPWQBQcjs.d.call(void 0, this,T)))return;let e=_chunk2GKPWQBQcjs.d.call(void 0, this,x).length===0?_chunk2GKPWQBQcjs.d.call(void 0, this,b):_chunk2GKPWQBQcjs.d.call(void 0, this,x).length===1?_chunk2GKPWQBQcjs.d.call(void 0, this,x)[0]:null;if(e!=null&&this.isAutoAssemblableSignerConfig(e))try{let r=this.buildInternalSignerConfig(e);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(r))}catch(r){_chunkIBEOC3PYcjs.a.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:_chunk2GKPWQBQcjs.d.call(void 0, this,b).type,signerCount:_chunk2GKPWQBQcjs.d.call(void 0, this,x).length,error:r})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return _chunk2GKPWQBQcjs.d.call(void 0, e,b)}static getInitialSigners(e){return _chunk2GKPWQBQcjs.d.call(void 0, e,x)}get apiClient(){return _chunk2GKPWQBQcjs.d.call(void 0, this,u)}get options(){return _chunk2GKPWQBQcjs.d.call(void 0, this,m)}get recovery(){return _chunk2GKPWQBQcjs.d.call(void 0, this,b)}balances(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkIBEOC3PYcjs.a.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),t;switch(this.chain){case"solana":t="sol";break;case"stellar":t="xlm";break;default:t="eth";break}let n=[t,"usdc",...e!=null?e:[]],a=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getBalance(this.address,{chains:[r],tokens:n});if("error"in a)throw _chunkIBEOC3PYcjs.a.error("wallet.balances.error",{error:a}),new Error(`Failed to get balances for wallet: ${JSON.stringify(a.message)}`);return _chunkIBEOC3PYcjs.a.info("wallet.balances.success"),this.transformBalanceResponse(a,t,e)})}stagingFund(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkIBEOC3PYcjs.a.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let t=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in t)throw _chunkIBEOC3PYcjs.a.error("wallet.stagingFund.error",{error:t}),new Error(`Failed to fund wallet: ${JSON.stringify(t.message)}`);return _chunkIBEOC3PYcjs.a.info("wallet.stagingFund.success"),t})}transformBalanceResponse(e,r,t){let n=l=>{var v,y,I,$,K;let h=(v=l.chains)==null?void 0:v[this.chain],f={};return this.chain==="solana"&&h!=null&&"mintHash"in h?f={mintHash:h.mintHash}:this.chain==="stellar"&&h!=null&&"contractId"in h?f={contractId:h.contractId}:h!=null&&"contractAddress"in h&&(f={contractAddress:h.contractAddress}),_chunk2GKPWQBQcjs.a.call(void 0, {symbol:(y=l.symbol)!=null?y:"",name:(I=l.name)!=null?I:"",amount:($=l.amount)!=null?$:"0",decimals:l.decimals,rawAmount:(K=l.rawAmount)!=null?K:"0"},f)},a=e.find(l=>l.symbol===r),g=e.find(l=>l.symbol==="usdc"),d=e.filter(l=>{var h;return l.symbol!==r&&l.symbol!=="usdc"&&(t==null||t.includes((h=l.symbol)!=null?h:""))}),o=l=>{let h={symbol:l,name:l,amount:"0",decimals:0,rawAmount:"0"},f={};return this.chain==="solana"?f={mintHash:void 0}:this.chain==="stellar"?f={contractId:void 0}:f={contractAddress:void 0},_chunk2GKPWQBQcjs.a.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},h),f)};return{nativeToken:a!=null?n(a):o(r),usdc:g!=null?n(g):o("usdc"),tokens:d.map(n)}}nfts(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getNfts(_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},e),{chain:this.chain,address:this.address}))})}transactions(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let e=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=this.resolveChainForEnvironment(),t=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e==null?void 0:e.tokens,status:e==null?void 0:e.status});if("error"in t)throw new Error(`Failed to get transfers: ${JSON.stringify(t.message)}`);return t})}send(e,r,t,n){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let a=this.resolveChainForEnvironment(),g=ce(e),d=de(r,a),o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o)||o<=0)throw new (0, _chunkT3U46LK3cjs.s)(`Invalid transfer amount: "${t}". Amount must be a positive number greater than zero.`);_chunkIBEOC3PYcjs.a.info("wallet.send.start",_chunk2GKPWQBQcjs.a.call(void 0, {recipient:g,token:d,amount:t},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{})),yield this.preAuthIfNeeded();let l=this.requireSigner(),h;(n==null?void 0:n.signer)==null?h=l.locator():typeof n.signer=="string"?h=n.signer:h=`server:${_chunk3VSFHDFHcjs.b.call(void 0, n.signer,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress}`;let f=_chunk2GKPWQBQcjs.a.call(void 0, {recipient:g,amount:t,signer:h},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{}),v=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).send(this.walletLocator,d,f);if("message"in v)throw _chunkIBEOC3PYcjs.a.error("wallet.send.error",{error:v}),new (0, _chunkT3U46LK3cjs.t)(`Failed to send token: ${JSON.stringify(v.message)}`);if((n==null?void 0:n.prepareOnly)===!0)return _chunkIBEOC3PYcjs.a.info("wallet.send.prepared",{transactionId:v.id}),{hash:void 0,explorerLink:void 0,transactionId:v.id};let y=yield this.approveTransactionAndWait(v.id);return _chunkIBEOC3PYcjs.a.info("wallet.send.success",{transactionId:v.id,hash:y.hash}),y})}approveTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(this.requireSigner(),_chunkIBEOC3PYcjs.a.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return _chunkIBEOC3PYcjs.a.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return _chunkIBEOC3PYcjs.a.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw _chunkIBEOC3PYcjs.a.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(_chunkIBEOC3PYcjs.a.info("wallet.addSigner.start"),e.type==="device"&&this.chain==="solana")throw new (0, _chunkT3U46LK3cjs.j)("Device signers are not currently supported for Solana wallets. Contact sales (https://www.crossmint.com/contact/sales) for access.");let t=typeof e=="object"&&"type"in e&&e.type==="server"?`server:${_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress}`:e;return this.withRecoverySigner(()=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var d;let n=typeof t=="string"||t.type==="passkey"?t:t.type==="device"&&"publicKey"in t&&t.publicKey!=null?{type:"device",publicKey:t.publicKey,name:t.name}:_chunkNX256LAHcjs.a.call(void 0, t),a=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).registerSigner(this.walletLocator,{signer:n,chain:this.getSignerRegistrationChain()});if("error"in a)throw _chunkIBEOC3PYcjs.a.error("wallet.addSigner.error",{error:a}),new Error(`Failed to register signer: ${JSON.stringify(a.message)}`);let g=_chunkD6SLJ5C2cjs.b.call(void 0, a,this.chain);if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in a)||a.transaction==null)throw _chunkIBEOC3PYcjs.a.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");let o=a.transaction.id;if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);return r!=null&&r.prepareOnly?(_chunkIBEOC3PYcjs.a.info("wallet.addSigner.prepared",{transactionId:o}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{transactionId:o})):(yield this.approveTransactionAndWait(o),_chunkIBEOC3PYcjs.a.info("wallet.addSigner.success",{transactionId:o}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{status:"success"}))}else{if(!("chains"in a))throw _chunkIBEOC3PYcjs.a.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");let o=(d=a.chains)==null?void 0:d[this.chain];if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let l=_chunkD6SLJ5C2cjs.c.call(void 0, a,this.chain),h=(l==null?void 0:l.type)==="signature"?l.id:void 0;if(r!=null&&r.prepareOnly)return _chunkIBEOC3PYcjs.a.info("wallet.addSigner.prepared",{signatureId:h}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{signatureId:h});if((l==null?void 0:l.type)==="signature")yield this.approveSignatureAndWait(l.id),_chunkIBEOC3PYcjs.a.info("wallet.addSigner.success",{signatureId:l.id});else{if((o==null?void 0:o.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);_chunkIBEOC3PYcjs.a.info("wallet.addSigner.success")}return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{status:"success"})}}))})}removeSigner(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=this.resolveSignerLocator(e);return _chunkIBEOC3PYcjs.a.info("wallet.removeSigner.start",{signerLocator:t}),this.withRecoverySigner(()=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let n=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).removeSigner(this.walletLocator,t,{chain:this.getSignerRegistrationChain()});if("error"in n)throw _chunkIBEOC3PYcjs.a.error("wallet.removeSigner.error",{error:n}),new Error(`Failed to remove signer: ${JSON.stringify(n)}`);let a=n.id;return r!=null&&r.prepareOnly?(_chunkIBEOC3PYcjs.a.info("wallet.removeSigner.prepared",{transactionId:a}),{transactionId:a,status:void 0}):(yield this.approveTransactionAndWait(a),_chunkIBEOC3PYcjs.a.info("wallet.removeSigner.success",{transactionId:a}),{transactionId:a,status:"success"})}))})}useSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkIBEOC3PYcjs.a.info("wallet.useSigner.start"),this.validateSignerInput(e),e.type==="device"?yield this.resolveDeviceSignerAvailability(e):yield this.resolveNonDeviceSigner(e);let r=this.buildInternalSignerConfig(e),t=_chunkNX256LAHcjs.a.call(void 0, e);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(r)),_chunkIBEOC3PYcjs.a.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}throw new Error("No passkey signer is registered on this wallet.")}let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}if(this.isRecoverySigner(e)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}throw new Error(`Signer "${r}" is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=(yield this.signers()).filter(n=>n.type==="passkey");if(t.length===0)return!1;if(t.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=t[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){if(e.type==="server"){let{derivedAddress:r}=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return`server:${r}`}return _chunkNX256LAHcjs.a.call(void 0, e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;let r=this.signer,t=this.buildInternalSignerConfig(_chunk2GKPWQBQcjs.d.call(void 0, this,b));_chunk2GKPWQBQcjs.f.call(void 0, this,S,_chunkTTDWZ77Ocjs.a.call(void 0, this.chain,t,(n=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:n.deviceSignerKeyStorage));try{return yield e()}finally{_chunk2GKPWQBQcjs.f.call(void 0, this,S,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.signers()).some(t=>t.locator===e)})}isSignerApproved(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((t=r.signer)==null?void 0:t.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return _chunk2GKPWQBQcjs.d.call(void 0, this,T)}recover(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a,g;if(_chunkIBEOC3PYcjs.a.info("wallet.recover.start"),_chunk2GKPWQBQcjs.d.call(void 0, this,N)){_chunkIBEOC3PYcjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}let e=()=>{_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1),_chunk2GKPWQBQcjs.f.call(void 0, this,N,!0)};if(((a=_chunk2GKPWQBQcjs.d.call(void 0, this,S))==null?void 0:a.type)==="device"&&(yield this.checkAndResumeDeviceSigner(_chunk2GKPWQBQcjs.d.call(void 0, this,S)))){e();return}if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null&&_chunk2GKPWQBQcjs.d.call(void 0, this,S).type!=="device"){_chunkIBEOC3PYcjs.a.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"});return}let r=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null){if(!_chunk2GKPWQBQcjs.d.call(void 0, this,T))return;throw new Error("Device signer key storage is required to recover a device signer")}if(this.chain==="solana"){_chunkIBEOC3PYcjs.a.warn("wallet.recover.skipped",{reason:"Device signers are not supported on Solana"});return}let t=yield this.findLocalDeviceSigner(r);if(t!=null&&(yield this.checkAndResumeDeviceSigner(t))){_chunk2GKPWQBQcjs.f.call(void 0, this,S,t),e();let d=t.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,d)}catch(o){_chunkIBEOC3PYcjs.a.warn("wallet.recover.mapAddressToKey.error",{error:o})}return}let n=yield _chunkYHV3672Rcjs.a.call(void 0, r,this.address);try{yield this.addSigner(n)}catch(d){if(d instanceof Error&&d.message.toLowerCase().includes("delegated signer")&&d.message.toLowerCase().includes("already")&&d.message.toLowerCase().includes("approved"))_chunkIBEOC3PYcjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:n.locator});else throw _chunkIBEOC3PYcjs.a.error("wallet.recover.device.error",{error:d}),yield r.deleteKey(this.address),d}_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner({type:"device",locator:n.locator,address:this.address},r)),_chunk2GKPWQBQcjs.d.call(void 0, this,S).type==="device"&&(_chunk2GKPWQBQcjs.d.call(void 0, this,S).status="success"),_chunkIBEOC3PYcjs.a.info("wallet.recover.device.success",{signerLocator:n.locator}),e()})}checkAndResumeDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;if(this.isApprovedSignerStatus(e.status))return _chunkIBEOC3PYcjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(t=r.signer)==null?void 0:t.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(_chunkIBEOC3PYcjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a;let t=_chunk2GKPWQBQcjs.d.call(void 0, this,S),n=this.buildInternalSignerConfig(_chunk2GKPWQBQcjs.d.call(void 0, this,b));_chunk2GKPWQBQcjs.f.call(void 0, this,S,_chunkTTDWZ77Ocjs.a.call(void 0, this.chain,n,(a=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:a.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(g){throw _chunk2GKPWQBQcjs.f.call(void 0, this,S,e),g}finally{_chunk2GKPWQBQcjs.d.call(void 0, this,S)!==e&&_chunk2GKPWQBQcjs.f.call(void 0, this,S,t)}e.status="success",_chunkIBEOC3PYcjs.a.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=(yield this.signers()).filter(n=>n.locator.startsWith("device:"));for(let n of t){let a=n.locator.replace("device:","");try{if(yield e.hasKey(a)){let d=_chunkTTDWZ77Ocjs.a.call(void 0, this.chain,{type:"device",locator:n.locator,address:this.address},e);return _chunkIBEOC3PYcjs.a.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:n.locator}),d}}catch(g){_chunkIBEOC3PYcjs.a.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:n.locator,error:g})}}return null})}signers(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a,g;_chunkIBEOC3PYcjs.a.info("wallet.signers.start");let e=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getWallet(this.walletLocator);if("error"in e)throw _chunkIBEOC3PYcjs.a.error("wallet.signers.error",{error:e}),new (0, _chunkT3U46LK3cjs.e)(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw _chunkIBEOC3PYcjs.a.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new (0, _chunkT3U46LK3cjs.d)(`Wallet type ${e.type} not supported`);let r=(g=(a=e==null?void 0:e.config)==null?void 0:a.delegatedSigners)!=null?g:[],n=(yield Promise.all(r.map(d=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){try{return(yield this.getSignerState(d.locator)).signer}catch(o){return null}})))).filter(d=>d!=null);return _chunkIBEOC3PYcjs.a.info("wallet.signers.success",{count:n.length}),n})}get walletLocator(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,u).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)==null)throw _chunk2GKPWQBQcjs.d.call(void 0, this,x).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):_chunk2GKPWQBQcjs.d.call(void 0, this,b).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunkNX256LAHcjs = require('./chunk-NX256LAH.cjs');var _chunkD6SLJ5C2cjs = require('./chunk-D6SLJ5C2.cjs');var _chunkBFM7DC5Ocjs = require('./chunk-BFM7DC5O.cjs');var _chunk3VSFHDFHcjs = require('./chunk-3VSFHDFH.cjs');var _chunkY76OKATGcjs = require('./chunk-Y76OKATG.cjs');var _chunkZTIMDM5Vcjs = require('./chunk-ZTIMDM5V.cjs');var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var _chunkJX4QNRH6cjs = require('./chunk-JX4QNRH6.cjs');var _chunkBFN7XMPWcjs = require('./chunk-BFN7XMPW.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var S,m,u,b,x,T,N,D,F,A= exports.a =class{constructor(e,r){_chunk2GKPWQBQcjs.e.call(void 0, this,S);_chunk2GKPWQBQcjs.e.call(void 0, this,m);_chunk2GKPWQBQcjs.e.call(void 0, this,u);_chunk2GKPWQBQcjs.e.call(void 0, this,b);_chunk2GKPWQBQcjs.e.call(void 0, this,x);_chunk2GKPWQBQcjs.e.call(void 0, this,T,!1);_chunk2GKPWQBQcjs.e.call(void 0, this,N,!1);_chunk2GKPWQBQcjs.e.call(void 0, this,D);_chunk2GKPWQBQcjs.e.call(void 0, this,F,null);let{chain:t,address:n,owner:a,options:g,alias:d,recovery:o,signers:l,signer:h}=e;_chunk2GKPWQBQcjs.f.call(void 0, this,u,r),this.chain=t,this.address=n,this.owner=a,_chunk2GKPWQBQcjs.f.call(void 0, this,m,g),this.alias=d,_chunk2GKPWQBQcjs.f.call(void 0, this,b,o),_chunk2GKPWQBQcjs.f.call(void 0, this,x,l!=null?l:[]),_chunk2GKPWQBQcjs.f.call(void 0, this,S,h),_chunk2GKPWQBQcjs.f.call(void 0, this,D,this.initDefaultSigner())}get signer(){return _chunk2GKPWQBQcjs.d.call(void 0, this,S)}initDeviceSigner(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;let e=(n=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:n.deviceSignerKeyStorage;if(e==null||this.chain==="solana")return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(a){_chunkJX4QNRH6cjs.a.error("wallet.initDeviceSigner.error",{error:a}),_chunk2GKPWQBQcjs.f.call(void 0, this,T,!0);return}if(_chunk2GKPWQBQcjs.d.call(void 0, this,T))return;let t=this.buildInternalSignerConfig(r);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(t,e))})}initDefaultSigner(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null||(yield this.initDeviceSigner(),_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null||_chunk2GKPWQBQcjs.d.call(void 0, this,T)))return;let e=_chunk2GKPWQBQcjs.d.call(void 0, this,x).length===0?_chunk2GKPWQBQcjs.d.call(void 0, this,b):_chunk2GKPWQBQcjs.d.call(void 0, this,x).length===1?_chunk2GKPWQBQcjs.d.call(void 0, this,x)[0]:null;if(e!=null&&this.isAutoAssemblableSignerConfig(e))try{let r=this.buildInternalSignerConfig(e);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(r))}catch(r){_chunkJX4QNRH6cjs.a.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:_chunk2GKPWQBQcjs.d.call(void 0, this,b).type,signerCount:_chunk2GKPWQBQcjs.d.call(void 0, this,x).length,error:r})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return _chunk2GKPWQBQcjs.d.call(void 0, e,b)}static getInitialSigners(e){return _chunk2GKPWQBQcjs.d.call(void 0, e,x)}get apiClient(){return _chunk2GKPWQBQcjs.d.call(void 0, this,u)}get options(){return _chunk2GKPWQBQcjs.d.call(void 0, this,m)}get recovery(){return _chunk2GKPWQBQcjs.d.call(void 0, this,b)}balances(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),t;switch(this.chain){case"solana":t="sol";break;case"stellar":t="xlm";break;default:t="eth";break}let n=[t,"usdc",...e!=null?e:[]],a=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getBalance(this.address,{chains:[r],tokens:n});if("error"in a)throw _chunkJX4QNRH6cjs.a.error("wallet.balances.error",{error:a}),new Error(`Failed to get balances for wallet: ${JSON.stringify(a.message)}`);return _chunkJX4QNRH6cjs.a.info("wallet.balances.success"),this.transformBalanceResponse(a,t,e)})}stagingFund(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let t=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in t)throw _chunkJX4QNRH6cjs.a.error("wallet.stagingFund.error",{error:t}),new Error(`Failed to fund wallet: ${JSON.stringify(t.message)}`);return _chunkJX4QNRH6cjs.a.info("wallet.stagingFund.success"),t})}transformBalanceResponse(e,r,t){let n=l=>{var v,y,R,$,K;let h=(v=l.chains)==null?void 0:v[this.chain],f={};return this.chain==="solana"&&h!=null&&"mintHash"in h?f={mintHash:h.mintHash}:this.chain==="stellar"&&h!=null&&"contractId"in h?f={contractId:h.contractId}:h!=null&&"contractAddress"in h&&(f={contractAddress:h.contractAddress}),_chunk2GKPWQBQcjs.a.call(void 0, {symbol:(y=l.symbol)!=null?y:"",name:(R=l.name)!=null?R:"",amount:($=l.amount)!=null?$:"0",decimals:l.decimals,rawAmount:(K=l.rawAmount)!=null?K:"0"},f)},a=e.find(l=>l.symbol===r),g=e.find(l=>l.symbol==="usdc"),d=e.filter(l=>{var h;return l.symbol!==r&&l.symbol!=="usdc"&&(t==null||t.includes((h=l.symbol)!=null?h:""))}),o=l=>{let h={symbol:l,name:l,amount:"0",decimals:0,rawAmount:"0"},f={};return this.chain==="solana"?f={mintHash:void 0}:this.chain==="stellar"?f={contractId:void 0}:f={contractAddress:void 0},_chunk2GKPWQBQcjs.a.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},h),f)};return{nativeToken:a!=null?n(a):o(r),usdc:g!=null?n(g):o("usdc"),tokens:d.map(n)}}nfts(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getNfts(_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},e),{chain:this.chain,address:this.address}))})}transactions(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let e=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=this.resolveChainForEnvironment(),t=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e==null?void 0:e.tokens,status:e==null?void 0:e.status});if("error"in t)throw new Error(`Failed to get transfers: ${JSON.stringify(t.message)}`);return t})}send(e,r,t,n){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let a=this.resolveChainForEnvironment(),g=ce(e),d=de(r,a),o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o)||o<=0)throw new (0, _chunkT3U46LK3cjs.s)(`Invalid transfer amount: "${t}". Amount must be a positive number greater than zero.`);_chunkJX4QNRH6cjs.a.info("wallet.send.start",_chunk2GKPWQBQcjs.a.call(void 0, {recipient:g,token:d,amount:t},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{})),yield this.preAuthIfNeeded();let l=this.requireSigner(),h;(n==null?void 0:n.signer)==null?h=l.locator():typeof n.signer=="string"?h=n.signer:h=`server:${_chunk3VSFHDFHcjs.b.call(void 0, n.signer,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress}`;let f=_chunk2GKPWQBQcjs.a.call(void 0, {recipient:g,amount:t,signer:h},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{}),v=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).send(this.walletLocator,d,f);if("message"in v)throw _chunkJX4QNRH6cjs.a.error("wallet.send.error",{error:v}),new (0, _chunkT3U46LK3cjs.t)(`Failed to send token: ${JSON.stringify(v.message)}`);if((n==null?void 0:n.prepareOnly)===!0)return _chunkJX4QNRH6cjs.a.info("wallet.send.prepared",{transactionId:v.id}),{hash:void 0,explorerLink:void 0,transactionId:v.id};let y=yield this.approveTransactionAndWait(v.id);return _chunkJX4QNRH6cjs.a.info("wallet.send.success",{transactionId:v.id,hash:y.hash}),y})}approveTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(_chunkJX4QNRH6cjs.a.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),yield this.preAuthIfNeeded(),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return _chunkJX4QNRH6cjs.a.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return _chunkJX4QNRH6cjs.a.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw _chunkJX4QNRH6cjs.a.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(_chunkJX4QNRH6cjs.a.info("wallet.addSigner.start"),e.type==="device"&&this.chain==="solana")throw new (0, _chunkT3U46LK3cjs.j)("Device signers are not currently supported for Solana wallets. Contact sales (https://www.crossmint.com/contact/sales) for access.");let t=typeof e=="object"&&"type"in e&&e.type==="server"?`server:${_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress}`:e;return this.withRecoverySigner(()=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var d;let n=typeof t=="string"||t.type==="passkey"?t:t.type==="device"&&"publicKey"in t&&t.publicKey!=null?{type:"device",publicKey:t.publicKey,name:t.name}:_chunkNX256LAHcjs.a.call(void 0, t),a=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).registerSigner(this.walletLocator,{signer:n,chain:this.getSignerRegistrationChain()});if("error"in a)throw _chunkJX4QNRH6cjs.a.error("wallet.addSigner.error",{error:a}),new Error(`Failed to register signer: ${JSON.stringify(a.message)}`);let g=_chunkD6SLJ5C2cjs.b.call(void 0, a,this.chain);if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in a)||a.transaction==null)throw _chunkJX4QNRH6cjs.a.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");let o=a.transaction.id;if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);return r!=null&&r.prepareOnly?(_chunkJX4QNRH6cjs.a.info("wallet.addSigner.prepared",{transactionId:o}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{transactionId:o})):(yield this.approveTransactionAndWait(o),_chunkJX4QNRH6cjs.a.info("wallet.addSigner.success",{transactionId:o}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{status:"success"}))}else{if(!("chains"in a))throw _chunkJX4QNRH6cjs.a.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");let o=(d=a.chains)==null?void 0:d[this.chain];if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let l=_chunkD6SLJ5C2cjs.c.call(void 0, a,this.chain),h=(l==null?void 0:l.type)==="signature"?l.id:void 0;if(r!=null&&r.prepareOnly)return _chunkJX4QNRH6cjs.a.info("wallet.addSigner.prepared",{signatureId:h}),_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{signatureId:h});if((l==null?void 0:l.type)==="signature")yield this.approveSignatureAndWait(l.id),_chunkJX4QNRH6cjs.a.info("wallet.addSigner.success",{signatureId:l.id});else{if((o==null?void 0:o.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);_chunkJX4QNRH6cjs.a.info("wallet.addSigner.success")}return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},g),{status:"success"})}}))})}removeSigner(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=this.resolveSignerLocator(e);return _chunkJX4QNRH6cjs.a.info("wallet.removeSigner.start",{signerLocator:t}),this.withRecoverySigner(()=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let n=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).removeSigner(this.walletLocator,t,{chain:this.getSignerRegistrationChain()});if("error"in n)throw _chunkJX4QNRH6cjs.a.error("wallet.removeSigner.error",{error:n}),new Error(`Failed to remove signer: ${JSON.stringify(n)}`);let a=n.id;return r!=null&&r.prepareOnly?(_chunkJX4QNRH6cjs.a.info("wallet.removeSigner.prepared",{transactionId:a}),{transactionId:a,status:void 0}):(yield this.approveTransactionAndWait(a),_chunkJX4QNRH6cjs.a.info("wallet.removeSigner.success",{transactionId:a}),{transactionId:a,status:"success"})}))})}useSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallet.useSigner.start"),this.validateSignerInput(e),e.type==="device"?yield this.resolveDeviceSignerAvailability(e):yield this.resolveNonDeviceSigner(e);let r=this.buildInternalSignerConfig(e),t=_chunkNX256LAHcjs.a.call(void 0, e);_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner(r)),_chunkJX4QNRH6cjs.a.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}throw new Error("No passkey signer is registered on this wallet.")}let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}if(this.isRecoverySigner(e)){_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1);return}throw new Error(`Signer "${r}" is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=(yield this.signers()).filter(n=>n.type==="passkey");if(t.length===0)return!1;if(t.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=t[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){if(e.type==="server"){let{derivedAddress:r}=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return`server:${r}`}return _chunkNX256LAHcjs.a.call(void 0, e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var n;let r=this.signer,t=this.buildInternalSignerConfig(_chunk2GKPWQBQcjs.d.call(void 0, this,b));_chunk2GKPWQBQcjs.f.call(void 0, this,S,_chunkBFM7DC5Ocjs.a.call(void 0, this.chain,t,(n=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:n.deviceSignerKeyStorage));try{return yield e()}finally{_chunk2GKPWQBQcjs.f.call(void 0, this,S,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return(yield this.signers()).some(t=>t.locator===e)})}isSignerApproved(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((t=r.signer)==null?void 0:t.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return _chunk2GKPWQBQcjs.d.call(void 0, this,T)}recover(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a,g;if(_chunkJX4QNRH6cjs.a.info("wallet.recover.start"),_chunk2GKPWQBQcjs.d.call(void 0, this,N)){_chunkJX4QNRH6cjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}let e=()=>{_chunk2GKPWQBQcjs.f.call(void 0, this,T,!1),_chunk2GKPWQBQcjs.f.call(void 0, this,N,!0)};if(((a=_chunk2GKPWQBQcjs.d.call(void 0, this,S))==null?void 0:a.type)==="device"&&(yield this.checkAndResumeDeviceSigner(_chunk2GKPWQBQcjs.d.call(void 0, this,S)))){e();return}if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)!=null&&_chunk2GKPWQBQcjs.d.call(void 0, this,S).type!=="device"){_chunkJX4QNRH6cjs.a.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"});return}let r=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null){if(!_chunk2GKPWQBQcjs.d.call(void 0, this,T))return;throw new Error("Device signer key storage is required to recover a device signer")}if(this.chain==="solana"){_chunkJX4QNRH6cjs.a.warn("wallet.recover.skipped",{reason:"Device signers are not supported on Solana"});return}let t=yield this.findLocalDeviceSigner(r);if(t!=null&&(yield this.checkAndResumeDeviceSigner(t))){_chunk2GKPWQBQcjs.f.call(void 0, this,S,t),e();let d=t.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,d)}catch(o){_chunkJX4QNRH6cjs.a.warn("wallet.recover.mapAddressToKey.error",{error:o})}return}let n=yield _chunkYHV3672Rcjs.a.call(void 0, r,this.address);try{yield this.addSigner(n)}catch(d){if(d instanceof Error&&d.message.toLowerCase().includes("delegated signer")&&d.message.toLowerCase().includes("already")&&d.message.toLowerCase().includes("approved"))_chunkJX4QNRH6cjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:n.locator});else throw _chunkJX4QNRH6cjs.a.error("wallet.recover.device.error",{error:d}),yield r.deleteKey(this.address),d}_chunk2GKPWQBQcjs.f.call(void 0, this,S,yield this.assembleFullSigner({type:"device",locator:n.locator,address:this.address},r)),_chunk2GKPWQBQcjs.d.call(void 0, this,S).type==="device"&&(_chunk2GKPWQBQcjs.d.call(void 0, this,S).status="success"),_chunkJX4QNRH6cjs.a.info("wallet.recover.device.success",{signerLocator:n.locator}),e()})}checkAndResumeDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;if(this.isApprovedSignerStatus(e.status))return _chunkJX4QNRH6cjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(t=r.signer)==null?void 0:t.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(_chunkJX4QNRH6cjs.a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a;let t=_chunk2GKPWQBQcjs.d.call(void 0, this,S),n=this.buildInternalSignerConfig(_chunk2GKPWQBQcjs.d.call(void 0, this,b));_chunk2GKPWQBQcjs.f.call(void 0, this,S,_chunkBFM7DC5Ocjs.a.call(void 0, this.chain,n,(a=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:a.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(g){throw _chunk2GKPWQBQcjs.f.call(void 0, this,S,e),g}finally{_chunk2GKPWQBQcjs.d.call(void 0, this,S)!==e&&_chunk2GKPWQBQcjs.f.call(void 0, this,S,t)}e.status="success",_chunkJX4QNRH6cjs.a.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=(yield this.signers()).filter(n=>n.locator.startsWith("device:"));for(let n of t){let a=n.locator.replace("device:","");try{if(yield e.hasKey(a)){let d=_chunkBFM7DC5Ocjs.a.call(void 0, this.chain,{type:"device",locator:n.locator,address:this.address},e);return _chunkJX4QNRH6cjs.a.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:n.locator}),d}}catch(g){_chunkJX4QNRH6cjs.a.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:n.locator,error:g})}}return null})}signers(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a,g;_chunkJX4QNRH6cjs.a.info("wallet.signers.start");let e=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getWallet(this.walletLocator);if("error"in e)throw _chunkJX4QNRH6cjs.a.error("wallet.signers.error",{error:e}),new (0, _chunkT3U46LK3cjs.e)(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw _chunkJX4QNRH6cjs.a.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new (0, _chunkT3U46LK3cjs.d)(`Wallet type ${e.type} not supported`);let r=(g=(a=e==null?void 0:e.config)==null?void 0:a.delegatedSigners)!=null?g:[],n=(yield Promise.all(r.map(d=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){try{return(yield this.getSignerState(d.locator)).signer}catch(o){return null}})))).filter(d=>d!=null);return _chunkJX4QNRH6cjs.a.info("wallet.signers.success",{count:n.length}),n})}get walletLocator(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,u).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(_chunk2GKPWQBQcjs.d.call(void 0, this,S)==null)throw _chunk2GKPWQBQcjs.d.call(void 0, this,x).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):_chunk2GKPWQBQcjs.d.call(void 0, this,b).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
|
|
2
2
|
Example: wallet.useSigner({ type: "server", secret: process.env.YOUR_SERVER_SECRET })`):_chunk2GKPWQBQcjs.d.call(void 0, this,b).type==="external-wallet"||!this.isAutoAssemblableSignerConfig(_chunk2GKPWQBQcjs.d.call(void 0, this,b))?new Error(`No signer is set. External wallet signers require calling wallet.useSigner() with the onSign callback before signing operations.
|
|
3
|
-
Example: wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... })`):new Error("This wallet is read-only because no signer was provided. Operations that require signing (send, approve, addSigner, etc.) are not available.");return _chunk2GKPWQBQcjs.d.call(void 0, this,S)}preAuthIfNeeded(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){yield _chunk2GKPWQBQcjs.d.call(void 0, this,D),_chunk2GKPWQBQcjs.d.call(void 0, this,F)==null&&_chunk2GKPWQBQcjs.f.call(void 0, this,F,this.recover());try{yield _chunk2GKPWQBQcjs.d.call(void 0, this,F)}finally{_chunk2GKPWQBQcjs.f.call(void 0, this,F,null)}let e=this.requireSigner();e instanceof _chunkEXQQQBO5cjs.a&&(yield e.ensureAuthenticated())})}isRecoverySigner(e){let r=_chunk2GKPWQBQcjs.d.call(void 0, this,b);if(r==null||r.type!==e.type||e.type==="device")return!1;if(e.type==="passkey")return!0;if(e.type==="server"&&r.type==="server"){let t=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress,n=_chunk3VSFHDFHcjs.b.call(void 0, r,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress;return t===n}return _chunkNX256LAHcjs.a.call(void 0, e)===_chunkNX256LAHcjs.a.call(void 0, r)}validateSignerInput(e){switch(e.type){case"email":if(!("email"in e)||e.email==null)throw new Error("Email signer requires an email address");break;case"phone":if(!("phone"in e)||e.phone==null)throw new Error("Phone signer requires a phone number");break;case"external-wallet":if(!("address"in e)||e.address==null)throw new Error("External wallet signer requires a wallet address");if(!("onSign"in e)||typeof e.onSign!="function")throw new Error("External wallet signer requires an onSign callback");break;case"passkey":case"device":case"api-key":break;default:break}}resolveDeviceSignerAvailability(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var g;let r=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null)throw new Error("Device signer key storage is required for device signers");let t=yield r.getKey(this.address);if(t!=null){e.locator=`device:${t}`;return}let a=(yield this.signers()).filter(d=>d.locator.startsWith("device:"));for(let d of a){let o=d.locator.replace("device:","");if(yield r.hasKey(o)){yield r.mapAddressToKey(this.address,o),e.locator=d.locator;return}}_chunk2GKPWQBQcjs.f.call(void 0, this,T,!0),_chunk2GKPWQBQcjs.f.call(void 0, this,N,!1)})}assembleFullSigner(n){return _chunk2GKPWQBQcjs.g.call(void 0, this,arguments,function*(e,r=(t=>(t=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:t.deviceSignerKeyStorage)()){var d;let a=_chunkTTDWZ77Ocjs.a.call(void 0, this.chain,e,r),g=yield this.getSignerState(a.locator());return a.status=(d=g.signer)==null?void 0:d.status,a})}getSignerState(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=null;try{r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSigner(this.walletLocator,e)}catch(n){return{response:null,signer:null,pendingOperation:null}}if(r==null||typeof r!="object"||"error"in r)return{response:null,signer:null,pendingOperation:null};let t=_chunkD6SLJ5C2cjs.b.call(void 0, r,this.chain);return{response:r,signer:t,pendingOperation:_chunkD6SLJ5C2cjs.c.call(void 0, r,this.chain)}})}buildInternalSignerConfig(e){var r,t,n,a,g,d;switch(e.type){case"email":return{type:"email",email:e.email,locator:`email:${e.email}`,address:this.address,crossmint:_chunk2GKPWQBQcjs.d.call(void 0, this,u).crossmint,clientTEEConnection:(r=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:r.clientTEEConnection,onAuthRequired:(n=(t=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:t.callbacks)==null?void 0:n.onAuthRequired};case"phone":return{type:"phone",phone:e.phone,locator:`phone:${e.phone}`,address:this.address,crossmint:_chunk2GKPWQBQcjs.d.call(void 0, this,u).crossmint,clientTEEConnection:(a=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:a.clientTEEConnection,onAuthRequired:(d=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.callbacks)==null?void 0:d.onAuthRequired};case"passkey":{let o="id"in e&&e.id?e.id:"";return{type:"passkey",id:o,locator:`passkey:${o}`,name:"name"in e?e.name:void 0,publicKey:"publicKey"in e?e.publicKey:void 0,onCreatePasskey:e.onCreatePasskey,onSignWithPasskey:e.onSignWithPasskey}}case"device":return{type:"device",locator:"locator"in e&&e.locator?e.locator:void 0,address:this.address};case"external-wallet":return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},e),{locator:`external-wallet:${e.address}`});case"api-key":return{type:"api-key",locator:"api-key",address:this.address};case"server":{let{derivedKeyBytes:o,derivedAddress:l}=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return{type:"server",derivedKeyBytes:o,locator:`server:${l}`,address:l}}default:throw new Error(`Unknown signer type: ${e==null?void 0:e.type}`)}}isAutoAssemblableSignerConfig(e){switch(e.type){case"email":case"phone":case"passkey":case"api-key":case"device":return!0;case"server":return"secret"in e&&typeof e.secret=="string";case"external-wallet":return"onSign"in e&&typeof e.onSign=="function";default:return!1}}get isSolanaWallet(){return this.chain==="solana"}resolveChainForEnvironment(){let e=_chunkZZBLGUBWcjs.f.call(void 0, this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return e!==this.chain&&(this.chain=e),this.chain}approveTransactionAndWait(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.approveTransactionInternal(e,r),yield this.sleep(1e3),yield this.waitForTransaction(e)})}approveSignatureAndWait(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield this.approveSignatureInternal(e,r);return!("error"in t)&&t.status==="success"&&t.outputSignature!=null?{signature:t.outputSignature,signatureId:e}:(yield this.sleep(1e3),yield this.waitForSignature(e))})}approveSignatureInternal(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,l;if(this.isSolanaWallet)throw new Error("Approving signatures is only supported for EVM smart wallets");let t=this.requireSigner(),n=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSignature(this.walletLocator,e);if("error"in n)throw new (0, _chunkT3U46LK3cjs.q)(JSON.stringify(n));if(t.type==="api-key")return n;if((r==null?void 0:r.approval)!=null){let h=[r.approval];return yield this.executeApproveSignatureWithErrorHandling(e,h)}let a=(o=n.approvals)==null?void 0:o.pending;if(a==null)return n;let g=[...(l=r==null?void 0:r.additionalSigners)!=null?l:[],t],d=yield Promise.all(a.map(h=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let f=g.find(y=>y.locator()===h.signer.locator);if(f==null)throw new (0, _chunkT3U46LK3cjs.j)(`Signer ${h.signer.locator} not found in pending approvals`);let v=yield f.signMessage(h.message);return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},v),{signer:f.locator()})})));return yield this.executeApproveSignatureWithErrorHandling(e,d)})}approveTransactionInternal(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,l,h,f,v;let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e);if("error"in t)throw new (0, _chunkT3U46LK3cjs.u)(JSON.stringify(t));yield(h=(l=(o=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:o.callbacks)==null?void 0:l.onTransactionStart)==null?void 0:h.call(l);let n=this.requireSigner();if(n.type==="api-key")return t;if((r==null?void 0:r.approval)!=null){let y=[r.approval];return yield this.executeApproveTransactionWithErrorHandling(e,y)}let a=(f=t.approvals)==null?void 0:f.pending;if(a==null)return t;let g=[...(v=r==null?void 0:r.additionalSigners)!=null?v:[],n],d=yield Promise.all(a.map(y=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let I=g.find(le=>le.locator()===y.signer.locator);if(I==null)throw new (0, _chunkT3U46LK3cjs.j)(`Signer ${y.signer.locator} not found in pending approvals`);let $=I.type==="device",K=t.chainType==="solana"&&"transaction"in t.onChain&&!$?t.onChain.transaction:y.message,oe=yield I.signTransaction(K);return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},oe),{signer:I.locator()})})));return yield this.executeApproveTransactionWithErrorHandling(e,d)})}executeApproveTransactionWithErrorHandling(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkIBEOC3PYcjs.a.info("wallet.approve: submitting approval to API",{transactionId:e});let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).approveTransaction(this.walletLocator,e,{approvals:r});if(t.error)throw new (0, _chunkT3U46LK3cjs.z)(JSON.stringify(t));return t})}executeApproveSignatureWithErrorHandling(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).approveSignature(this.walletLocator,e,{approvals:r});if(t.error)throw new (0, _chunkT3U46LK3cjs.r)(JSON.stringify(t));return t})}waitForSignature(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=null;do if(yield new Promise(t=>setTimeout(t,_chunkSCPDMHCRcjs.d)),r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSignature(this.walletLocator,e),"error"in r)throw new (0, _chunkT3U46LK3cjs.q)(JSON.stringify(r));while(r===null||r.status==="pending");if(r.status==="failed")throw new (0, _chunkT3U46LK3cjs.n)("Signature signing failed");if(!r.outputSignature)throw new (0, _chunkT3U46LK3cjs.q)("Signature not available");return{signature:r.outputSignature,signatureId:e}})}waitForTransaction(g){return _chunk2GKPWQBQcjs.g.call(void 0, this,arguments,function*(e,r=6e4,{backoffMultiplier:t=1.1,maxBackoffMs:n=2e3,initialBackoffMs:a=_chunkSCPDMHCRcjs.d}={}){var f,v;_chunkIBEOC3PYcjs.a.info("wallet.approve: waiting for transaction confirmation",{transactionId:e,timeoutMs:r});let d=Date.now(),o;do{if(Date.now()-d>r)throw new (0, _chunkT3U46LK3cjs.v)("Transaction confirmation timeout");if(o=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e),o.error)throw new (0, _chunkT3U46LK3cjs.u)(JSON.stringify(o));yield this.sleep(a),a=Math.min(a*t,n)}while(o.status==="pending");if(o.status==="failed")throw new (0, _chunkT3U46LK3cjs.w)(`Transaction sending failed: ${JSON.stringify(o.error)}`);if(o.status==="awaiting-approval")throw new (0, _chunkT3U46LK3cjs.x)("Transaction is awaiting approval. Please submit required approvals before waiting for completion.");let l="txHash"in o.onChain&&typeof o.onChain.txHash=="string"?o.onChain.txHash:void 0,h=(f=o.onChain.txId)!=null?f:l;if(h==null)throw new (0, _chunkT3U46LK3cjs.y)("Transaction hash not found on transaction response");return{hash:h,explorerLink:(v=o.onChain.explorerLink)!=null?v:"",transactionId:o.id}})}sleep(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return new Promise(r=>setTimeout(r,e))})}};S=new WeakMap,m=new WeakMap,u=new WeakMap,b=new WeakMap,x=new WeakMap,T=new WeakMap,N=new WeakMap,D=new WeakMap,F=new WeakMap,_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.balances",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"balances",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.stagingFund",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"stagingFund",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.send",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"send",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.approve",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"approve",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.addSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"addSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.removeSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"removeSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.useSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"useSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.recover",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"recover",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkIBEOC3PYcjs.a,methodName:"wallet.signers",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"signers",1);function ce(w){if(typeof w=="string"){if(!_commonsdkbase.isValidAddress.call(void 0, w))throw new (0, _chunkT3U46LK3cjs.B)(`Invalid recipient address: "${w}". Expected a valid EVM (0x...), Solana (base58), or Stellar (G.../C...) address.`);return w}if("email"in w)return`email:${w.email}`;if("x"in w)return`x:${w.x}`;if("twitter"in w)return`twitter:${w.twitter}`;if("phone"in w)return`phoneNumber:${w.phone}`;if("userId"in w)return`userId:${w.userId}`;throw new Error("Invalid recipient locator")}function de(w,e){return _commonsdkbase.isValidAddress.call(void 0, w)?`${e}:${w}`:`${e}:${w.toLowerCase()}`}exports.a = A;
|
|
3
|
+
Example: wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... })`):new Error("This wallet is read-only because no signer was provided. Operations that require signing (send, approve, addSigner, etc.) are not available.");return _chunk2GKPWQBQcjs.d.call(void 0, this,S)}preAuthIfNeeded(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){yield _chunk2GKPWQBQcjs.d.call(void 0, this,D),_chunk2GKPWQBQcjs.d.call(void 0, this,F)==null&&_chunk2GKPWQBQcjs.f.call(void 0, this,F,this.recover());try{yield _chunk2GKPWQBQcjs.d.call(void 0, this,F)}finally{_chunk2GKPWQBQcjs.f.call(void 0, this,F,null)}let e=this.requireSigner();e instanceof _chunkY76OKATGcjs.a&&(yield e.ensureAuthenticated())})}isRecoverySigner(e){let r=_chunk2GKPWQBQcjs.d.call(void 0, this,b);if(r==null||r.type!==e.type||e.type==="device")return!1;if(e.type==="passkey")return!0;if(e.type==="server"&&r.type==="server"){let t=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress,n=_chunk3VSFHDFHcjs.b.call(void 0, r,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment).derivedAddress;return t===n}return _chunkNX256LAHcjs.a.call(void 0, e)===_chunkNX256LAHcjs.a.call(void 0, r)}validateSignerInput(e){switch(e.type){case"email":if(!("email"in e)||e.email==null)throw new Error("Email signer requires an email address");break;case"phone":if(!("phone"in e)||e.phone==null)throw new Error("Phone signer requires a phone number");break;case"external-wallet":if(!("address"in e)||e.address==null)throw new Error("External wallet signer requires a wallet address");if(!("onSign"in e)||typeof e.onSign!="function")throw new Error("External wallet signer requires an onSign callback");break;case"passkey":case"device":case"api-key":break;default:break}}resolveDeviceSignerAvailability(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var g;let r=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null)throw new Error("Device signer key storage is required for device signers");let t=yield r.getKey(this.address);if(t!=null){e.locator=`device:${t}`;return}let a=(yield this.signers()).filter(d=>d.locator.startsWith("device:"));for(let d of a){let o=d.locator.replace("device:","");if(yield r.hasKey(o)){yield r.mapAddressToKey(this.address,o),e.locator=d.locator;return}}_chunk2GKPWQBQcjs.f.call(void 0, this,T,!0),_chunk2GKPWQBQcjs.f.call(void 0, this,N,!1)})}assembleFullSigner(n){return _chunk2GKPWQBQcjs.g.call(void 0, this,arguments,function*(e,r=(t=>(t=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:t.deviceSignerKeyStorage)()){var d;let a=_chunkBFM7DC5Ocjs.a.call(void 0, this.chain,e,r),g=yield this.getSignerState(a.locator());return a.status=(d=g.signer)==null?void 0:d.status,a})}getSignerState(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=null;try{r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSigner(this.walletLocator,e)}catch(n){return{response:null,signer:null,pendingOperation:null}}if(r==null||typeof r!="object"||"error"in r)return{response:null,signer:null,pendingOperation:null};let t=_chunkD6SLJ5C2cjs.b.call(void 0, r,this.chain);return{response:r,signer:t,pendingOperation:_chunkD6SLJ5C2cjs.c.call(void 0, r,this.chain)}})}buildInternalSignerConfig(e){var r,t,n,a,g,d;switch(e.type){case"email":return{type:"email",email:e.email,locator:`email:${e.email}`,address:this.address,crossmint:_chunk2GKPWQBQcjs.d.call(void 0, this,u).crossmint,clientTEEConnection:(r=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:r.clientTEEConnection,onAuthRequired:(n=(t=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:t.callbacks)==null?void 0:n.onAuthRequired};case"phone":return{type:"phone",phone:e.phone,locator:`phone:${e.phone}`,address:this.address,crossmint:_chunk2GKPWQBQcjs.d.call(void 0, this,u).crossmint,clientTEEConnection:(a=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:a.clientTEEConnection,onAuthRequired:(d=(g=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:g.callbacks)==null?void 0:d.onAuthRequired};case"passkey":{let o="id"in e&&e.id?e.id:"";return{type:"passkey",id:o,locator:`passkey:${o}`,name:"name"in e?e.name:void 0,publicKey:"publicKey"in e?e.publicKey:void 0,onCreatePasskey:e.onCreatePasskey,onSignWithPasskey:e.onSignWithPasskey}}case"device":return{type:"device",locator:"locator"in e&&e.locator?e.locator:void 0,address:this.address};case"external-wallet":return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},e),{locator:`external-wallet:${e.address}`});case"api-key":return{type:"api-key",locator:"api-key",address:this.address};case"server":{let{derivedKeyBytes:o,derivedAddress:l}=_chunk3VSFHDFHcjs.b.call(void 0, e,this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).projectId,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return{type:"server",derivedKeyBytes:o,locator:`server:${l}`,address:l}}default:throw new Error(`Unknown signer type: ${e==null?void 0:e.type}`)}}isAutoAssemblableSignerConfig(e){switch(e.type){case"email":case"phone":case"passkey":case"api-key":case"device":return!0;case"server":return"secret"in e&&typeof e.secret=="string";case"external-wallet":return"onSign"in e&&typeof e.onSign=="function";default:return!1}}get isSolanaWallet(){return this.chain==="solana"}resolveChainForEnvironment(){let e=_chunkZTIMDM5Vcjs.f.call(void 0, this.chain,_chunk2GKPWQBQcjs.d.call(void 0, this,u).environment);return e!==this.chain&&(this.chain=e),this.chain}approveTransactionAndWait(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.approveTransactionInternal(e,r),yield this.sleep(1e3),yield this.waitForTransaction(e)})}approveSignatureAndWait(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield this.approveSignatureInternal(e,r);return!("error"in t)&&t.status==="success"&&t.outputSignature!=null?{signature:t.outputSignature,signatureId:e}:(yield this.sleep(1e3),yield this.waitForSignature(e))})}approveSignatureInternal(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,l;if(this.isSolanaWallet)throw new Error("Approving signatures is only supported for EVM smart wallets");let t=this.requireSigner(),n=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSignature(this.walletLocator,e);if("error"in n)throw new (0, _chunkT3U46LK3cjs.q)(JSON.stringify(n));if(t.type==="api-key")return n;if((r==null?void 0:r.approval)!=null){let h=[r.approval];return yield this.executeApproveSignatureWithErrorHandling(e,h)}let a=(o=n.approvals)==null?void 0:o.pending;if(a==null)return n;let g=[...(l=r==null?void 0:r.additionalSigners)!=null?l:[],t],d=yield Promise.all(a.map(h=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let f=g.find(y=>y.locator()===h.signer.locator);if(f==null)throw new (0, _chunkT3U46LK3cjs.j)(`Signer ${h.signer.locator} not found in pending approvals`);let v=yield f.signMessage(h.message);return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},v),{signer:f.locator()})})));return yield this.executeApproveSignatureWithErrorHandling(e,d)})}approveTransactionInternal(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,l,h,f,v;let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e);if("error"in t)throw new (0, _chunkT3U46LK3cjs.u)(JSON.stringify(t));yield(h=(l=(o=_chunk2GKPWQBQcjs.d.call(void 0, this,m))==null?void 0:o.callbacks)==null?void 0:l.onTransactionStart)==null?void 0:h.call(l);let n=this.requireSigner();if(n.type==="api-key")return t;if((r==null?void 0:r.approval)!=null){let y=[r.approval];return yield this.executeApproveTransactionWithErrorHandling(e,y)}let a=(f=t.approvals)==null?void 0:f.pending;if(a==null)return t;let g=[...(v=r==null?void 0:r.additionalSigners)!=null?v:[],n],d=yield Promise.all(a.map(y=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let R=g.find(le=>le.locator()===y.signer.locator);if(R==null)throw new (0, _chunkT3U46LK3cjs.j)(`Signer ${y.signer.locator} not found in pending approvals`);let $=R.type==="device",K=t.chainType==="solana"&&"transaction"in t.onChain&&!$?t.onChain.transaction:y.message,oe=yield R.signTransaction(K);return _chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},oe),{signer:R.locator()})})));return yield this.executeApproveTransactionWithErrorHandling(e,d)})}executeApproveTransactionWithErrorHandling(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("wallet.approve: submitting approval to API",{transactionId:e});let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).approveTransaction(this.walletLocator,e,{approvals:r});if(t.error)throw new (0, _chunkT3U46LK3cjs.z)(JSON.stringify(t));return t})}executeApproveSignatureWithErrorHandling(e,r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).approveSignature(this.walletLocator,e,{approvals:r});if(t.error)throw new (0, _chunkT3U46LK3cjs.r)(JSON.stringify(t));return t})}waitForSignature(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let r=null;do if(yield new Promise(t=>setTimeout(t,_chunkBFN7XMPWcjs.d)),r=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getSignature(this.walletLocator,e),"error"in r)throw new (0, _chunkT3U46LK3cjs.q)(JSON.stringify(r));while(r===null||r.status==="pending");if(r.status==="failed")throw new (0, _chunkT3U46LK3cjs.n)("Signature signing failed");if(!r.outputSignature)throw new (0, _chunkT3U46LK3cjs.q)("Signature not available");return{signature:r.outputSignature,signatureId:e}})}waitForTransaction(g){return _chunk2GKPWQBQcjs.g.call(void 0, this,arguments,function*(e,r=6e4,{backoffMultiplier:t=1.1,maxBackoffMs:n=2e3,initialBackoffMs:a=_chunkBFN7XMPWcjs.d}={}){var f,v;_chunkJX4QNRH6cjs.a.info("wallet.approve: waiting for transaction confirmation",{transactionId:e,timeoutMs:r});let d=Date.now(),o;do{if(Date.now()-d>r)throw new (0, _chunkT3U46LK3cjs.v)("Transaction confirmation timeout");if(o=yield _chunk2GKPWQBQcjs.d.call(void 0, this,u).getTransaction(this.walletLocator,e),o.error)throw new (0, _chunkT3U46LK3cjs.u)(JSON.stringify(o));yield this.sleep(a),a=Math.min(a*t,n)}while(o.status==="pending");if(o.status==="failed")throw new (0, _chunkT3U46LK3cjs.w)(`Transaction sending failed: ${JSON.stringify(o.error)}`);if(o.status==="awaiting-approval")throw new (0, _chunkT3U46LK3cjs.x)("Transaction is awaiting approval. Please submit required approvals before waiting for completion.");let l="txHash"in o.onChain&&typeof o.onChain.txHash=="string"?o.onChain.txHash:void 0,h=(f=o.onChain.txId)!=null?f:l;if(h==null)throw new (0, _chunkT3U46LK3cjs.y)("Transaction hash not found on transaction response");return{hash:h,explorerLink:(v=o.onChain.explorerLink)!=null?v:"",transactionId:o.id}})}sleep(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return new Promise(r=>setTimeout(r,e))})}};S=new WeakMap,m=new WeakMap,u=new WeakMap,b=new WeakMap,x=new WeakMap,T=new WeakMap,N=new WeakMap,D=new WeakMap,F=new WeakMap,_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.balances",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"balances",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.stagingFund",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"stagingFund",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.send",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"send",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.approve",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"approve",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.addSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"addSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.removeSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"removeSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.useSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"useSigner",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.recover",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"recover",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"wallet.signers",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"signers",1);function ce(w){if(typeof w=="string"){if(!_commonsdkbase.isValidAddress.call(void 0, w))throw new (0, _chunkT3U46LK3cjs.B)(`Invalid recipient address: "${w}". Expected a valid EVM (0x...), Solana (base58), or Stellar (G.../C...) address.`);return w}if("email"in w)return`email:${w.email}`;if("x"in w)return`x:${w.x}`;if("twitter"in w)return`twitter:${w.twitter}`;if("phone"in w)return`phoneNumber:${w.phone}`;if("userId"in w)return`userId:${w.userId}`;throw new Error("Invalid recipient locator")}function de(w,e){return _commonsdkbase.isValidAddress.call(void 0, w)?`${e}:${w}`:`${e}:${w.toLowerCase()}`}exports.a = A;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-EXC7TCGL.js";import{a}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-EXC7TCGL.js";import{a}from"./chunk-EDN5LPJV.js";import{b as p,c}from"./chunk-YXHWN6FD.js";import{g as t}from"./chunk-J3R36SGJ.js";import{APIKeyEnvironmentPrefix as d,APIKeyUsageOrigin as g,CrossmintApiClient as P}from"@crossmint/common-sdk-base";var l=class extends P{constructor(e){super(e,{internalConfig:{sdkMetadata:{name:c,version:p}}});this.apiPrefix="api/2025-06-09/wallets";this.unstableApiPrefix="api/unstable/wallets"}createWallet(e){return t(this,null,function*(){let s=this.isServerSide?`${this.apiPrefix}`:`${this.apiPrefix}/me`;a.info("wallets.api.createWallet",{chainType:e.chainType,walletType:e.type});let n=yield(yield this.post(s,{body:JSON.stringify(e),headers:this.headers})).json();return"error"in n?a.error("wallets.api.createWallet.error",{error:n.error,chainType:e.chainType}):"address"in n&&a.info("wallets.api.createWallet.success",{address:n.address,chainType:e.chainType}),n})}getWallet(e){return t(this,null,function*(){a.info("wallets.api.getWallet",{locator:e});let r=yield(yield this.get(`${this.apiPrefix}/${e}`,{headers:this.headers})).json();return"error"in r?a.warn("wallets.api.getWallet.error",{locator:e,error:r.error}):"address"in r&&a.info("wallets.api.getWallet.success",{address:r.address,locator:e}),r})}createTransaction(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveTransaction(e,s,r){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getTransaction(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions/${s}`,{headers:this.headers})).json()})}createSignature(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveSignature(e,s,r){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getSignature(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/signatures/${s}`,{headers:this.headers})).json()})}getTransactions(e){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions`,{headers:this.headers})).json()})}getNfts(e){return t(this,null,function*(){let s=new URLSearchParams;s.append("page",e.page.toString()),s.append("perPage",e.perPage.toString());let r=`${e.chain}:${e.address}`;return(yield this.get(`${this.apiPrefix}/${r}/nfts?${s.toString()}`,{headers:this.headers})).json()})}getTransfers(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("chain",s.chain.toString()),s.tokens!=null&&r.append("tokens",s.tokens),s.status!=null&&r.append("status",s.status),(yield this.get(`${this.unstableApiPrefix}/${e}/transfers?${r.toString()}`,{headers:this.headers})).json()})}getBalance(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("tokens",s.tokens.join(",")),r.append("chains",s.chains.join(",")),(yield this.get(`${this.apiPrefix}/${e}/balances?${r.toString()}`,{headers:this.headers})).json()})}fundWallet(e,s){return t(this,null,function*(){if(this.environment===d.PRODUCTION)throw new Error("Funding wallets is only supported in staging environment");return(yield this.post(`api/v1-alpha2/wallets/${e}/balances`,{body:JSON.stringify(s),headers:this.headers})).json()})}registerSigner(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signers`,{body:JSON.stringify(s),headers:this.headers})).json()})}removeSigner(e,s,r){return t(this,null,function*(){let n=encodeURIComponent(s),i=new URLSearchParams;r.chain&&i.append("chain",r.chain);let h=`${this.apiPrefix}/${e}/signers/${n}${i.size>0?`?${i.toString()}`:""}`;return(yield this.delete(h,{headers:this.headers})).json()})}getSigner(e,s){return t(this,null,function*(){let r=encodeURIComponent(s);return(yield this.get(`${this.apiPrefix}/${e}/signers/${r}`,{headers:this.headers})).json()})}send(e,s,r){return t(this,null,function*(){a.info("wallets.api.send",{walletLocator:e,tokenLocator:s,recipient:r.recipient});let i=yield(yield this.post(`${this.apiPrefix}/${e}/tokens/${s}/transfers`,{body:JSON.stringify(r),headers:this.headers})).json();return"error"in i?a.error("wallets.api.send.error",{walletLocator:e,tokenLocator:s,error:i.error}):"id"in i&&a.info("wallets.api.send.success",{walletLocator:e,transactionId:i.id}),i})}get isServerSide(){return this.parsedAPIKey.usageOrigin===g.SERVER}get environment(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.environment}get projectId(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.projectId}get headers(){return{"Content-Type":"application/json"}}};export{l as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as n}from"./chunk-
|
|
1
|
+
import{a as n}from"./chunk-HCD56LQH.js";import{a as s}from"./chunk-N4IWDL6M.js";import{a as l}from"./chunk-TEY5A2C6.js";import{a,b as i}from"./chunk-EDN5LPJV.js";import{g as r}from"./chunk-J3R36SGJ.js";import{createCrossmint as C}from"@crossmint/common-sdk-base";import{WebAuthnP256 as p}from"ox";var o=class c{constructor(e){i(e.apiKey);let t=new l(e);this.walletFactory=new n(t),a.info("wallets.sdk.initialized")}static from(e){return new c(e)}getWallet(e,t){return r(this,null,function*(){if(typeof e=="string"){if(t==null)throw new Error("Args parameter is required when walletLocator is provided");return yield this.walletFactory.getWallet(e,t)}return yield this.walletFactory.getWallet(e)})}createWallet(e){return r(this,null,function*(){return yield this.walletFactory.createWallet(e)})}createDeviceSigner(e,t){return r(this,null,function*(){return yield s(e,t)})}createPasskeySigner(e){return r(this,null,function*(){let t=yield p.createCredential({name:e});return{type:"passkey",id:t.id,name:e,publicKey:{x:t.publicKey.x.toString(),y:t.publicKey.y.toString()}}})}};export{C as a,o as b};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as ae}from"./chunk-N4IWDL6M.js";import{a as W}from"./chunk-GOXB2RBF.js";import{b as G,c as M}from"./chunk-VADIEIDS.js";import{a as O}from"./chunk-FBFT2E6I.js";import{b as L}from"./chunk-RBSMBO4T.js";import{a as ne}from"./chunk-U2NZDB37.js";import{f as ie}from"./chunk-JLQXK6OD.js";import{B as te,d as j,e as _,j as B,n as U,q,r as V,s as z,t as Y,u as J,v as Q,w as X,x as Z,y as ee,z as re}from"./chunk-EXC7TCGL.js";import{a as s}from"./chunk-EIM3O5OX.js";import{d as H}from"./chunk-FFEHHGVZ.js";import{a as C,b as P,c as E,d as i,e as k,f as p,g as c}from"./chunk-J3R36SGJ.js";import{isValidAddress as se,WithLoggerContext as R}from"@crossmint/common-sdk-base";var S,m,u,b,x,T,N,D,F,A=class{constructor(e,r){k(this,S);k(this,m);k(this,u);k(this,b);k(this,x);k(this,T,!1);k(this,N,!1);k(this,D);k(this,F,null);let{chain:t,address:n,owner:a,options:g,alias:d,recovery:o,signers:l,signer:h}=e;p(this,u,r),this.chain=t,this.address=n,this.owner=a,p(this,m,g),this.alias=d,p(this,b,o),p(this,x,l!=null?l:[]),p(this,S,h),p(this,D,this.initDefaultSigner())}get signer(){return i(this,S)}initDeviceSigner(){return c(this,null,function*(){var n;let e=(n=i(this,m))==null?void 0:n.deviceSignerKeyStorage;if(e==null||this.chain==="solana")return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(a){s.error("wallet.initDeviceSigner.error",{error:a}),p(this,T,!0);return}if(i(this,T))return;let t=this.buildInternalSignerConfig(r);p(this,S,yield this.assembleFullSigner(t,e))})}initDefaultSigner(){return c(this,null,function*(){if(i(this,S)!=null||(yield this.initDeviceSigner(),i(this,S)!=null||i(this,T)))return;let e=i(this,x).length===0?i(this,b):i(this,x).length===1?i(this,x)[0]:null;if(e!=null&&this.isAutoAssemblableSignerConfig(e))try{let r=this.buildInternalSignerConfig(e);p(this,S,yield this.assembleFullSigner(r))}catch(r){s.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:i(this,b).type,signerCount:i(this,x).length,error:r})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return i(e,b)}static getInitialSigners(e){return i(e,x)}get apiClient(){return i(this,u)}get options(){return i(this,m)}get recovery(){return i(this,b)}balances(e){return c(this,null,function*(){s.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),t;switch(this.chain){case"solana":t="sol";break;case"stellar":t="xlm";break;default:t="eth";break}let n=[t,"usdc",...e!=null?e:[]],a=yield i(this,u).getBalance(this.address,{chains:[r],tokens:n});if("error"in a)throw s.error("wallet.balances.error",{error:a}),new Error(`Failed to get balances for wallet: ${JSON.stringify(a.message)}`);return s.info("wallet.balances.success"),this.transformBalanceResponse(a,t,e)})}stagingFund(e,r){return c(this,null,function*(){s.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let t=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in t)throw s.error("wallet.stagingFund.error",{error:t}),new Error(`Failed to fund wallet: ${JSON.stringify(t.message)}`);return s.info("wallet.stagingFund.success"),t})}transformBalanceResponse(e,r,t){let n=l=>{var v,y,I,$,K;let h=(v=l.chains)==null?void 0:v[this.chain],f={};return this.chain==="solana"&&h!=null&&"mintHash"in h?f={mintHash:h.mintHash}:this.chain==="stellar"&&h!=null&&"contractId"in h?f={contractId:h.contractId}:h!=null&&"contractAddress"in h&&(f={contractAddress:h.contractAddress}),C({symbol:(y=l.symbol)!=null?y:"",name:(I=l.name)!=null?I:"",amount:($=l.amount)!=null?$:"0",decimals:l.decimals,rawAmount:(K=l.rawAmount)!=null?K:"0"},f)},a=e.find(l=>l.symbol===r),g=e.find(l=>l.symbol==="usdc"),d=e.filter(l=>{var h;return l.symbol!==r&&l.symbol!=="usdc"&&(t==null||t.includes((h=l.symbol)!=null?h:""))}),o=l=>{let h={symbol:l,name:l,amount:"0",decimals:0,rawAmount:"0"},f={};return this.chain==="solana"?f={mintHash:void 0}:this.chain==="stellar"?f={contractId:void 0}:f={contractAddress:void 0},C(C({},h),f)};return{nativeToken:a!=null?n(a):o(r),usdc:g!=null?n(g):o("usdc"),tokens:d.map(n)}}nfts(e){return c(this,null,function*(){return yield i(this,u).getNfts(P(C({},e),{chain:this.chain,address:this.address}))})}transactions(){return c(this,null,function*(){let e=yield i(this,u).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return c(this,null,function*(){let r=yield i(this,u).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return c(this,null,function*(){let r=this.resolveChainForEnvironment(),t=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e==null?void 0:e.tokens,status:e==null?void 0:e.status});if("error"in t)throw new Error(`Failed to get transfers: ${JSON.stringify(t.message)}`);return t})}send(e,r,t,n){return c(this,null,function*(){let a=this.resolveChainForEnvironment(),g=ce(e),d=de(r,a),o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o)||o<=0)throw new z(`Invalid transfer amount: "${t}". Amount must be a positive number greater than zero.`);s.info("wallet.send.start",C({recipient:g,token:d,amount:t},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{})),yield this.preAuthIfNeeded();let l=this.requireSigner(),h;(n==null?void 0:n.signer)==null?h=l.locator():typeof n.signer=="string"?h=n.signer:h=`server:${L(n.signer,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress}`;let f=C({recipient:g,amount:t,signer:h},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{}),v=yield i(this,u).send(this.walletLocator,d,f);if("message"in v)throw s.error("wallet.send.error",{error:v}),new Y(`Failed to send token: ${JSON.stringify(v.message)}`);if((n==null?void 0:n.prepareOnly)===!0)return s.info("wallet.send.prepared",{transactionId:v.id}),{hash:void 0,explorerLink:void 0,transactionId:v.id};let y=yield this.approveTransactionAndWait(v.id);return s.info("wallet.send.success",{transactionId:v.id,hash:y.hash}),y})}approveTransaction(e){return c(this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return c(this,null,function*(){if(this.requireSigner(),s.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return s.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return s.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw s.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return c(this,null,function*(){if(s.info("wallet.addSigner.start"),e.type==="device"&&this.chain==="solana")throw new B("Device signers are not currently supported for Solana wallets. Contact sales (https://www.crossmint.com/contact/sales) for access.");let t=typeof e=="object"&&"type"in e&&e.type==="server"?`server:${L(e,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress}`:e;return this.withRecoverySigner(()=>c(this,null,function*(){var d;let n=typeof t=="string"||t.type==="passkey"?t:t.type==="device"&&"publicKey"in t&&t.publicKey!=null?{type:"device",publicKey:t.publicKey,name:t.name}:W(t),a=yield i(this,u).registerSigner(this.walletLocator,{signer:n,chain:this.getSignerRegistrationChain()});if("error"in a)throw s.error("wallet.addSigner.error",{error:a}),new Error(`Failed to register signer: ${JSON.stringify(a.message)}`);let g=G(a,this.chain);if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in a)||a.transaction==null)throw s.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");let o=a.transaction.id;if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);return r!=null&&r.prepareOnly?(s.info("wallet.addSigner.prepared",{transactionId:o}),P(C({},g),{transactionId:o})):(yield this.approveTransactionAndWait(o),s.info("wallet.addSigner.success",{transactionId:o}),P(C({},g),{status:"success"}))}else{if(!("chains"in a))throw s.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");let o=(d=a.chains)==null?void 0:d[this.chain];if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let l=M(a,this.chain),h=(l==null?void 0:l.type)==="signature"?l.id:void 0;if(r!=null&&r.prepareOnly)return s.info("wallet.addSigner.prepared",{signatureId:h}),P(C({},g),{signatureId:h});if((l==null?void 0:l.type)==="signature")yield this.approveSignatureAndWait(l.id),s.info("wallet.addSigner.success",{signatureId:l.id});else{if((o==null?void 0:o.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);s.info("wallet.addSigner.success")}return P(C({},g),{status:"success"})}}))})}removeSigner(e,r){return c(this,null,function*(){let t=this.resolveSignerLocator(e);return s.info("wallet.removeSigner.start",{signerLocator:t}),this.withRecoverySigner(()=>c(this,null,function*(){let n=yield i(this,u).removeSigner(this.walletLocator,t,{chain:this.getSignerRegistrationChain()});if("error"in n)throw s.error("wallet.removeSigner.error",{error:n}),new Error(`Failed to remove signer: ${JSON.stringify(n)}`);let a=n.id;return r!=null&&r.prepareOnly?(s.info("wallet.removeSigner.prepared",{transactionId:a}),{transactionId:a,status:void 0}):(yield this.approveTransactionAndWait(a),s.info("wallet.removeSigner.success",{transactionId:a}),{transactionId:a,status:"success"})}))})}useSigner(e){return c(this,null,function*(){s.info("wallet.useSigner.start"),this.validateSignerInput(e),e.type==="device"?yield this.resolveDeviceSignerAvailability(e):yield this.resolveNonDeviceSigner(e);let r=this.buildInternalSignerConfig(e),t=W(e);p(this,S,yield this.assembleFullSigner(r)),s.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return c(this,null,function*(){if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e)){p(this,T,!1);return}throw new Error("No passkey signer is registered on this wallet.")}let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r)){p(this,T,!1);return}if(this.isRecoverySigner(e)){p(this,T,!1);return}throw new Error(`Signer "${r}" is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return c(this,null,function*(){let t=(yield this.signers()).filter(n=>n.type==="passkey");if(t.length===0)return!1;if(t.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=t[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){if(e.type==="server"){let{derivedAddress:r}=L(e,this.chain,i(this,u).projectId,i(this,u).environment);return`server:${r}`}return W(e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return c(this,null,function*(){var n;let r=this.signer,t=this.buildInternalSignerConfig(i(this,b));p(this,S,O(this.chain,t,(n=i(this,m))==null?void 0:n.deviceSignerKeyStorage));try{return yield e()}finally{p(this,S,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return c(this,null,function*(){return(yield this.signers()).some(t=>t.locator===e)})}isSignerApproved(e){return c(this,null,function*(){var t;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((t=r.signer)==null?void 0:t.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return i(this,T)}recover(){return c(this,null,function*(){var a,g;if(s.info("wallet.recover.start"),i(this,N)){s.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}let e=()=>{p(this,T,!1),p(this,N,!0)};if(((a=i(this,S))==null?void 0:a.type)==="device"&&(yield this.checkAndResumeDeviceSigner(i(this,S)))){e();return}if(i(this,S)!=null&&i(this,S).type!=="device"){s.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"});return}let r=(g=i(this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null){if(!i(this,T))return;throw new Error("Device signer key storage is required to recover a device signer")}if(this.chain==="solana"){s.warn("wallet.recover.skipped",{reason:"Device signers are not supported on Solana"});return}let t=yield this.findLocalDeviceSigner(r);if(t!=null&&(yield this.checkAndResumeDeviceSigner(t))){p(this,S,t),e();let d=t.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,d)}catch(o){s.warn("wallet.recover.mapAddressToKey.error",{error:o})}return}let n=yield ae(r,this.address);try{yield this.addSigner(n)}catch(d){if(d instanceof Error&&d.message.toLowerCase().includes("delegated signer")&&d.message.toLowerCase().includes("already")&&d.message.toLowerCase().includes("approved"))s.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:n.locator});else throw s.error("wallet.recover.device.error",{error:d}),yield r.deleteKey(this.address),d}p(this,S,yield this.assembleFullSigner({type:"device",locator:n.locator,address:this.address},r)),i(this,S).type==="device"&&(i(this,S).status="success"),s.info("wallet.recover.device.success",{signerLocator:n.locator}),e()})}checkAndResumeDeviceSigner(e){return c(this,null,function*(){var t;if(this.isApprovedSignerStatus(e.status))return s.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(t=r.signer)==null?void 0:t.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(s.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return c(this,null,function*(){var a;let t=i(this,S),n=this.buildInternalSignerConfig(i(this,b));p(this,S,O(this.chain,n,(a=i(this,m))==null?void 0:a.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(g){throw p(this,S,e),g}finally{i(this,S)!==e&&p(this,S,t)}e.status="success",s.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return c(this,null,function*(){let t=(yield this.signers()).filter(n=>n.locator.startsWith("device:"));for(let n of t){let a=n.locator.replace("device:","");try{if(yield e.hasKey(a)){let d=O(this.chain,{type:"device",locator:n.locator,address:this.address},e);return s.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:n.locator}),d}}catch(g){s.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:n.locator,error:g})}}return null})}signers(){return c(this,null,function*(){var a,g;s.info("wallet.signers.start");let e=yield i(this,u).getWallet(this.walletLocator);if("error"in e)throw s.error("wallet.signers.error",{error:e}),new _(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw s.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new j(`Wallet type ${e.type} not supported`);let r=(g=(a=e==null?void 0:e.config)==null?void 0:a.delegatedSigners)!=null?g:[],n=(yield Promise.all(r.map(d=>c(this,null,function*(){try{return(yield this.getSignerState(d.locator)).signer}catch(o){return null}})))).filter(d=>d!=null);return s.info("wallet.signers.success",{count:n.length}),n})}get walletLocator(){if(i(this,u).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(i(this,S)==null)throw i(this,x).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):i(this,b).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
|
|
1
|
+
import{a as ae}from"./chunk-N4IWDL6M.js";import{a as W}from"./chunk-GOXB2RBF.js";import{b as G,c as M}from"./chunk-VADIEIDS.js";import{a as O}from"./chunk-7TEUO6AH.js";import{b as L}from"./chunk-RBSMBO4T.js";import{a as ne}from"./chunk-7HGPAR7D.js";import{f as ie}from"./chunk-Y22U2RZ2.js";import{B as te,d as j,e as _,j as B,n as U,q,r as V,s as z,t as Y,u as J,v as Q,w as X,x as Z,y as ee,z as re}from"./chunk-EXC7TCGL.js";import{a as s}from"./chunk-EDN5LPJV.js";import{d as H}from"./chunk-YXHWN6FD.js";import{a as C,b as I,c as E,d as i,e as k,f as p,g as c}from"./chunk-J3R36SGJ.js";import{isValidAddress as se,WithLoggerContext as P}from"@crossmint/common-sdk-base";var S,m,u,b,x,T,N,D,F,A=class{constructor(e,r){k(this,S);k(this,m);k(this,u);k(this,b);k(this,x);k(this,T,!1);k(this,N,!1);k(this,D);k(this,F,null);let{chain:t,address:n,owner:a,options:g,alias:d,recovery:o,signers:l,signer:h}=e;p(this,u,r),this.chain=t,this.address=n,this.owner=a,p(this,m,g),this.alias=d,p(this,b,o),p(this,x,l!=null?l:[]),p(this,S,h),p(this,D,this.initDefaultSigner())}get signer(){return i(this,S)}initDeviceSigner(){return c(this,null,function*(){var n;let e=(n=i(this,m))==null?void 0:n.deviceSignerKeyStorage;if(e==null||this.chain==="solana")return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(a){s.error("wallet.initDeviceSigner.error",{error:a}),p(this,T,!0);return}if(i(this,T))return;let t=this.buildInternalSignerConfig(r);p(this,S,yield this.assembleFullSigner(t,e))})}initDefaultSigner(){return c(this,null,function*(){if(i(this,S)!=null||(yield this.initDeviceSigner(),i(this,S)!=null||i(this,T)))return;let e=i(this,x).length===0?i(this,b):i(this,x).length===1?i(this,x)[0]:null;if(e!=null&&this.isAutoAssemblableSignerConfig(e))try{let r=this.buildInternalSignerConfig(e);p(this,S,yield this.assembleFullSigner(r))}catch(r){s.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:i(this,b).type,signerCount:i(this,x).length,error:r})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return i(e,b)}static getInitialSigners(e){return i(e,x)}get apiClient(){return i(this,u)}get options(){return i(this,m)}get recovery(){return i(this,b)}balances(e){return c(this,null,function*(){s.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),t;switch(this.chain){case"solana":t="sol";break;case"stellar":t="xlm";break;default:t="eth";break}let n=[t,"usdc",...e!=null?e:[]],a=yield i(this,u).getBalance(this.address,{chains:[r],tokens:n});if("error"in a)throw s.error("wallet.balances.error",{error:a}),new Error(`Failed to get balances for wallet: ${JSON.stringify(a.message)}`);return s.info("wallet.balances.success"),this.transformBalanceResponse(a,t,e)})}stagingFund(e,r){return c(this,null,function*(){s.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let t=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in t)throw s.error("wallet.stagingFund.error",{error:t}),new Error(`Failed to fund wallet: ${JSON.stringify(t.message)}`);return s.info("wallet.stagingFund.success"),t})}transformBalanceResponse(e,r,t){let n=l=>{var v,y,R,$,K;let h=(v=l.chains)==null?void 0:v[this.chain],f={};return this.chain==="solana"&&h!=null&&"mintHash"in h?f={mintHash:h.mintHash}:this.chain==="stellar"&&h!=null&&"contractId"in h?f={contractId:h.contractId}:h!=null&&"contractAddress"in h&&(f={contractAddress:h.contractAddress}),C({symbol:(y=l.symbol)!=null?y:"",name:(R=l.name)!=null?R:"",amount:($=l.amount)!=null?$:"0",decimals:l.decimals,rawAmount:(K=l.rawAmount)!=null?K:"0"},f)},a=e.find(l=>l.symbol===r),g=e.find(l=>l.symbol==="usdc"),d=e.filter(l=>{var h;return l.symbol!==r&&l.symbol!=="usdc"&&(t==null||t.includes((h=l.symbol)!=null?h:""))}),o=l=>{let h={symbol:l,name:l,amount:"0",decimals:0,rawAmount:"0"},f={};return this.chain==="solana"?f={mintHash:void 0}:this.chain==="stellar"?f={contractId:void 0}:f={contractAddress:void 0},C(C({},h),f)};return{nativeToken:a!=null?n(a):o(r),usdc:g!=null?n(g):o("usdc"),tokens:d.map(n)}}nfts(e){return c(this,null,function*(){return yield i(this,u).getNfts(I(C({},e),{chain:this.chain,address:this.address}))})}transactions(){return c(this,null,function*(){let e=yield i(this,u).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return c(this,null,function*(){let r=yield i(this,u).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return c(this,null,function*(){let r=this.resolveChainForEnvironment(),t=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e==null?void 0:e.tokens,status:e==null?void 0:e.status});if("error"in t)throw new Error(`Failed to get transfers: ${JSON.stringify(t.message)}`);return t})}send(e,r,t,n){return c(this,null,function*(){let a=this.resolveChainForEnvironment(),g=ce(e),d=de(r,a),o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o)||o<=0)throw new z(`Invalid transfer amount: "${t}". Amount must be a positive number greater than zero.`);s.info("wallet.send.start",C({recipient:g,token:d,amount:t},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{})),yield this.preAuthIfNeeded();let l=this.requireSigner(),h;(n==null?void 0:n.signer)==null?h=l.locator():typeof n.signer=="string"?h=n.signer:h=`server:${L(n.signer,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress}`;let f=C({recipient:g,amount:t,signer:h},(n==null?void 0:n.transactionType)!=null?{transactionType:n.transactionType}:{}),v=yield i(this,u).send(this.walletLocator,d,f);if("message"in v)throw s.error("wallet.send.error",{error:v}),new Y(`Failed to send token: ${JSON.stringify(v.message)}`);if((n==null?void 0:n.prepareOnly)===!0)return s.info("wallet.send.prepared",{transactionId:v.id}),{hash:void 0,explorerLink:void 0,transactionId:v.id};let y=yield this.approveTransactionAndWait(v.id);return s.info("wallet.send.success",{transactionId:v.id,hash:y.hash}),y})}approveTransaction(e){return c(this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return c(this,null,function*(){if(s.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),yield this.preAuthIfNeeded(),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return s.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return s.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw s.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return c(this,null,function*(){if(s.info("wallet.addSigner.start"),e.type==="device"&&this.chain==="solana")throw new B("Device signers are not currently supported for Solana wallets. Contact sales (https://www.crossmint.com/contact/sales) for access.");let t=typeof e=="object"&&"type"in e&&e.type==="server"?`server:${L(e,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress}`:e;return this.withRecoverySigner(()=>c(this,null,function*(){var d;let n=typeof t=="string"||t.type==="passkey"?t:t.type==="device"&&"publicKey"in t&&t.publicKey!=null?{type:"device",publicKey:t.publicKey,name:t.name}:W(t),a=yield i(this,u).registerSigner(this.walletLocator,{signer:n,chain:this.getSignerRegistrationChain()});if("error"in a)throw s.error("wallet.addSigner.error",{error:a}),new Error(`Failed to register signer: ${JSON.stringify(a.message)}`);let g=G(a,this.chain);if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in a)||a.transaction==null)throw s.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");let o=a.transaction.id;if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);return r!=null&&r.prepareOnly?(s.info("wallet.addSigner.prepared",{transactionId:o}),I(C({},g),{transactionId:o})):(yield this.approveTransactionAndWait(o),s.info("wallet.addSigner.success",{transactionId:o}),I(C({},g),{status:"success"}))}else{if(!("chains"in a))throw s.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");let o=(d=a.chains)==null?void 0:d[this.chain];if(g==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let l=M(a,this.chain),h=(l==null?void 0:l.type)==="signature"?l.id:void 0;if(r!=null&&r.prepareOnly)return s.info("wallet.addSigner.prepared",{signatureId:h}),I(C({},g),{signatureId:h});if((l==null?void 0:l.type)==="signature")yield this.approveSignatureAndWait(l.id),s.info("wallet.addSigner.success",{signatureId:l.id});else{if((o==null?void 0:o.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);s.info("wallet.addSigner.success")}return I(C({},g),{status:"success"})}}))})}removeSigner(e,r){return c(this,null,function*(){let t=this.resolveSignerLocator(e);return s.info("wallet.removeSigner.start",{signerLocator:t}),this.withRecoverySigner(()=>c(this,null,function*(){let n=yield i(this,u).removeSigner(this.walletLocator,t,{chain:this.getSignerRegistrationChain()});if("error"in n)throw s.error("wallet.removeSigner.error",{error:n}),new Error(`Failed to remove signer: ${JSON.stringify(n)}`);let a=n.id;return r!=null&&r.prepareOnly?(s.info("wallet.removeSigner.prepared",{transactionId:a}),{transactionId:a,status:void 0}):(yield this.approveTransactionAndWait(a),s.info("wallet.removeSigner.success",{transactionId:a}),{transactionId:a,status:"success"})}))})}useSigner(e){return c(this,null,function*(){s.info("wallet.useSigner.start"),this.validateSignerInput(e),e.type==="device"?yield this.resolveDeviceSignerAvailability(e):yield this.resolveNonDeviceSigner(e);let r=this.buildInternalSignerConfig(e),t=W(e);p(this,S,yield this.assembleFullSigner(r)),s.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return c(this,null,function*(){if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e)){p(this,T,!1);return}throw new Error("No passkey signer is registered on this wallet.")}let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r)){p(this,T,!1);return}if(this.isRecoverySigner(e)){p(this,T,!1);return}throw new Error(`Signer "${r}" is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return c(this,null,function*(){let t=(yield this.signers()).filter(n=>n.type==="passkey");if(t.length===0)return!1;if(t.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=t[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){if(e.type==="server"){let{derivedAddress:r}=L(e,this.chain,i(this,u).projectId,i(this,u).environment);return`server:${r}`}return W(e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return c(this,null,function*(){var n;let r=this.signer,t=this.buildInternalSignerConfig(i(this,b));p(this,S,O(this.chain,t,(n=i(this,m))==null?void 0:n.deviceSignerKeyStorage));try{return yield e()}finally{p(this,S,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return c(this,null,function*(){return(yield this.signers()).some(t=>t.locator===e)})}isSignerApproved(e){return c(this,null,function*(){var t;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((t=r.signer)==null?void 0:t.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return i(this,T)}recover(){return c(this,null,function*(){var a,g;if(s.info("wallet.recover.start"),i(this,N)){s.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}let e=()=>{p(this,T,!1),p(this,N,!0)};if(((a=i(this,S))==null?void 0:a.type)==="device"&&(yield this.checkAndResumeDeviceSigner(i(this,S)))){e();return}if(i(this,S)!=null&&i(this,S).type!=="device"){s.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"});return}let r=(g=i(this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null){if(!i(this,T))return;throw new Error("Device signer key storage is required to recover a device signer")}if(this.chain==="solana"){s.warn("wallet.recover.skipped",{reason:"Device signers are not supported on Solana"});return}let t=yield this.findLocalDeviceSigner(r);if(t!=null&&(yield this.checkAndResumeDeviceSigner(t))){p(this,S,t),e();let d=t.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,d)}catch(o){s.warn("wallet.recover.mapAddressToKey.error",{error:o})}return}let n=yield ae(r,this.address);try{yield this.addSigner(n)}catch(d){if(d instanceof Error&&d.message.toLowerCase().includes("delegated signer")&&d.message.toLowerCase().includes("already")&&d.message.toLowerCase().includes("approved"))s.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:n.locator});else throw s.error("wallet.recover.device.error",{error:d}),yield r.deleteKey(this.address),d}p(this,S,yield this.assembleFullSigner({type:"device",locator:n.locator,address:this.address},r)),i(this,S).type==="device"&&(i(this,S).status="success"),s.info("wallet.recover.device.success",{signerLocator:n.locator}),e()})}checkAndResumeDeviceSigner(e){return c(this,null,function*(){var t;if(this.isApprovedSignerStatus(e.status))return s.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(t=r.signer)==null?void 0:t.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(s.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return c(this,null,function*(){var a;let t=i(this,S),n=this.buildInternalSignerConfig(i(this,b));p(this,S,O(this.chain,n,(a=i(this,m))==null?void 0:a.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(g){throw p(this,S,e),g}finally{i(this,S)!==e&&p(this,S,t)}e.status="success",s.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return c(this,null,function*(){let t=(yield this.signers()).filter(n=>n.locator.startsWith("device:"));for(let n of t){let a=n.locator.replace("device:","");try{if(yield e.hasKey(a)){let d=O(this.chain,{type:"device",locator:n.locator,address:this.address},e);return s.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:n.locator}),d}}catch(g){s.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:n.locator,error:g})}}return null})}signers(){return c(this,null,function*(){var a,g;s.info("wallet.signers.start");let e=yield i(this,u).getWallet(this.walletLocator);if("error"in e)throw s.error("wallet.signers.error",{error:e}),new _(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw s.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new j(`Wallet type ${e.type} not supported`);let r=(g=(a=e==null?void 0:e.config)==null?void 0:a.delegatedSigners)!=null?g:[],n=(yield Promise.all(r.map(d=>c(this,null,function*(){try{return(yield this.getSignerState(d.locator)).signer}catch(o){return null}})))).filter(d=>d!=null);return s.info("wallet.signers.success",{count:n.length}),n})}get walletLocator(){if(i(this,u).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(i(this,S)==null)throw i(this,x).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):i(this,b).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
|
|
2
2
|
Example: wallet.useSigner({ type: "server", secret: process.env.YOUR_SERVER_SECRET })`):i(this,b).type==="external-wallet"||!this.isAutoAssemblableSignerConfig(i(this,b))?new Error(`No signer is set. External wallet signers require calling wallet.useSigner() with the onSign callback before signing operations.
|
|
3
|
-
Example: wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... })`):new Error("This wallet is read-only because no signer was provided. Operations that require signing (send, approve, addSigner, etc.) are not available.");return i(this,S)}preAuthIfNeeded(){return c(this,null,function*(){yield i(this,D),i(this,F)==null&&p(this,F,this.recover());try{yield i(this,F)}finally{p(this,F,null)}let e=this.requireSigner();e instanceof ne&&(yield e.ensureAuthenticated())})}isRecoverySigner(e){let r=i(this,b);if(r==null||r.type!==e.type||e.type==="device")return!1;if(e.type==="passkey")return!0;if(e.type==="server"&&r.type==="server"){let t=L(e,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress,n=L(r,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress;return t===n}return W(e)===W(r)}validateSignerInput(e){switch(e.type){case"email":if(!("email"in e)||e.email==null)throw new Error("Email signer requires an email address");break;case"phone":if(!("phone"in e)||e.phone==null)throw new Error("Phone signer requires a phone number");break;case"external-wallet":if(!("address"in e)||e.address==null)throw new Error("External wallet signer requires a wallet address");if(!("onSign"in e)||typeof e.onSign!="function")throw new Error("External wallet signer requires an onSign callback");break;case"passkey":case"device":case"api-key":break;default:break}}resolveDeviceSignerAvailability(e){return c(this,null,function*(){var g;let r=(g=i(this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null)throw new Error("Device signer key storage is required for device signers");let t=yield r.getKey(this.address);if(t!=null){e.locator=`device:${t}`;return}let a=(yield this.signers()).filter(d=>d.locator.startsWith("device:"));for(let d of a){let o=d.locator.replace("device:","");if(yield r.hasKey(o)){yield r.mapAddressToKey(this.address,o),e.locator=d.locator;return}}p(this,T,!0),p(this,N,!1)})}assembleFullSigner(n){return c(this,arguments,function*(e,r=(t=>(t=i(this,m))==null?void 0:t.deviceSignerKeyStorage)()){var d;let a=O(this.chain,e,r),g=yield this.getSignerState(a.locator());return a.status=(d=g.signer)==null?void 0:d.status,a})}getSignerState(e){return c(this,null,function*(){let r=null;try{r=yield i(this,u).getSigner(this.walletLocator,e)}catch(n){return{response:null,signer:null,pendingOperation:null}}if(r==null||typeof r!="object"||"error"in r)return{response:null,signer:null,pendingOperation:null};let t=G(r,this.chain);return{response:r,signer:t,pendingOperation:M(r,this.chain)}})}buildInternalSignerConfig(e){var r,t,n,a,g,d;switch(e.type){case"email":return{type:"email",email:e.email,locator:`email:${e.email}`,address:this.address,crossmint:i(this,u).crossmint,clientTEEConnection:(r=i(this,m))==null?void 0:r.clientTEEConnection,onAuthRequired:(n=(t=i(this,m))==null?void 0:t.callbacks)==null?void 0:n.onAuthRequired};case"phone":return{type:"phone",phone:e.phone,locator:`phone:${e.phone}`,address:this.address,crossmint:i(this,u).crossmint,clientTEEConnection:(a=i(this,m))==null?void 0:a.clientTEEConnection,onAuthRequired:(d=(g=i(this,m))==null?void 0:g.callbacks)==null?void 0:d.onAuthRequired};case"passkey":{let o="id"in e&&e.id?e.id:"";return{type:"passkey",id:o,locator:`passkey:${o}`,name:"name"in e?e.name:void 0,publicKey:"publicKey"in e?e.publicKey:void 0,onCreatePasskey:e.onCreatePasskey,onSignWithPasskey:e.onSignWithPasskey}}case"device":return{type:"device",locator:"locator"in e&&e.locator?e.locator:void 0,address:this.address};case"external-wallet":return P(C({},e),{locator:`external-wallet:${e.address}`});case"api-key":return{type:"api-key",locator:"api-key",address:this.address};case"server":{let{derivedKeyBytes:o,derivedAddress:l}=L(e,this.chain,i(this,u).projectId,i(this,u).environment);return{type:"server",derivedKeyBytes:o,locator:`server:${l}`,address:l}}default:throw new Error(`Unknown signer type: ${e==null?void 0:e.type}`)}}isAutoAssemblableSignerConfig(e){switch(e.type){case"email":case"phone":case"passkey":case"api-key":case"device":return!0;case"server":return"secret"in e&&typeof e.secret=="string";case"external-wallet":return"onSign"in e&&typeof e.onSign=="function";default:return!1}}get isSolanaWallet(){return this.chain==="solana"}resolveChainForEnvironment(){let e=ie(this.chain,i(this,u).environment);return e!==this.chain&&(this.chain=e),this.chain}approveTransactionAndWait(e,r){return c(this,null,function*(){return yield this.approveTransactionInternal(e,r),yield this.sleep(1e3),yield this.waitForTransaction(e)})}approveSignatureAndWait(e,r){return c(this,null,function*(){let t=yield this.approveSignatureInternal(e,r);return!("error"in t)&&t.status==="success"&&t.outputSignature!=null?{signature:t.outputSignature,signatureId:e}:(yield this.sleep(1e3),yield this.waitForSignature(e))})}approveSignatureInternal(e,r){return c(this,null,function*(){var o,l;if(this.isSolanaWallet)throw new Error("Approving signatures is only supported for EVM smart wallets");let t=this.requireSigner(),n=yield i(this,u).getSignature(this.walletLocator,e);if("error"in n)throw new q(JSON.stringify(n));if(t.type==="api-key")return n;if((r==null?void 0:r.approval)!=null){let h=[r.approval];return yield this.executeApproveSignatureWithErrorHandling(e,h)}let a=(o=n.approvals)==null?void 0:o.pending;if(a==null)return n;let g=[...(l=r==null?void 0:r.additionalSigners)!=null?l:[],t],d=yield Promise.all(a.map(h=>c(this,null,function*(){let f=g.find(y=>y.locator()===h.signer.locator);if(f==null)throw new B(`Signer ${h.signer.locator} not found in pending approvals`);let v=yield f.signMessage(h.message);return P(C({},v),{signer:f.locator()})})));return yield this.executeApproveSignatureWithErrorHandling(e,d)})}approveTransactionInternal(e,r){return c(this,null,function*(){var o,l,h,f,v;let t=yield i(this,u).getTransaction(this.walletLocator,e);if("error"in t)throw new J(JSON.stringify(t));yield(h=(l=(o=i(this,m))==null?void 0:o.callbacks)==null?void 0:l.onTransactionStart)==null?void 0:h.call(l);let n=this.requireSigner();if(n.type==="api-key")return t;if((r==null?void 0:r.approval)!=null){let y=[r.approval];return yield this.executeApproveTransactionWithErrorHandling(e,y)}let a=(f=t.approvals)==null?void 0:f.pending;if(a==null)return t;let g=[...(v=r==null?void 0:r.additionalSigners)!=null?v:[],n],d=yield Promise.all(a.map(y=>c(this,null,function*(){let I=g.find(le=>le.locator()===y.signer.locator);if(I==null)throw new B(`Signer ${y.signer.locator} not found in pending approvals`);let $=I.type==="device",K=t.chainType==="solana"&&"transaction"in t.onChain&&!$?t.onChain.transaction:y.message,oe=yield I.signTransaction(K);return P(C({},oe),{signer:I.locator()})})));return yield this.executeApproveTransactionWithErrorHandling(e,d)})}executeApproveTransactionWithErrorHandling(e,r){return c(this,null,function*(){s.info("wallet.approve: submitting approval to API",{transactionId:e});let t=yield i(this,u).approveTransaction(this.walletLocator,e,{approvals:r});if(t.error)throw new re(JSON.stringify(t));return t})}executeApproveSignatureWithErrorHandling(e,r){return c(this,null,function*(){let t=yield i(this,u).approveSignature(this.walletLocator,e,{approvals:r});if(t.error)throw new V(JSON.stringify(t));return t})}waitForSignature(e){return c(this,null,function*(){let r=null;do if(yield new Promise(t=>setTimeout(t,H)),r=yield i(this,u).getSignature(this.walletLocator,e),"error"in r)throw new q(JSON.stringify(r));while(r===null||r.status==="pending");if(r.status==="failed")throw new U("Signature signing failed");if(!r.outputSignature)throw new q("Signature not available");return{signature:r.outputSignature,signatureId:e}})}waitForTransaction(g){return c(this,arguments,function*(e,r=6e4,{backoffMultiplier:t=1.1,maxBackoffMs:n=2e3,initialBackoffMs:a=H}={}){var f,v;s.info("wallet.approve: waiting for transaction confirmation",{transactionId:e,timeoutMs:r});let d=Date.now(),o;do{if(Date.now()-d>r)throw new Q("Transaction confirmation timeout");if(o=yield i(this,u).getTransaction(this.walletLocator,e),o.error)throw new J(JSON.stringify(o));yield this.sleep(a),a=Math.min(a*t,n)}while(o.status==="pending");if(o.status==="failed")throw new X(`Transaction sending failed: ${JSON.stringify(o.error)}`);if(o.status==="awaiting-approval")throw new Z("Transaction is awaiting approval. Please submit required approvals before waiting for completion.");let l="txHash"in o.onChain&&typeof o.onChain.txHash=="string"?o.onChain.txHash:void 0,h=(f=o.onChain.txId)!=null?f:l;if(h==null)throw new ee("Transaction hash not found on transaction response");return{hash:h,explorerLink:(v=o.onChain.explorerLink)!=null?v:"",transactionId:o.id}})}sleep(e){return c(this,null,function*(){return new Promise(r=>setTimeout(r,e))})}};S=new WeakMap,m=new WeakMap,u=new WeakMap,b=new WeakMap,x=new WeakMap,T=new WeakMap,N=new WeakMap,D=new WeakMap,F=new WeakMap,E([R({logger:s,methodName:"wallet.balances",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"balances",1),E([R({logger:s,methodName:"wallet.stagingFund",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"stagingFund",1),E([R({logger:s,methodName:"wallet.send",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"send",1),E([R({logger:s,methodName:"wallet.approve",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"approve",1),E([R({logger:s,methodName:"wallet.addSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"addSigner",1),E([R({logger:s,methodName:"wallet.removeSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"removeSigner",1),E([R({logger:s,methodName:"wallet.useSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"useSigner",1),E([R({logger:s,methodName:"wallet.recover",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"recover",1),E([R({logger:s,methodName:"wallet.signers",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"signers",1);function ce(w){if(typeof w=="string"){if(!se(w))throw new te(`Invalid recipient address: "${w}". Expected a valid EVM (0x...), Solana (base58), or Stellar (G.../C...) address.`);return w}if("email"in w)return`email:${w.email}`;if("x"in w)return`x:${w.x}`;if("twitter"in w)return`twitter:${w.twitter}`;if("phone"in w)return`phoneNumber:${w.phone}`;if("userId"in w)return`userId:${w.userId}`;throw new Error("Invalid recipient locator")}function de(w,e){return se(w)?`${e}:${w}`:`${e}:${w.toLowerCase()}`}export{A as a};
|
|
3
|
+
Example: wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... })`):new Error("This wallet is read-only because no signer was provided. Operations that require signing (send, approve, addSigner, etc.) are not available.");return i(this,S)}preAuthIfNeeded(){return c(this,null,function*(){yield i(this,D),i(this,F)==null&&p(this,F,this.recover());try{yield i(this,F)}finally{p(this,F,null)}let e=this.requireSigner();e instanceof ne&&(yield e.ensureAuthenticated())})}isRecoverySigner(e){let r=i(this,b);if(r==null||r.type!==e.type||e.type==="device")return!1;if(e.type==="passkey")return!0;if(e.type==="server"&&r.type==="server"){let t=L(e,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress,n=L(r,this.chain,i(this,u).projectId,i(this,u).environment).derivedAddress;return t===n}return W(e)===W(r)}validateSignerInput(e){switch(e.type){case"email":if(!("email"in e)||e.email==null)throw new Error("Email signer requires an email address");break;case"phone":if(!("phone"in e)||e.phone==null)throw new Error("Phone signer requires a phone number");break;case"external-wallet":if(!("address"in e)||e.address==null)throw new Error("External wallet signer requires a wallet address");if(!("onSign"in e)||typeof e.onSign!="function")throw new Error("External wallet signer requires an onSign callback");break;case"passkey":case"device":case"api-key":break;default:break}}resolveDeviceSignerAvailability(e){return c(this,null,function*(){var g;let r=(g=i(this,m))==null?void 0:g.deviceSignerKeyStorage;if(r==null)throw new Error("Device signer key storage is required for device signers");let t=yield r.getKey(this.address);if(t!=null){e.locator=`device:${t}`;return}let a=(yield this.signers()).filter(d=>d.locator.startsWith("device:"));for(let d of a){let o=d.locator.replace("device:","");if(yield r.hasKey(o)){yield r.mapAddressToKey(this.address,o),e.locator=d.locator;return}}p(this,T,!0),p(this,N,!1)})}assembleFullSigner(n){return c(this,arguments,function*(e,r=(t=>(t=i(this,m))==null?void 0:t.deviceSignerKeyStorage)()){var d;let a=O(this.chain,e,r),g=yield this.getSignerState(a.locator());return a.status=(d=g.signer)==null?void 0:d.status,a})}getSignerState(e){return c(this,null,function*(){let r=null;try{r=yield i(this,u).getSigner(this.walletLocator,e)}catch(n){return{response:null,signer:null,pendingOperation:null}}if(r==null||typeof r!="object"||"error"in r)return{response:null,signer:null,pendingOperation:null};let t=G(r,this.chain);return{response:r,signer:t,pendingOperation:M(r,this.chain)}})}buildInternalSignerConfig(e){var r,t,n,a,g,d;switch(e.type){case"email":return{type:"email",email:e.email,locator:`email:${e.email}`,address:this.address,crossmint:i(this,u).crossmint,clientTEEConnection:(r=i(this,m))==null?void 0:r.clientTEEConnection,onAuthRequired:(n=(t=i(this,m))==null?void 0:t.callbacks)==null?void 0:n.onAuthRequired};case"phone":return{type:"phone",phone:e.phone,locator:`phone:${e.phone}`,address:this.address,crossmint:i(this,u).crossmint,clientTEEConnection:(a=i(this,m))==null?void 0:a.clientTEEConnection,onAuthRequired:(d=(g=i(this,m))==null?void 0:g.callbacks)==null?void 0:d.onAuthRequired};case"passkey":{let o="id"in e&&e.id?e.id:"";return{type:"passkey",id:o,locator:`passkey:${o}`,name:"name"in e?e.name:void 0,publicKey:"publicKey"in e?e.publicKey:void 0,onCreatePasskey:e.onCreatePasskey,onSignWithPasskey:e.onSignWithPasskey}}case"device":return{type:"device",locator:"locator"in e&&e.locator?e.locator:void 0,address:this.address};case"external-wallet":return I(C({},e),{locator:`external-wallet:${e.address}`});case"api-key":return{type:"api-key",locator:"api-key",address:this.address};case"server":{let{derivedKeyBytes:o,derivedAddress:l}=L(e,this.chain,i(this,u).projectId,i(this,u).environment);return{type:"server",derivedKeyBytes:o,locator:`server:${l}`,address:l}}default:throw new Error(`Unknown signer type: ${e==null?void 0:e.type}`)}}isAutoAssemblableSignerConfig(e){switch(e.type){case"email":case"phone":case"passkey":case"api-key":case"device":return!0;case"server":return"secret"in e&&typeof e.secret=="string";case"external-wallet":return"onSign"in e&&typeof e.onSign=="function";default:return!1}}get isSolanaWallet(){return this.chain==="solana"}resolveChainForEnvironment(){let e=ie(this.chain,i(this,u).environment);return e!==this.chain&&(this.chain=e),this.chain}approveTransactionAndWait(e,r){return c(this,null,function*(){return yield this.approveTransactionInternal(e,r),yield this.sleep(1e3),yield this.waitForTransaction(e)})}approveSignatureAndWait(e,r){return c(this,null,function*(){let t=yield this.approveSignatureInternal(e,r);return!("error"in t)&&t.status==="success"&&t.outputSignature!=null?{signature:t.outputSignature,signatureId:e}:(yield this.sleep(1e3),yield this.waitForSignature(e))})}approveSignatureInternal(e,r){return c(this,null,function*(){var o,l;if(this.isSolanaWallet)throw new Error("Approving signatures is only supported for EVM smart wallets");let t=this.requireSigner(),n=yield i(this,u).getSignature(this.walletLocator,e);if("error"in n)throw new q(JSON.stringify(n));if(t.type==="api-key")return n;if((r==null?void 0:r.approval)!=null){let h=[r.approval];return yield this.executeApproveSignatureWithErrorHandling(e,h)}let a=(o=n.approvals)==null?void 0:o.pending;if(a==null)return n;let g=[...(l=r==null?void 0:r.additionalSigners)!=null?l:[],t],d=yield Promise.all(a.map(h=>c(this,null,function*(){let f=g.find(y=>y.locator()===h.signer.locator);if(f==null)throw new B(`Signer ${h.signer.locator} not found in pending approvals`);let v=yield f.signMessage(h.message);return I(C({},v),{signer:f.locator()})})));return yield this.executeApproveSignatureWithErrorHandling(e,d)})}approveTransactionInternal(e,r){return c(this,null,function*(){var o,l,h,f,v;let t=yield i(this,u).getTransaction(this.walletLocator,e);if("error"in t)throw new J(JSON.stringify(t));yield(h=(l=(o=i(this,m))==null?void 0:o.callbacks)==null?void 0:l.onTransactionStart)==null?void 0:h.call(l);let n=this.requireSigner();if(n.type==="api-key")return t;if((r==null?void 0:r.approval)!=null){let y=[r.approval];return yield this.executeApproveTransactionWithErrorHandling(e,y)}let a=(f=t.approvals)==null?void 0:f.pending;if(a==null)return t;let g=[...(v=r==null?void 0:r.additionalSigners)!=null?v:[],n],d=yield Promise.all(a.map(y=>c(this,null,function*(){let R=g.find(le=>le.locator()===y.signer.locator);if(R==null)throw new B(`Signer ${y.signer.locator} not found in pending approvals`);let $=R.type==="device",K=t.chainType==="solana"&&"transaction"in t.onChain&&!$?t.onChain.transaction:y.message,oe=yield R.signTransaction(K);return I(C({},oe),{signer:R.locator()})})));return yield this.executeApproveTransactionWithErrorHandling(e,d)})}executeApproveTransactionWithErrorHandling(e,r){return c(this,null,function*(){s.info("wallet.approve: submitting approval to API",{transactionId:e});let t=yield i(this,u).approveTransaction(this.walletLocator,e,{approvals:r});if(t.error)throw new re(JSON.stringify(t));return t})}executeApproveSignatureWithErrorHandling(e,r){return c(this,null,function*(){let t=yield i(this,u).approveSignature(this.walletLocator,e,{approvals:r});if(t.error)throw new V(JSON.stringify(t));return t})}waitForSignature(e){return c(this,null,function*(){let r=null;do if(yield new Promise(t=>setTimeout(t,H)),r=yield i(this,u).getSignature(this.walletLocator,e),"error"in r)throw new q(JSON.stringify(r));while(r===null||r.status==="pending");if(r.status==="failed")throw new U("Signature signing failed");if(!r.outputSignature)throw new q("Signature not available");return{signature:r.outputSignature,signatureId:e}})}waitForTransaction(g){return c(this,arguments,function*(e,r=6e4,{backoffMultiplier:t=1.1,maxBackoffMs:n=2e3,initialBackoffMs:a=H}={}){var f,v;s.info("wallet.approve: waiting for transaction confirmation",{transactionId:e,timeoutMs:r});let d=Date.now(),o;do{if(Date.now()-d>r)throw new Q("Transaction confirmation timeout");if(o=yield i(this,u).getTransaction(this.walletLocator,e),o.error)throw new J(JSON.stringify(o));yield this.sleep(a),a=Math.min(a*t,n)}while(o.status==="pending");if(o.status==="failed")throw new X(`Transaction sending failed: ${JSON.stringify(o.error)}`);if(o.status==="awaiting-approval")throw new Z("Transaction is awaiting approval. Please submit required approvals before waiting for completion.");let l="txHash"in o.onChain&&typeof o.onChain.txHash=="string"?o.onChain.txHash:void 0,h=(f=o.onChain.txId)!=null?f:l;if(h==null)throw new ee("Transaction hash not found on transaction response");return{hash:h,explorerLink:(v=o.onChain.explorerLink)!=null?v:"",transactionId:o.id}})}sleep(e){return c(this,null,function*(){return new Promise(r=>setTimeout(r,e))})}};S=new WeakMap,m=new WeakMap,u=new WeakMap,b=new WeakMap,x=new WeakMap,T=new WeakMap,N=new WeakMap,D=new WeakMap,F=new WeakMap,E([P({logger:s,methodName:"wallet.balances",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"balances",1),E([P({logger:s,methodName:"wallet.stagingFund",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"stagingFund",1),E([P({logger:s,methodName:"wallet.send",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"send",1),E([P({logger:s,methodName:"wallet.approve",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"approve",1),E([P({logger:s,methodName:"wallet.addSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"addSigner",1),E([P({logger:s,methodName:"wallet.removeSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"removeSigner",1),E([P({logger:s,methodName:"wallet.useSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"useSigner",1),E([P({logger:s,methodName:"wallet.recover",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"recover",1),E([P({logger:s,methodName:"wallet.signers",buildContext(e){return{chain:e.chain,address:e.address}}})],A.prototype,"signers",1);function ce(w){if(typeof w=="string"){if(!se(w))throw new te(`Invalid recipient address: "${w}". Expected a valid EVM (0x...), Solana (base58), or Stellar (G.../C...) address.`);return w}if("email"in w)return`email:${w.email}`;if("x"in w)return`x:${w.x}`;if("twitter"in w)return`twitter:${w.twitter}`;if("phone"in w)return`phoneNumber:${w.phone}`;if("userId"in w)return`userId:${w.userId}`;throw new Error("Invalid recipient locator")}function de(w,e){return se(w)?`${e}:${w}`:`${e}:${w.toLowerCase()}`}export{A as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTE2QAVEHcjs = require('./chunk-TE2QAVEH.cjs');var _chunk3VSFHDFHcjs = require('./chunk-3VSFHDFH.cjs');var _chunkT3U46LK3cjs = require('./chunk-T3U46LK3.cjs');var _chunkJX4QNRH6cjs = require('./chunk-JX4QNRH6.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var o=class o extends _chunkTE2QAVEHcjs.a{constructor(e){super({chain:e.chain,address:e.address,owner:e.owner,options:_chunkTE2QAVEHcjs.a.getOptions(e),alias:e.alias,recovery:_chunkTE2QAVEHcjs.a.getRecovery(e),signer:e.signer,signers:_chunkTE2QAVEHcjs.a.getInitialSigners(e)},_chunkTE2QAVEHcjs.a.getApiClient(e))}static from(e){if(!_commonsdkbase.isValidStellarAddress.call(void 0, e.address))throw new Error("Wallet is not a Stellar wallet");return new o(e)}sendTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var a;_chunkJX4QNRH6cjs.a.info("stellarWallet.sendTransaction.start"),yield this.preAuthIfNeeded();let t=yield this.createTransaction(e);if((a=e.options)!=null&&a.prepareOnly)return _chunkJX4QNRH6cjs.a.info("stellarWallet.sendTransaction.prepared",{transactionId:t.id}),{hash:void 0,explorerLink:void 0,transactionId:t.id};let n={},r=yield this.approveTransactionAndWait(t.id,n);return _chunkJX4QNRH6cjs.a.info("stellarWallet.sendTransaction.success",{transactionId:t.id,hash:r.hash}),r})}createTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let{contractId:t,options:n}=e,r;(n==null?void 0:n.signer)==null?r=this.requireSigner().locator():typeof n.signer=="string"?r=n.signer:r=`server:${_chunk3VSFHDFHcjs.b.call(void 0, n.signer,this.chain,this.apiClient.projectId,this.apiClient.environment).derivedAddress}`;let a;if("transaction"in e)a={type:"serialized-transaction",serializedTransaction:e.transaction,contractId:t};else{let{method:T,memo:d,args:g}=e;a={type:"contract-call",contractId:t,method:T,memo:d!=null?{type:"text",value:d}:void 0,args:g}}let c=yield this.apiClient.createTransaction(this.walletLocator,{params:{transaction:a,signer:r}});if("error"in c)throw new (0, _chunkT3U46LK3cjs.t)(JSON.stringify(c));return c})}};_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"stellarWallet.sendTransaction",buildContext(e){return{chain:e.chain,address:e.address}}})],o.prototype,"sendTransaction",1);var f=o;exports.a = f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as A}from"./chunk-S3DYQVRD.js";import{a as O}from"./chunk-KUP7H7X2.js";import{a as l}from"./chunk-FT5EVMLB.js";import{a as o}from"./chunk-SVIKBM3S.js";import{a as S}from"./chunk-KKQBZXFE.js";import{b as i,c as s}from"./chunk-EXC7TCGL.js";import{a as E}from"./chunk-
|
|
1
|
+
import{a as A}from"./chunk-S3DYQVRD.js";import{a as O}from"./chunk-KUP7H7X2.js";import{a as l}from"./chunk-FT5EVMLB.js";import{a as o}from"./chunk-SVIKBM3S.js";import{a as S}from"./chunk-KKQBZXFE.js";import{b as i,c as s}from"./chunk-EXC7TCGL.js";import{a as E}from"./chunk-EDN5LPJV.js";import{APIKeyEnvironmentPrefix as M,BlockchainIncludingTestnet as e}from"@crossmint/common-sdk-base";import{baseSepolia as m,base as _,polygonAmoy as L,polygon as P,optimismSepolia as u,optimism as c,arbitrumSepolia as N,arbitrum as p,arbitrumNova as R,modeTestnet as h,mode as d,bsc as f,shape as W,zora as V,zoraSepolia as B,sepolia as U,flowMainnet as y,flowTestnet as v,plume as H,plumeTestnet as x}from"viem/chains";var b=[e.ABSTRACT_TESTNET,e.ARBITRUM_SEPOLIA,e.BASE_SEPOLIA,e.CURTIS,e.ETHEREUM_SEPOLIA,e.FLOW_TESTNET,e.MANTLE_SEPOLIA,e.MODE_SEPOLIA,e.OPTIMISM_SEPOLIA,e.PLUME_TESTNET,e.POLYGON_AMOY,e.SCROLL_SEPOLIA,e.SEI_ATLANTIC_2_TESTNET,e.STORY_TESTNET,e.WORLD_CHAIN_SEPOLIA,e.ZORA_SEPOLIA,e.ARC_TESTNET,e.TEMPO_TESTNET],w=[e.ABSTRACT,e.APECHAIN,e.ARBITRUM,e.ARBITRUMNOVA,e.BASE,e.BSC,e.FLOW,e.MANTLE,e.MODE,e.OPTIMISM,e.PLUME,e.POLYGON,e.SCROLL,e.SEI_PACIFIC_1,e.SHAPE,e.STORY,e.TEMPO,e.WORLDCHAIN,e.ZORA];function X(t){switch(t){case e.BASE_SEPOLIA:return m;case e.BASE:return _;case e.POLYGON_AMOY:return L;case e.POLYGON:return P;case e.OPTIMISM_SEPOLIA:return u;case e.OPTIMISM:return c;case e.ARBITRUM_SEPOLIA:return N;case e.ARBITRUM:return p;case e.ARBITRUMNOVA:return R;case e.STORY_TESTNET:return A;case e.STORY:return S;case e.MODE_SEPOLIA:return h;case e.MODE:return d;case e.BSC:return f;case e.SHAPE:return W;case e.ZORA:return V;case e.ZORA_SEPOLIA:return B;case e.ETHEREUM_SEPOLIA:return U;case e.FLOW:return y;case e.FLOW_TESTNET:return v;case e.PLUME_TESTNET:return x;case e.PLUME:return H;case e.ARC_TESTNET:return o;case e.TEMPO:return O;case e.TEMPO_TESTNET:return l;case e.ABSTRACT:case e.ABSTRACT_TESTNET:case e.APECHAIN:case e.MANTLE:case e.MANTLE_SEPOLIA:case e.SCROLL:case e.SCROLL_SEPOLIA:case e.SEI_PACIFIC_1:case e.SEI_ATLANTIC_2_TESTNET:case e.CURTIS:case e.WORLDCHAIN:case e.WORLD_CHAIN_SEPOLIA:throw new Error(`Chain ${t} is not yet supported in toViemChain function. Please add the appropriate viem chain definition.`);default:throw new Error(`Unknown chain: ${t}`)}}function I(t){return b.includes(t)}function C(t){return w.includes(t)}var D={[e.ABSTRACT]:e.ABSTRACT_TESTNET,[e.APECHAIN]:e.CURTIS,[e.ARBITRUM]:e.ARBITRUM_SEPOLIA,[e.BASE]:e.BASE_SEPOLIA,[e.FLOW]:e.FLOW_TESTNET,[e.MANTLE]:e.MANTLE_SEPOLIA,[e.MODE]:e.MODE_SEPOLIA,[e.OPTIMISM]:e.OPTIMISM_SEPOLIA,[e.PLUME]:e.PLUME_TESTNET,[e.POLYGON]:e.POLYGON_AMOY,[e.SCROLL]:e.SCROLL_SEPOLIA,[e.SEI_PACIFIC_1]:e.SEI_ATLANTIC_2_TESTNET,[e.STORY]:e.STORY_TESTNET,[e.WORLDCHAIN]:e.WORLD_CHAIN_SEPOLIA,[e.ZORA]:e.ZORA_SEPOLIA,[e.TEMPO]:e.TEMPO_TESTNET};function Y(t){return D[t]}function g(t){return t==="solana"||t==="stellar"||I(t)||C(t)}function ee(t,a){if(!g(t))throw new s(`Unknown chain "${t}". Please use a supported chain name (e.g. "base-sepolia", "polygon", "solana", "stellar").`);if(t==="solana"||t==="stellar")return t;let r=t,T=a===M.PRODUCTION;if(T&&I(r))throw new i(`Chain "${t}" is a testnet chain and cannot be used in production. Please use a mainnet chain instead.`);if(!T&&C(r)){let n=Y(r);if(n!=null)return E.debug("validateChainForEnvironment.autoConverted",{chain:t,convertedTo:n,environment:a,message:`Chain "${t}" is a mainnet chain and cannot be used in ${a} environment. Automatically converted to "${n}".`}),n;E.debug("validateChainForEnvironment.mismatch",{chain:t,environment:a,message:`Chain "${t}" is a mainnet chain and should not be used in ${a} environment. No testnet equivalent is available. Please use a testnet chain instead.`})}return t}export{X as a,I as b,C as c,Y as d,g as e,ee as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJBP52JOHcjs = require('./chunk-JBP52JOH.cjs');var _chunk5QIW67NUcjs = require('./chunk-5QIW67NU.cjs');var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJBP52JOHcjs = require('./chunk-JBP52JOH.cjs');var _chunk5QIW67NUcjs = require('./chunk-5QIW67NU.cjs');var _chunkJX4QNRH6cjs = require('./chunk-JX4QNRH6.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var f=class{constructor(r){this.config=r;this._needsAuth=!0;this._authPromise=null;this._initializationPromise=null;typeof window!="undefined"&&(this._initializationPromise=this.initialize()),this.type=this.config.type}locator(){return this.config.locator}address(){return this.config.address}initialize(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){try{if(this.config.clientTEEConnection==null){let r=_commonsdkbase.validateAPIKey.call(void 0, this.config.crossmint.apiKey);if(!r.isValid)throw new Error("Invalid API key");let t=new (0, _chunkJBP52JOHcjs.a)({environment:r.environment});this.config.clientTEEConnection=yield t.initialize()}}finally{this._initializationPromise=null}})}getTEEConnection(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(this.config.clientTEEConnection==null){if(this._initializationPromise){if(yield this._initializationPromise,this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");return this.config.clientTEEConnection}this._initializationPromise=this.initializeTEEConnection();try{yield this._initializationPromise}finally{this._initializationPromise=null}}if(this.config.clientTEEConnection==null)throw new Error("TEE connection is not initialized");return this.config.clientTEEConnection})}initializeTEEConnection(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("TEE connection not initialized, initializing now");let r=_commonsdkbase.validateAPIKey.call(void 0, this.config.crossmint.apiKey);if(!r.isValid)throw new Error("Invalid API key");let t=new (0, _chunkJBP52JOHcjs.a)({environment:r.environment});if(this.config.clientTEEConnection=yield t.initialize(),this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");_chunkJX4QNRH6cjs.a.info("TEE connection initialized successfully")})}handleAuthRequired(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var u;let r=yield this.getTEEConnection();if(this.config.onAuthRequired==null)throw new Error(`${this.type} signer requires the onAuthRequired callback to handle OTP verification. This callback manages the authentication flow (sending OTP and verifying user input). If using our React/React Native SDK, this is handled automatically by the provider. For other environments, implement: onAuthRequired: (needsAuth, sendOtp, verifyOtp, reject) => { /* your UI logic */ }`);_chunkJX4QNRH6cjs.a.info("get-status: sending request");let t=Date.now(),n=yield r.sendAction({event:"request:get-status",responseEvent:"response:get-status",data:{authData:{jwt:(u=this.config.crossmint.jwt)!=null?u:"",apiKey:this.config.crossmint.apiKey}},options:d}),i=Date.now()-t;if((n==null?void 0:n.status)!=="success")throw _chunkJX4QNRH6cjs.a.error("get-status: failed",{status:n==null?void 0:n.status,error:n==null?void 0:n.error,durationMs:i}),new Error(n==null?void 0:n.error);if(_chunkJX4QNRH6cjs.a.info("get-status: response received",{signerStatus:n.signerStatus,durationMs:i}),n.signerStatus==="ready"){this._needsAuth=!1;return}else this._needsAuth=!0;_chunkJX4QNRH6cjs.a.info("Auth required, initiating OTP flow",{needsAuth:this._needsAuth});let{promise:s,resolve:h,reject:c}=this.createAuthPromise();if(this._authPromise={promise:s,resolve:h,reject:c},this.config.onAuthRequired)try{yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),e=>this.verifyOtp(e),()=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){_chunkJX4QNRH6cjs.a.info("Auth rejected",{authRejected:!0}),this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),e=>this.verifyOtp(e),()=>{var e;return(e=this._authPromise)==null?void 0:e.reject(new _chunk5QIW67NUcjs.a)})),c(new _chunk5QIW67NUcjs.a)}))}catch(e){_chunkJX4QNRH6cjs.a.error("handleAuthRequired error",{error:e}),c(e)}try{yield s}catch(e){throw _chunkJX4QNRH6cjs.a.error("handleAuthRequired promise error",{error:e}),e}})}ensureAuthenticated(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){yield this.handleAuthRequired()})}getJwtOrThrow(){let r=this.config.crossmint.jwt;if(r==null)throw new Error("JWT is required");return r}createAuthPromise(){let r,t;return{promise:new Promise((i,s)=>{r=i,t=s}),resolve:r,reject:t}}sendMessageWithOtp(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var h,c;let r=yield this.getTEEConnection(),t=this.getAuthId();_chunkJX4QNRH6cjs.a.info("start-onboarding: sending request");let n=Date.now(),i=yield r.sendAction({event:"request:start-onboarding",responseEvent:"response:start-onboarding",data:{authData:{jwt:(h=this.config.crossmint.jwt)!=null?h:"",apiKey:this.config.crossmint.apiKey},data:{authId:t}},options:d}),s=Date.now()-n;if(_chunkJX4QNRH6cjs.a.info("start-onboarding: response received",{status:i==null?void 0:i.status,durationMs:s}),(i==null?void 0:i.status)==="success"&&i.signerStatus==="ready"){this._needsAuth=!1;return}(i==null?void 0:i.status)==="error"&&(_chunkJX4QNRH6cjs.a.error("start-onboarding: failed",{error:i.error}),(c=this._authPromise)==null||c.reject(new Error(i.error||"Failed to initiate OTP process.")))})}getAuthId(){return this.config.type==="email"?`email:${this.config.email}`:`phone:${this.config.phone}`}verifyOtp(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var s,h,c,u;let t;try{let e=yield this.getTEEConnection();_chunkJX4QNRH6cjs.a.info("complete-onboarding: sending request");let E=Date.now();t=yield e.sendAction({event:"request:complete-onboarding",responseEvent:"response:complete-onboarding",data:{authData:{jwt:(s=this.config.crossmint.jwt)!=null?s:"",apiKey:this.config.crossmint.apiKey},data:{onboardingAuthentication:{encryptedOtp:r}}},options:d}),_chunkJX4QNRH6cjs.a.info("complete-onboarding: response received",{status:t==null?void 0:t.status,durationMs:Date.now()-E})}catch(e){throw _chunkJX4QNRH6cjs.a.error("complete-onboarding: error",{error:e}),this._needsAuth=!0,(h=this._authPromise)==null||h.reject(e),e}if((t==null?void 0:t.status)==="success"){this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),e=>this.verifyOtp(e),()=>{var e;return(e=this._authPromise)==null?void 0:e.reject(new _chunk5QIW67NUcjs.a)})),(c=this._authPromise)==null||c.resolve();return}_chunkJX4QNRH6cjs.a.error("complete-onboarding: OTP validation failed",{status:t==null?void 0:t.status}),this._needsAuth=!0;let n=(t==null?void 0:t.status)==="error"?t.error:"Failed to validate encrypted OTP",i=new Error(n);throw(u=this._authPromise)==null||u.reject(i),i})}_exportPrivateKey(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){yield this.handleAuthRequired();let t=this.getJwtOrThrow(),{scheme:n,encoding:i}=this.getChainKeyParams(),s=yield r.sendAction({event:"request:export-signer",responseEvent:"response:export-signer",data:{authData:{jwt:t,apiKey:this.config.crossmint.apiKey},data:{scheme:n,encoding:i}},options:d});if((s==null?void 0:s.status)==="error")throw new Error(s.error||"Failed to export private key")})}};_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJX4QNRH6cjs.a,methodName:"handleAuthRequired"})],f.prototype,"handleAuthRequired",1);var d={timeoutMs:3e4};exports.a = f; exports.b = d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s,b as o}from"./chunk-
|
|
1
|
+
import{a as s,b as o}from"./chunk-7HGPAR7D.js";import{a as r}from"./chunk-EDN5LPJV.js";import{g as t}from"./chunk-J3R36SGJ.js";import{VersionedTransaction as u}from"@solana/web3.js";import a from"bs58";var g=class c extends s{constructor(n){super(n)}signMessage(){return t(this,null,function*(){return yield Promise.reject(new Error("signMessage method not implemented for email signer"))})}signTransaction(n){return t(this,null,function*(){var i;yield this.handleAuthRequired();let d=this.getJwtOrThrow(),m=a.decode(n),y=u.deserialize(m).message.serialize();r.info("sign: sending request",{keyType:"ed25519"});let l=Date.now(),e=yield(i=this.config.clientTEEConnection)==null?void 0:i.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:d,apiKey:this.config.crossmint.apiKey},data:{keyType:"ed25519",bytes:a.encode(new Uint8Array(y)),encoding:"base58"}},options:o});if(r.info("sign: response received",{status:e==null?void 0:e.status,durationMs:Date.now()-l}),(e==null?void 0:e.status)==="error")throw new Error(e.error);if((e==null?void 0:e.signature)==null)throw new Error("Failed to sign transaction");return c.verifyPublicKeyFormat(e.publicKey),{signature:e.signature.bytes}})}static verifyPublicKeyFormat(n){if(n==null)throw new Error("No public key found");if(n.encoding!=="base58"||n.keyType!=="ed25519"||n.bytes==null)throw new Error("Not supported. Expected public key to be in base58 encoding and ed25519 key type. Got: "+JSON.stringify(n))}getChainKeyParams(){return{scheme:"ed25519",encoding:"base58"}}};export{g as a};
|