UNPKG

@keyban/sdk-base

Version:

Keyban Javascript SDK provides core functionalities for the MPC wallet solution, supporting web and Node.js apps with TypeScript, custom storage, and Ethereum blockchain integration.

2 lines 4.11 kB
import {c as c$1,a}from'./chunk-WPOOJWVI.mjs';import'./chunk-DWBGILVH.mjs';import'./chunk-7K44U4PL.mjs';import {rpc,StrKey,xdr,TransactionBuilder,BASE_FEE,Operation,Asset,Transaction}from'@stellar/stellar-sdk';import {Buffer}from'buffer';import {BigNumber}from'bignumber.js';import {ed25519}from'@noble/curves/ed25519';var E=25,g=7;BigNumber.config({DECIMAL_PLACES:g});var o=class extends a{address;publicKey;#t;#e;constructor(t,e,r,i){super(t),this.#e=e,this.#t=r,this.address=i,this.publicKey=i;}async signMessage(t){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return (await this.#t.sign(Buffer.from(e))).toString("base64")}async transfer(t,e){let[r,i]=await Promise.all([this.#e.getAccount(this.address),this.#e.getNetwork()]),s=new TransactionBuilder(r,{fee:BASE_FEE,networkPassphrase:i.passphrase}).addOperation(Operation.payment({destination:t,asset:Asset.native(),amount:BigNumber(e).dividedBy(10**g).toString()})).setTimeout(E).build(),u=await this.#t.signDecorated(s.hash());return s.addDecoratedSignature(u),this.#r(s)}estimateTransfer(t){throw new Error("estimateTransfer not implemented.")}transferERC20(t){throw new Error("transferERC20 not implemented.")}estimateERC20Transfer(t){throw new Error("estimateERC20Transfer not implemented.")}transferNft(t){throw new Error("transferNft not implemented.")}estimateNftTransfer(t){throw new Error("estimateNftTransfer not implemented.")}async#r(t){return this.#e.sendTransaction(t).then(async e=>{if(e.status!=="PENDING")throw e;return this.#e.pollTransaction(e.hash)}).then(e=>{switch(e.status){case rpc.Api.GetTransactionStatus.FAILED:case rpc.Api.GetTransactionStatus.NOT_FOUND:throw e;case rpc.Api.GetTransactionStatus.SUCCESS:return e.txHash}})}async loyaltySetup(){try{if(await this.#e.getAccount(this.publicKey))return}catch{console.log("Stellar Account not yet setup for Loyalty, Doing it now...");}let t=await this.rpcClient.call("loyalty","initAccountSetup"),{passphrase:e}=await this.#e.getNetwork(),r=new Transaction(t,e),i=await this.#t.signDecorated(r.hash());r.addDecoratedSignature(i),await this.rpcClient.call("loyalty","submitAccountSetup",r.toXDR());}};var c=class{type="ed25519";#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r;}publicKey(){return StrKey.encodeEd25519PublicKey(this.rawPublicKey())}rawPublicKey(){let t=this.#r.replace(/^0x/,"");return Buffer.from(t,"hex")}async sign(t){let e=await this.#t.call("eddsa","sign",this.#e,t.toString("hex"));return Buffer.from(e,"hex")}async signDecorated(t){let e=await this.sign(t),r=this.signatureHint();return new xdr.DecoratedSignature({hint:r,signature:e})}async signPayloadDecorated(t){let e=await this.sign(t),r=this.signatureHint(),i=Buffer.from(t.slice(-4));return i.length<4&&(i=Buffer.concat([i,Buffer.alloc(4-t.length,0)])),new xdr.DecoratedSignature({hint:i.map((s,u)=>s^r[u]),signature:e})}signatureHint(){let t=this.xdrAccountId().toXDR();return t.slice(t.length-4)}verify(t,e){try{return ed25519.verify(e,t,this.rawPublicKey())}catch{return false}}xdrAccountId(){return xdr.PublicKey.publicKeyTypeEd25519(this.rawPublicKey())}xdrPublicKey(){return xdr.PublicKey.publicKeyTypeEd25519(this.rawPublicKey())}xdrMuxedAccount(t){if(typeof t<"u"){if(typeof t!="string")throw new TypeError(`expected string for ID, got ${typeof t}`);return xdr.MuxedAccount.keyTypeMuxedEd25519(new xdr.MuxedAccountMed25519({id:xdr.Uint64.fromString(t),ed25519:this.rawPublicKey()}))}return xdr.MuxedAccount.keyTypeEd25519(this.rawPublicKey())}};var m=class extends c$1{#t;constructor(t,e){super(t,e),this.#t=this.metadataConfig.then(r=>new rpc.Server(r.network.rpcUrl));}async initialize(){let t=await this.clientShareProvider.get("eddsa");t||(t=await this.rpcClient.call("eddsa","dkg"),await this.clientShareProvider.set("eddsa",t));let[e,r]=await Promise.all([this.#t,this.rpcClient.call("eddsa","publicKey",t)]),i=new c(this.rpcClient,t,r),s=StrKey.encodeEd25519PublicKey(Buffer.from(r,"hex"));return new o(this.rpcClient,e,i,s)}};export{m as StellarClient};//# sourceMappingURL=stellar-PRHQHVS4.mjs.map //# sourceMappingURL=stellar-PRHQHVS4.mjs.map