@swapkit/toolboxes 4.20.2 → 4.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/src/index.cjs +1 -1
- package/dist/src/stellar/index.cjs +1 -1
- package/dist/src/stellar/index.js +1 -1
- package/dist/types/stellar/index.d.ts +1 -1
- package/dist/types/stellar/toolbox.d.ts +4 -1
- package/dist/types/stellar/types.d.ts +8 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=Object.create;var{getPrototypeOf:e,defineProperty:O,getOwnPropertyNames:g,getOwnPropertyDescriptor:PP}=Object,h=Object.prototype.hasOwnProperty;function m(P){return this[P]}var jP,qP,NP=(P,q,Z)=>{var M=P!=null&&typeof P==="object";if(M){var N=q?jP??=new WeakMap:qP??=new WeakMap,L=N.get(P);if(L)return L}Z=P!=null?s(e(P)):{};let W=q||!P||!P.__esModule?O(Z,"default",{value:P,enumerable:!0}):Z;for(let _ of g(P))if(!h.call(W,_))O(W,_,{get:m.bind(P,_),enumerable:!0});if(M)N.set(P,W);return W},GP=(P)=>{var q=(v??=new WeakMap).get(P),Z;if(q)return q;if(q=O({},"__esModule",{value:!0}),P&&typeof P==="object"||typeof P==="function"){for(var M of g(P))if(!h.call(q,M))O(q,M,{get:m.bind(P,M),enumerable:!(Z=PP(P,M))||Z.enumerable})}return v.set(P,q),q},v;var JP=(P)=>P;function QP(P,q){this[P]=JP.bind(null,q)}var XP=(P,q)=>{for(var Z in q)O(P,Z,{get:q[Z],enumerable:!0,configurable:!0,set:QP.bind(q,Z)})};var b=(P,q)=>()=>(P&&(q=P(P=0)),q);async function WP(P){if(k&&Date.now()-k.timestamp<MP)return k.value;let Z=(await P.ledgers().order("desc").limit(1).call()).records[0]?.base_reserve_in_stroops;if(Z===void 0)throw new j.SwapKitError({errorKey:"toolbox_stellar_balance_error",info:{reason:"base_reserve_unavailable"}});return k={timestamp:Date.now(),value:Z},Z}function p(P){return j.AssetValue.from({chain:j.Chain.Stellar,value:P}).getBaseValue("bigint")}function FP({balance:P,baseReserveInStroops:q,numSponsored:Z,numSponsoring:M,sellingLiabilities:N,subentryCount:L}){let W=p(P),_=p(N),z=$P+L+M-Z,U=BigInt(z)*BigInt(q),B=W-U-_;return B>0n?B:0n}function y(P){if(!P||typeof P!=="string"||!P.startsWith("G")||P.length!==56)return!1;return YP.test(P)}function l(P){if(typeof P!=="object"||P===null)return;let q="response"in P?P.response:void 0;return typeof q?.status==="number"?q.status:void 0}function fP(P){return l(P)===504}function wP(P){return P.hash?.().toString("hex")}function LP(P){return[...new Set([P,...j.SKConfig.get("rpcUrls")[j.Chain.Stellar]])].filter(Boolean)}async function d(P){if(!y(P))return!1;try{let{StrKey:q}=await import("@stellar/stellar-sdk");return q.isValidEd25519PublicKey(P)}catch{return!1}}async function u(P){let{address:q,ticker:Z}=P,M=q?await d(q):!1;if(P.chain!==j.Chain.Stellar||P.isGasAsset||!ZP.test(Z)||!q||!M)throw new j.SwapKitError({errorKey:"helpers_invalid_asset_identifier",info:{identifier:P.toString()}});return{assetCode:Z,issuer:q}}function c(P={}){let q,Z=P.derivationPath||j.NetworkDerivationPath[j.Chain.Stellar],M=j.derivationPathToString(Z.slice(0,3));async function N({phrase:G,path:J}){let{HDKey:X}=await import("micro-key-producer/slip10.js"),{mnemonicToSeedSync:Q}=await import("@scure/bip39"),{Keypair:$}=await import("@stellar/stellar-sdk"),Y=Q(G),F=X.fromMasterSeed(Y).derive(J,!0);return $.fromRawEd25519Seed(Buffer.from(F.privateKey))}async function L(){if(q)return q;let G=H.match(P).with({phrase:H.P.string},({phrase:J})=>J).otherwise(()=>{return});if(!G)throw new j.SwapKitError("toolbox_stellar_no_signer");return q=await N({path:M,phrase:G}),q}async function W(G){let{Horizon:J}=await import("@stellar/stellar-sdk"),X=G||await j.getRPCUrl(j.Chain.Stellar);return new J.Server(X)}async function _(G,J){for(let X of J)try{return(await(await W(X)).transactions().transaction(G).call()).hash||G}catch{}return}async function z(G,J){let X=await j.getRPCUrl(j.Chain.Stellar),Q=LP(X),$=wP(G),Y;for(let f of Q)try{let F=await W(f),{hash:w}=await F.submitTransaction(G);return w}catch(F){if(Y=F,!fP(F))break;let w=$?await _($,Q):void 0;if(w)return w}throw new j.SwapKitError(J,Y)}async function U(){try{return(await L()).publicKey()}catch{return""}}async function B(G){let J=G||await U();if(!J)throw new j.SwapKitError("toolbox_stellar_account_not_found");let X=await W(),[Q,$]=await Promise.allSettled([X.loadAccount(J),WP(X)]);if(Q.status==="rejected"){let Y=Q.reason;if(l(Y)===404)return[j.AssetValue.from({chain:j.Chain.Stellar,value:0})];throw Y}if($.status==="rejected")throw $.reason;return Q.value.balances.map((Y)=>{if(Y.asset_type==="native"){let w=FP({balance:Y.balance,baseReserveInStroops:$.value,numSponsored:Q.value.num_sponsored,numSponsoring:Q.value.num_sponsoring,sellingLiabilities:Y.selling_liabilities,subentryCount:Q.value.subentry_count}),{baseDecimal:D}=j.getChainConfig(j.Chain.Stellar);return j.AssetValue.from({chain:j.Chain.Stellar,fromBaseDecimal:D,value:w})}let f="asset_code"in Y?Y.asset_code:"",F="asset_issuer"in Y?Y.asset_issuer:"";return j.AssetValue.from({asset:`${j.Chain.Stellar}.${f}-${F}`,asyncTokenLookup:!1,value:Y.balance})})}async function S({recipient:G,assetValue:J,memo:X,sender:Q}){if(X){if(new TextEncoder().encode(X).length>28)throw new j.SwapKitError("helpers_invalid_memo_type")}if(!await d(G))throw new j.SwapKitError("core_transaction_invalid_recipient_address");let Y=Q||await U();if(!Y)throw new j.SwapKitError("toolbox_stellar_no_signer");let{Asset:f,Memo:F,Networks:w,Operation:D,TransactionBuilder:I}=await import("@stellar/stellar-sdk"),E=await W(),C=await E.fetchBaseFee(),K=await E.loadAccount(Y),x=new I(K,{fee:String(C),networkPassphrase:w.PUBLIC});if(J.isGasAsset)try{await E.loadAccount(G),x.addOperation(D.payment({amount:J.getValue("string"),asset:f.native(),destination:G}))}catch{x.addOperation(D.createAccount({destination:G,startingBalance:J.getValue("string")}))}else{let{assetCode:V,issuer:a}=await u(J);x.addOperation(D.payment({amount:J.getValue("string"),asset:new f(V,a),destination:G}))}if(X)x.addMemo(F.text(X));return x.setTimeout(30).build()}async function R({assetValue:G,limit:J,sender:X}){let Q=X||await U();if(!Q)throw new j.SwapKitError("toolbox_stellar_no_signer");let{Asset:$,Networks:Y,Operation:f,TransactionBuilder:F}=await import("@stellar/stellar-sdk"),{assetCode:w,issuer:D}=await u(G),I=await W(),[E,C]=await Promise.all([I.fetchBaseFee(),I.loadAccount(Q)]),K=new $(w,D),x=J!==void 0?f.changeTrust({asset:K,limit:J}):f.changeTrust({asset:K});return new F(C,{fee:String(E),networkPassphrase:Y.PUBLIC}).addOperation(x).setTimeout(30).build()}async function A(G){let{TransactionBuilder:J,Networks:X}=await import("@stellar/stellar-sdk"),Q=await L(),$=J.fromXDR(G.toXDR(),X.PUBLIC);return $.sign(Q),$}function T(G){return z(G,"toolbox_stellar_broadcast_error")}async function i({recipient:G,assetValue:J,memo:X}){let Q=await L(),$=Q.publicKey(),Y=await S({assetValue:J,memo:X,recipient:G,sender:$});return Y.sign(Q),z(Y,"toolbox_stellar_transaction_failed")}async function n({assetValue:G,limit:J}){let X=await L(),Q=await R({assetValue:G,limit:J,sender:X.publicKey()});return Q.sign(X),z(Q,"toolbox_stellar_transaction_failed")}async function t(G){let J=await A(G);return T(J)}async function r(){let{baseDecimal:G}=j.getChainConfig(j.Chain.Stellar);try{let Q=(await(await W()).feeStats()).fee_charged.p50;return j.AssetValue.from({chain:j.Chain.Stellar,fromBaseDecimal:G,value:Q})}catch{return j.AssetValue.from({chain:j.Chain.Stellar,fromBaseDecimal:G,value:"100"})}}return{broadcastTransaction:T,createTransaction:S,createTrustline:n,createTrustlineTransaction:R,estimateTransactionFee:r,getAddress:U,getBalance:B,signAndBroadcastTransaction:t,signTransaction:A,transfer:i,validateAddress:y}}var j,H,YP,ZP,$P=2,MP=600000,k;var o=b(()=>{j=require("@swapkit/helpers"),H=require("ts-pattern"),YP=/^G[A-Z2-7]{55}$/,ZP=/^[A-Za-z0-9]{1,12}$/});var _P={};XP(_P,{validateStellarAddress:()=>y,getStellarToolbox:()=>c});module.exports=GP(_P);var DP=b(()=>{o()});DP();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ea as
|
|
1
|
+
import{ea as L}from"../../chunk-ntbvmmch.js";import{AssetValue as U,Chain as Z,derivationPathToString as n,getChainConfig as g,getRPCUrl as h,NetworkDerivationPath as t,SKConfig as r,SwapKitError as f}from"@swapkit/helpers";import{match as a,P as s}from"ts-pattern";var e=/^G[A-Z2-7]{55}$/,PP=/^[A-Za-z0-9]{1,12}$/,jP=2,qP=600000,k;async function GP(j){if(k&&Date.now()-k.timestamp<qP)return k.value;let M=(await j.ledgers().order("desc").limit(1).call()).records[0]?.base_reserve_in_stroops;if(M===void 0)throw new f({errorKey:"toolbox_stellar_balance_error",info:{reason:"base_reserve_unavailable"}});return k={timestamp:Date.now(),value:M},M}function m(j){return U.from({chain:Z.Stellar,value:j}).getBaseValue("bigint")}function JP({balance:j,baseReserveInStroops:X,numSponsored:M,numSponsoring:z,sellingLiabilities:H,subentryCount:x}){let w=m(j),y=m(H),E=jP+x+z-M,N=BigInt(E)*BigInt(X),B=w-N-y;return B>0n?B:0n}function S(j){if(!j||typeof j!=="string"||!j.startsWith("G")||j.length!==56)return!1;return e.test(j)}function p(j){if(typeof j!=="object"||j===null)return;let X="response"in j?j.response:void 0;return typeof X?.status==="number"?X.status:void 0}function QP(j){return p(j)===504}function XP(j){return j.hash?.().toString("hex")}function YP(j){return[...new Set([j,...r.get("rpcUrls")[Z.Stellar]])].filter(Boolean)}async function u(j){if(!S(j))return!1;try{let{StrKey:X}=await import("@stellar/stellar-sdk");return X.isValidEd25519PublicKey(j)}catch{return!1}}async function b(j){let{address:X,ticker:M}=j,z=X?await u(X):!1;if(j.chain!==Z.Stellar||j.isGasAsset||!PP.test(M)||!X||!z)throw new f({errorKey:"helpers_invalid_asset_identifier",info:{identifier:j.toString()}});return{assetCode:M,issuer:X}}function ZP(j={}){let X,M=j.derivationPath||t[Z.Stellar],z=n(M.slice(0,3));async function H({phrase:P,path:q}){let{HDKey:J}=await import("micro-key-producer/slip10.js"),{mnemonicToSeedSync:G}=await import("@scure/bip39"),{Keypair:Y}=await import("@stellar/stellar-sdk"),Q=G(P),$=J.fromMasterSeed(Q).derive(q,!0);return Y.fromRawEd25519Seed(Buffer.from($.privateKey))}async function x(){if(X)return X;let P=a(j).with({phrase:s.string},({phrase:q})=>q).otherwise(()=>{return});if(!P)throw new f("toolbox_stellar_no_signer");return X=await H({path:z,phrase:P}),X}async function w(P){let{Horizon:q}=await import("@stellar/stellar-sdk"),J=P||await h(Z.Stellar);return new q.Server(J)}async function y(P,q){for(let J of q)try{return(await(await w(J)).transactions().transaction(P).call()).hash||P}catch{}return}async function E(P,q){let J=await h(Z.Stellar),G=YP(J),Y=XP(P),Q;for(let W of G)try{let $=await w(W),{hash:F}=await $.submitTransaction(P);return F}catch($){if(Q=$,!QP($))break;let F=Y?await y(Y,G):void 0;if(F)return F}throw new f(q,Q)}async function N(){try{return(await x()).publicKey()}catch{return""}}async function B(P){let q=P||await N();if(!q)throw new f("toolbox_stellar_account_not_found");let J=await w(),[G,Y]=await Promise.allSettled([J.loadAccount(q),GP(J)]);if(G.status==="rejected"){let Q=G.reason;if(p(Q)===404)return[U.from({chain:Z.Stellar,value:0})];throw Q}if(Y.status==="rejected")throw Y.reason;return G.value.balances.map((Q)=>{if(Q.asset_type==="native"){let F=JP({balance:Q.balance,baseReserveInStroops:Y.value,numSponsored:G.value.num_sponsored,numSponsoring:G.value.num_sponsoring,sellingLiabilities:Q.selling_liabilities,subentryCount:G.value.subentry_count}),{baseDecimal:_}=g(Z.Stellar);return U.from({chain:Z.Stellar,fromBaseDecimal:_,value:F})}let W="asset_code"in Q?Q.asset_code:"",$="asset_issuer"in Q?Q.asset_issuer:"";return U.from({asset:`${Z.Stellar}.${W}-${$}`,asyncTokenLookup:!1,value:Q.balance})})}async function R({recipient:P,assetValue:q,memo:J,sender:G}){if(J){if(new TextEncoder().encode(J).length>28)throw new f("helpers_invalid_memo_type")}if(!await u(P))throw new f("core_transaction_invalid_recipient_address");let Q=G||await N();if(!Q)throw new f("toolbox_stellar_no_signer");let{Asset:W,Memo:$,Networks:F,Operation:_,TransactionBuilder:I}=await import("@stellar/stellar-sdk"),O=await w(),C=await O.fetchBaseFee(),K=await O.loadAccount(Q),D=new I(K,{fee:String(C),networkPassphrase:F.PUBLIC});if(q.isGasAsset)try{await O.loadAccount(P),D.addOperation(_.payment({amount:q.getValue("string"),asset:W.native(),destination:P}))}catch{D.addOperation(_.createAccount({destination:P,startingBalance:q.getValue("string")}))}else{let{assetCode:v,issuer:i}=await b(q);D.addOperation(_.payment({amount:q.getValue("string"),asset:new W(v,i),destination:P}))}if(J)D.addMemo($.text(J));return D.setTimeout(30).build()}async function A({assetValue:P,limit:q,sender:J}){let G=J||await N();if(!G)throw new f("toolbox_stellar_no_signer");let{Asset:Y,Networks:Q,Operation:W,TransactionBuilder:$}=await import("@stellar/stellar-sdk"),{assetCode:F,issuer:_}=await b(P),I=await w(),[O,C]=await Promise.all([I.fetchBaseFee(),I.loadAccount(G)]),K=new Y(F,_),D=q!==void 0?W.changeTrust({asset:K,limit:q}):W.changeTrust({asset:K});return new $(C,{fee:String(O),networkPassphrase:Q.PUBLIC}).addOperation(D).setTimeout(30).build()}async function T(P){let{TransactionBuilder:q,Networks:J}=await import("@stellar/stellar-sdk"),G=await x(),Y=q.fromXDR(P.toXDR(),J.PUBLIC);return Y.sign(G),Y}function V(P){return E(P,"toolbox_stellar_broadcast_error")}async function l({recipient:P,assetValue:q,memo:J}){let G=await x(),Y=G.publicKey(),Q=await R({assetValue:q,memo:J,recipient:P,sender:Y});return Q.sign(G),E(Q,"toolbox_stellar_transaction_failed")}async function d({assetValue:P,limit:q}){let J=await x(),G=await A({assetValue:P,limit:q,sender:J.publicKey()});return G.sign(J),E(G,"toolbox_stellar_transaction_failed")}async function c(P){let q=await T(P);return V(q)}async function o(){let{baseDecimal:P}=g(Z.Stellar);try{let G=(await(await w()).feeStats()).fee_charged.p50;return U.from({chain:Z.Stellar,fromBaseDecimal:P,value:G})}catch{return U.from({chain:Z.Stellar,fromBaseDecimal:P,value:"100"})}}return{broadcastTransaction:V,createTransaction:R,createTrustline:d,createTrustlineTransaction:A,estimateTransactionFee:o,getAddress:N,getBalance:B,signAndBroadcastTransaction:c,signTransaction:T,transfer:l,validateAddress:S}}export{S as validateStellarAddress,ZP as getStellarToolbox};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { getStellarToolbox, validateStellarAddress } from "./toolbox";
|
|
2
|
-
export type { StellarCreateTransactionParams, StellarToolboxParams, StellarTransferParams, StellarWallet, } from "./types";
|
|
2
|
+
export type { StellarCreateTransactionParams, StellarCreateTrustlineTransactionParams, StellarToolboxParams, StellarTransferParams, StellarTrustlineParams, StellarWallet, } from "./types";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AssetValue } from "@swapkit/helpers";
|
|
2
|
-
import type { StellarCreateTransactionParams, StellarToolboxParams, StellarTransferParams } from "./types";
|
|
2
|
+
import type { StellarCreateTransactionParams, StellarCreateTrustlineTransactionParams, StellarToolboxParams, StellarTransferParams, StellarTrustlineParams } from "./types";
|
|
3
|
+
export declare function _clearStellarBaseReserveCache(): void;
|
|
3
4
|
export declare function validateStellarAddress(address: string): boolean;
|
|
4
5
|
export declare function getStellarToolbox(params?: StellarToolboxParams): {
|
|
5
6
|
broadcastTransaction: (signedTransaction: {
|
|
@@ -7,6 +8,8 @@ export declare function getStellarToolbox(params?: StellarToolboxParams): {
|
|
|
7
8
|
toXDR: () => string;
|
|
8
9
|
}) => Promise<string>;
|
|
9
10
|
createTransaction: ({ recipient, assetValue, memo, sender }: StellarCreateTransactionParams) => Promise<import("@stellar/stellar-sdk").Transaction<import("@stellar/stellar-sdk").Memo<import("@stellar/stellar-sdk").MemoType>, import("@stellar/stellar-sdk").Operation[]>>;
|
|
11
|
+
createTrustline: ({ assetValue, limit }: StellarTrustlineParams) => Promise<string>;
|
|
12
|
+
createTrustlineTransaction: ({ assetValue, limit, sender }: StellarCreateTrustlineTransactionParams) => Promise<import("@stellar/stellar-sdk").Transaction<import("@stellar/stellar-sdk").Memo<import("@stellar/stellar-sdk").MemoType>, import("@stellar/stellar-sdk").Operation[]>>;
|
|
10
13
|
estimateTransactionFee: () => Promise<AssetValue>;
|
|
11
14
|
getAddress: () => Promise<string>;
|
|
12
15
|
getBalance: (checkAddress?: string) => Promise<AssetValue[]>;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type { DerivationPathArray, GenericCreateTransactionParams, GenericTransferParams } from "@swapkit/helpers";
|
|
1
|
+
import type { AssetValue, DerivationPathArray, GenericCreateTransactionParams, GenericTransferParams } from "@swapkit/helpers";
|
|
2
2
|
import type { getStellarToolbox } from "./toolbox";
|
|
3
3
|
export type StellarWallet = ReturnType<typeof getStellarToolbox>;
|
|
4
4
|
export type StellarCreateTransactionParams = Omit<GenericCreateTransactionParams, "feeRate">;
|
|
5
5
|
export type StellarTransferParams = Omit<GenericTransferParams, "feeRate">;
|
|
6
|
+
export type StellarTrustlineParams = {
|
|
7
|
+
assetValue: AssetValue;
|
|
8
|
+
limit?: string;
|
|
9
|
+
};
|
|
10
|
+
export type StellarCreateTrustlineTransactionParams = StellarTrustlineParams & {
|
|
11
|
+
sender?: string;
|
|
12
|
+
};
|
|
6
13
|
export type StellarToolboxParams = {
|
|
7
14
|
phrase?: string;
|
|
8
15
|
derivationPath?: DerivationPathArray;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"dependencies": { "@swapkit/helpers": "4.15.
|
|
2
|
+
"dependencies": { "@swapkit/helpers": "4.15.4", "@swapkit/utxo-signer": "2.2.3" },
|
|
3
3
|
"description": "SwapKit - Toolboxes",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@aptos-labs/ts-sdk": "7.0.1",
|
|
@@ -198,5 +198,5 @@
|
|
|
198
198
|
"type-check:go": "tsgo"
|
|
199
199
|
},
|
|
200
200
|
"type": "module",
|
|
201
|
-
"version": "4.
|
|
201
|
+
"version": "4.21.0"
|
|
202
202
|
}
|