@avalabs/core-wallets-sdk 3.1.0-alpha.9 → 3.1.0-alpha.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +435 -185
- package/esm/Avalanche/index.d.ts +5 -4
- package/esm/Avalanche/index.js +1 -1
- package/esm/Avalanche/models.d.ts +71 -4
- package/esm/Avalanche/models.js +1 -1
- package/esm/Avalanche/providers/AbstractProvider.d.ts +4 -14
- package/esm/Avalanche/providers/AbstractProvider.js +1 -1
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +4 -4
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
- package/esm/Avalanche/providers/constants.d.ts +2 -1
- package/esm/Avalanche/providers/constants.js +1 -1
- package/esm/Avalanche/providers/platformFeeConfig.js +1 -1
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/appendAutoRenewedValidatorConfigAddressMaps.js +1 -0
- package/esm/Avalanche/utils/appendDisableAuthAddressMaps.js +1 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +4 -3
- package/esm/Avalanche/utils/convertGlacierUtxo.js +1 -1
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +3 -2
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.d.ts +1 -1
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/getAssetBalance.d.ts +2 -1
- package/esm/Avalanche/utils/getAssetBalance.js +1 -1
- package/esm/Avalanche/utils/getAvalancheDerivationPath.d.ts +3 -0
- package/esm/Avalanche/utils/getAvalancheDerivationPath.js +1 -0
- package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
- package/esm/Avalanche/utils/getPchainUnixNow.d.ts +3 -1
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
- package/esm/Avalanche/utils/getStakedAssetBalance.d.ts +2 -1
- package/esm/Avalanche/utils/getTxOutputAddresses.js +1 -1
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +3 -2
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
- package/esm/Avalanche/utils/getVmByChainAlias.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -1
- package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
- package/esm/Avalanche/utils/orderBy.js +1 -0
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +12 -1
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/parsers/index.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddAutoRenewedValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddSubnetValidorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseBaseTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateChainTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseCreateSubnetTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseExportTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseImportTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRemoveSubnetValidatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseSetAutoRenewedValidatorConfigTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransferSubnetOwnershipTx.js +1 -1
- package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
- package/esm/Avalanche/utils/populateCredential.js +1 -1
- package/esm/Avalanche/utils/sortUTXOs.d.ts +5 -4
- package/esm/Avalanche/utils/sortUTXOs.js +1 -1
- package/esm/Avalanche/utils/txSizeLimits.d.ts +2 -2
- package/esm/Avalanche/utils/txSizeLimits.js +1 -1
- package/esm/Avalanche/wallets/AddressWallet.js +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.d.ts +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
- package/esm/Avalanche/wallets/StaticSigner.js +1 -1
- package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +139 -10
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +23 -27
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
- package/esm/Avalanche/wallets/WalletVoid.js +1 -1
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.d.ts +16 -0
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +4 -2
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/models.d.ts +1 -1
- package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -1
- package/esm/Avalanche/wallets/models.d.ts +1 -1
- package/esm/BitcoinVM/index.d.ts +5 -0
- package/esm/BitcoinVM/index.js +1 -0
- package/esm/BitcoinVM/models.d.ts +1 -1
- package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +3 -3
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -1
- package/esm/BitcoinVM/wallets/models.d.ts +1 -1
- package/esm/EVM/LedgerSigner.js +1 -1
- package/esm/EVM/utils/blockPolling.js +1 -1
- package/esm/EVM/utils/getEvmDerivationPath.d.ts +5 -0
- package/esm/EVM/utils/getEvmDerivationPath.js +1 -0
- package/esm/EVM/utils/getWalletFromMnemonic.js +1 -1
- package/esm/SolanaVM/utils/compileSolanaTx.d.ts +9 -0
- package/esm/SolanaVM/utils/compileSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/derivationPath.d.ts +3 -0
- package/esm/SolanaVM/utils/derivationPath.js +1 -0
- package/esm/SolanaVM/utils/deserializeSolanaTx.d.ts +6 -0
- package/esm/SolanaVM/utils/deserializeSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.d.ts +5 -0
- package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.js +1 -0
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.d.ts +40 -0
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.js +1 -0
- package/esm/SolanaVM/utils/resolveTokenProgramForMint.d.ts +13 -0
- package/esm/SolanaVM/utils/resolveTokenProgramForMint.js +1 -0
- package/esm/SolanaVM/utils/serializeSolanaTx.d.ts +6 -0
- package/esm/SolanaVM/utils/serializeSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/solanaProvider.d.ts +11 -0
- package/esm/SolanaVM/utils/solanaProvider.js +1 -0
- package/esm/SolanaVM/utils/transferSol.d.ts +14 -0
- package/esm/SolanaVM/utils/transferSol.js +1 -0
- package/esm/SolanaVM/utils/transferToken.d.ts +17 -0
- package/esm/SolanaVM/utils/transferToken.js +1 -0
- package/esm/SolanaVM/wallets/SolanaLedgerSigner.d.ts +10 -0
- package/esm/SolanaVM/wallets/SolanaLedgerSigner.js +1 -0
- package/esm/SolanaVM/wallets/SolanaSigner.d.ts +20 -0
- package/esm/SolanaVM/wallets/SolanaSigner.js +1 -0
- package/esm/abis/erc20.abi.js +1 -0
- package/esm/index.d.ts +33 -20
- package/esm/index.js +1 -1
- package/esm/utils/assertFeeStateProvided.js +1 -0
- package/esm/utils/getAddressDerivationPath.d.ts +8 -2
- package/esm/utils/getAddressDerivationPath.js +1 -1
- package/esm/utils/getPubKeyFromTransport.js +1 -1
- package/package.json +36 -13
- package/dist/index.js +0 -1
- package/esm/Avalanche/utils/getUtxoInfo.d.ts +0 -13
- package/esm/Avalanche/utils/getUtxoInfo.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"bip32-path";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as r}from"../../utils/digestMessage.js";import"bip32";import"@avalabs/avalanchejs";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";const s={C:60,X:9e3,P:9e3};class i{constructor(t){this.accountIndices=t}#t(t){return`m/44'/${s[t]}'`}#r(t,r){return`${this.#t(t)}/${r}'`}async signMessage(s){if(!s.transport||!s.message)throw new Error("Unable to sign message. Incomplete or invalid request.");if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a message.");const i=t.fromString(this.#r(s.chain,this.accountIndices[0])),n=t.fromString("0/0"),o=r(s.message),a=(await e.signHash(s.transport,o,i,[n])).signatures.get(n.toString(!0));if(!a)throw new Error("Failed to sign message.");return a}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const e=r.tx,s=e.getVM(),i=Buffer.from(e.toBytes()),n="EVM"===s?"C":"AVM"===s?"X":"P",o=new Set(r.externalIndices??this.accountIndices);for(const s of o){const o=t.fromString(this.#r(n,s));(await this.#e(o,{buffer:i,chain:n,transport:r.transport})).forEach((t=>{e.addSignature(t)}))}return e}async#e(r,s){if(!s.transport)throw new Error("Ledger transport not provided");return[...(await e.signTx(s.transport,s.buffer,r,s.signers??[t.fromString("0/0")],s.change??[t.fromString("0/0")])).signatures.values()]}async signTxBuffer(r){if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a tx buffer.");const e=t.fromString(this.#r(r.chain,this.accountIndices[0]));return this.#e(e,r)}}export{i as LedgerLiveSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletVoid as
|
|
1
|
+
import{WalletVoid as t}from"../WalletVoid.js";import{isObsidianApp as r}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import s from"@ledgerhq/hw-app-eth";import{utils as o}from"@avalabs/avalanchejs";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"bip32";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";import{SigningKey as p}from"ethers";const{strip0x:u}=o;class h extends t{constructor(t,r,e,i,s){const a=o.strip0x(p.computePublicKey(t,!0)),u=o.strip0x(p.computePublicKey(e,!0));if(super(Buffer.from(a,"hex"),Buffer.from(u,"hex"),s),this.pathXP=r,this.pathC=i,!n(r)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(t,e,i,o){if(await r(t))throw new Error("Ledger app not supported. Must be version >= 0.6.0");if(!n(e)||!n(i))throw new Error("Invalid path configuration.");const a=new s(t),f=await a.getAddress(i,!1),g=await a.getAddress(e,!1),m=Buffer.from(u(f.publicKey),"hex"),c=Buffer.from(u(g.publicKey),"hex"),l=Buffer.from(u(p.computePublicKey(m,!0)),"hex"),d=Buffer.from(u(p.computePublicKey(c,!0)),"hex");return new h(d,e,l,i,o)}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain)),o=a(t.message),n=(await e.signHash(t.transport,o,r,[s])).signatures.get(s.toString(!0));if(!n)throw new Error("Failed to sign message.");return n}getFullSignerPath(t){return"C"===t?this.pathC:this.pathXP}getPartialSignerPath(t){return this.getFullSignerPath(t).split("/").slice(4).join("/")}getAccountPath(t){return this.getFullSignerPath(t).split("/").slice(0,4).join("/")}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=t.tx,e=r.getVM(),i=Buffer.from(r.toBytes()),s="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:s,transport:t.transport})).forEach((t=>{r.addSignature(t)})),r}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain));return[...(await e.signTx(t.transport,t.buffer,r,[s],[s])).signatures.values()]}}export{h as LedgerSigner};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
2
2
|
import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '../models.js';
|
|
3
3
|
import { JsonRpcProvider } from '../../providers/JsonRpcProvider.js';
|
|
4
|
+
import { DerivationPath } from '../../../EVM/constants.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A wallet class that can sign X/P and C transactions.
|
|
@@ -12,12 +13,13 @@ import { JsonRpcProvider } from '../../providers/JsonRpcProvider.js';
|
|
|
12
13
|
declare class SimpleLedgerSigner implements Signer {
|
|
13
14
|
private activeAccountIndex;
|
|
14
15
|
private provider;
|
|
16
|
+
private pathSpec;
|
|
15
17
|
private accountNode;
|
|
16
18
|
/**
|
|
17
19
|
* @param {number} activeAccountIndex - the index of the primary account used for static signing
|
|
18
|
-
* @param {string} xpubXP - optional extended public key of `m/44'/9000'
|
|
20
|
+
* @param {string} xpubXP - optional extended public key of `m/44'/9000'/${activeAccountIndex}`
|
|
19
21
|
*/
|
|
20
|
-
constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string);
|
|
22
|
+
constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string, pathSpec?: DerivationPath);
|
|
21
23
|
private reSerializeTx;
|
|
22
24
|
private getChainAlias;
|
|
23
25
|
private getAccountPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{utils as t,EVMUnsignedTx as e,UnsignedTx as r}from"@avalabs/avalanchejs";import s from"bip32-path";import{getTxOutputAddresses as i}from"../../utils/getTxOutputAddresses.js";import{ZondaxProvider as n}from"./ZondaxProvider.js";import{fromBase58 as o}from"bip32";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as c}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";const{parse:h}=t;class p{constructor(t,e,r,s=c.BIP44){this.activeAccountIndex=t,this.provider=e,this.pathSpec=s,r&&(this.accountNode=o(r))}accountNode;reSerializeTx(t,s){return t instanceof e||"C"===s?e.fromJSON(JSON.stringify(t.toJSON())):r.fromJSON(JSON.stringify(t.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return`m/44'/9000'/${this.activeAccountIndex}'`;case"C":return`m/44'/60'/${this.pathSpec===c.LedgerLive?this.activeAccountIndex:0}'`}}getAddressOfPath(t,e){if(!this.accountNode)return null;const{publicKey:r}=this.accountNode.derivePath(t),s=this.provider.getAddress(r,e);return Buffer.from(h(s)[2]).toString("hex")}getAddressPathMap(t){const{tx:e,externalIndices:r,internalIndices:s}=t,i=this.getChainAlias(e),n="EVM"===t.tx.getVM()?`0/${this.pathSpec===c.LedgerLive?0:this.activeAccountIndex}`:"0/0",o=new Map;if("C"===i||!this.accountNode)return o;const a=[n,...(r??[]).map((t=>`0/${t}`)),...(s??[]).map((t=>`1/${t}`))];for(const t of a){const e=this.getAddressOfPath(t,i);e&&o.set(e,t)}return o}getAddressBipPaths(t,e,r){return 0===e.size?[s.fromString("C"===r?`0/${this.pathSpec===c.LedgerLive?0:this.activeAccountIndex}`:"0/0")]:t.reduce(((t,r)=>{const i=e.get(Buffer.from(r).toString("hex"));return i&&t.push(s.fromString(i)),t}),[])}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const e=this.getChainAlias(t.tx),r=this.reSerializeTx(t.tx,e),s=Buffer.from(r.toBytes()),n=this.getAddressPathMap(t),o=this.getAddressBipPaths(r.getAddresses(),n,e),a=this.getAddressBipPaths([...i(r)],n,e);return(await this.signTxBuffer({buffer:s,chain:e,transport:t.transport,signers:o,change:a})).forEach((t=>{r.addSignature(t)})),r}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");if(!t.signers)throw new Error("Signers not provided");const e=t.change||[],r=s.fromString(this.getAccountPath(t.chain));return[...(await n.signTx(t.transport,t.buffer,r,t.signers,e)).signatures.values()]}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const e="C"===t.chain?this.activeAccountIndex:0,r=t.signer||s.fromString(`0/${e}`);if(2!=r.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const i=a(t.message),o=(await n.signHash(t.transport,i,s.fromString(this.getAccountPath(t.chain)),[r])).signatures.get(r.toString(!0));if(!o)throw new Error("Failed to sign message.");return o}}export{p as SimpleLedgerSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MnemonicWalletVoid as r}from"./MnemonicWalletVoid.js";import{getAppEth as t}from"../../../EVM/utils/getAppEth.js";import{SigningKey as e}from"ethers";import{
|
|
1
|
+
import{MnemonicWalletVoid as r}from"./MnemonicWalletVoid.js";import{getAppEth as t}from"../../../EVM/utils/getAppEth.js";import{SigningKey as e}from"ethers";import{DerivationPath as s}from"../../../EVM/constants.js";import{fromPublicKey as i}from"bip32";import"bip39";import"bitcoinjs-lib";import{strip0x as n}from"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import o from"bip32-path";import{isObsidianApp as a}from"../ledger/isObsidianApp.js";import{ZondaxProvider as d}from"../ledger/ZondaxProvider.js";import{getTxOutputAddresses as p}from"../../utils/getTxOutputAddresses.js";import{getAddressDerivationPath as f}from"../../../utils/getAddressDerivationPath.js";import{utils as m}from"@avalabs/avalanchejs";import"hdkey";const{parse:c}=m;class g extends r{constructor(r,t,e){super(r,t,e)}getAdditionalAddressesByIndices(r,t,e){return"C"===e?[]:r.map((r=>{const s=this.getAddressAtIndex(r,t,e),[,,i]=c(s);return Buffer.from(i).toString("hex")}))}static async fromTransport(r,o){if(await a(r))throw new Error("Unsupported ledger app version. Must be >= 0.6.0");const p=t(r),m=await d.getXPUB(r,g.getAccountPath("X")),c=i(m.pubKey,m.chainCode),h=f(0,"EVM",{pathSpec:s.BIP44}),u=await p.getAddress(h,!1),l=e.computePublicKey(Buffer.from(u.publicKey,"hex"),!0),w=Buffer.from(n(l),"hex");return new g(c.toBase58(),w,o)}static getAccountPath(r){switch(r){case"P":case"X":return"m/44'/9000'/0'";case"C":return"m/44'/60'/0'"}}async signMessage(r){throw new Error("not implemented")}filterOwnedAddresses(r,t,e){const s=this.getInternalRawAddresses().map((r=>r.toString("hex"))),i=this.getExternalRawAddresses().map((r=>r.toString("hex"))),n=new Set([...s,...e??[]]),o=new Set([...i,...t??[]]),a=new Set;return r.forEach((r=>{const t=r.toString("hex");if(n.has(t)){const r=[...n].indexOf(t);a.add(`1/${r}`)}else if(o.has(t)){const r=[...o].indexOf(t);a.add(`0/${r}`)}})),a}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const{tx:t,externalIndices:e,internalIndices:s}=r,i=t.getVM(),n=Buffer.from(t.toBytes()),a="EVM"===i?"C":"X",d=t.getAddresses().map((r=>Buffer.from(r))),f=this.getAdditionalAddressesByIndices(e??[],!1,a),m=this.getAdditionalAddressesByIndices(s??[],!0,a),c=[...this.filterOwnedAddresses(d,f,m).values()].map((r=>o.fromString(r))),g=[...p(t)].map((r=>Buffer.from(r))),h=[...this.filterOwnedAddresses(g).values()].map((r=>o.fromString(r)));return(await this.signTxBuffer({buffer:n,chain:a,transport:r.transport,signers:c,change:h})).forEach((r=>{t.addSignature(r)})),t}async signTxBuffer(r){if(!r.transport)throw new Error("Ledger transport not provided");if(!r.signers)throw new Error("Signers not provided");const t=r.change||[],e=o.fromString(g.getAccountPath(r.chain));return[...(await d.signTx(r.transport,r.buffer,e,r.signers,t)).signatures.values()]}}export{g as LedgerWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MnemonicWalletVoid as e}from"./MnemonicWalletVoid.js";import{
|
|
1
|
+
import{MnemonicWalletVoid as e}from"./MnemonicWalletVoid.js";import{utils as t,addTxSignatures as r}from"@avalabs/avalanchejs";import{validateMnemonic as i,mnemonicToSeedSync as n}from"bip39";import{fromBase58 as o,fromSeed as s}from"bip32";import"@ledgerhq/hw-app-eth";import{SigningKey as a}from"ethers";import{DerivationPath as p}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{getAddressDerivationPath as c}from"../../../utils/getAddressDerivationPath.js";import"hdkey";const{strip0x:h}=t;class m extends e{constructor(e,t,r){const i=o(e).neutered(),n=new a(t),s=Buffer.from(h(n.compressedPublicKey),"hex");super(i.toBase58(),s,r),this.evmPrivKey=t,this.accountNode=o(e)}accountNode;static fromMnemonic(e,t){if(!i(e))throw new Error("Invalid mnemonic phrase.");const r=n(e),o=s(r),a=o.derivePath("m/44'/9000'/0'"),h=o.derivePath(c(0,"EVM",{pathSpec:p.BIP44}));if(!h.privateKey)throw new Error("Unable to derive EVM private key.");return new m(a.toBase58(),h.privateKey,t)}async signTx(e){const t=this.getSigningKeys(e);return await r({unsignedTx:e.tx,privateKeys:t}),e.tx}getExternalPrivateKeys(e){const t=[];for(let e=0;e<=this.externalIndex;e++){const r=this.accountNode.derivePath(`0/${e}`);if(!r.privateKey)throw new Error("Unable to get private key.");t.push(r.privateKey)}const r=(e??[]).reduce(((e,t)=>{if(t>this.externalIndex){const r=this.accountNode.derivePath(`0/${t}`);if(!r.privateKey)throw new Error("Unable to get private key.");e.push(r.privateKey)}return e}),[]);return[...t,...r]}getInternalPrivateKeys(e){const t=[];for(let e=0;e<=this.internalIndex;e++){const r=this.accountNode.derivePath(`1/${e}`);if(!r.privateKey)throw new Error("Unable to get private key.");t.push(r.privateKey)}const r=(e??[]).reduce(((e,t)=>{if(t>this.internalIndex){const r=this.accountNode.derivePath(`1/${t}`);if(!r.privateKey)throw new Error("Unable to get private key.");e.push(r.privateKey)}return e}),[]);return[...t,...r]}getSigningKeys(e){const{tx:t,externalIndices:r,internalIndices:i}=e;return"EVM"===t.getVM()?[this.evmPrivKey]:[...this.getInternalPrivateKeys(i),...this.getExternalPrivateKeys(r)]}async signTxBuffer(e){throw new Error("not implemented")}async signMessage(e){throw new Error("not implemented")}}export{m as MnemonicWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fromBase58 as e,fromSeed as t}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{WalletVoid as n}from"../WalletVoid.js";import{WalletAbstract as d}from"../WalletAbstract.js";import"@ledgerhq/hw-app-eth";import"ethers";import{
|
|
1
|
+
import{fromBase58 as e,fromSeed as t}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{WalletVoid as n}from"../WalletVoid.js";import{WalletAbstract as d}from"../WalletAbstract.js";import"@ledgerhq/hw-app-eth";import"ethers";import{getEVMDerivationPath as i}from"../../../EVM/utils/getEvmDerivationPath.js";import{DerivationPath as a}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{utils as o}from"@avalabs/avalanchejs";const{parse:h}=o;class l extends d{constructor(t,r,s){super(s),this.avmXpub=t,this.accountNode=e(t),this.evmWallet=new n(r,r,s)}accountNode;evmWallet;externalIndex=0;internalIndex=0;pubkeyCache={};static fromMnemonic(e,n){if(!r(e))throw new Error("Invalid mnemonic phrase.");const d=s(e),o=t(d),h=o.derivePath("m/44'/9000'/0'").neutered(),m=o.derivePath(i(0,a.BIP44)).neutered();return new l(h.toBase58(),m.publicKey,n)}setExternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.externalIndex=e}setInternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.internalIndex=e}getPubKeyAtIndex(e,t=!1){if(e<0)throw new Error("Index must be >= 0");const r=`${t?1:0}/${e}`,s=this.pubkeyCache[r];if(s)return s;const{publicKey:n}=this.accountNode.derivePath(r);return this.pubkeyCache[r]=n,n}getAddressAtIndex(e,t=!1,r){const s=this.getPubKeyAtIndex(e,t);return this.provider.getAddress(s,r)}getExternalAddresses(e){const t=[];for(let r=0;r<=this.externalIndex;r++)t.push(this.getAddressAtIndex(r,!1,e));return t}getInternalAddresses(e){const t=[];for(let r=0;r<=this.internalIndex;r++)t.push(this.getAddressAtIndex(r,!0,e));return t}getAddresses(e){return"C"===e?[this.getCurrentAddress("C")]:"P"===e?[...this.getExternalAddresses(e)]:[...this.getInternalAddresses(e),...this.getExternalAddresses(e)]}getChangeAddress(e){return"C"===e?this.evmWallet.getAddress("C"):"P"===e?this.getAddressAtIndex(this.externalIndex,!1,"P"):this.getAddressAtIndex(this.internalIndex,!0,e)}getCurrentAddress(e){return"C"===e?this.evmWallet.getAddress("C"):this.getAddressAtIndex(this.externalIndex,!1,e)}incrementIndex(e){e?this.externalIndex++:this.internalIndex++}getAddressEVM(){return this.evmWallet.getAddressEVM()}getActiveIndices(){return{external:this.externalIndex,internal:this.internalIndex}}getInternalRawAddresses(){return this.getInternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getExternalRawAddresses(){return this.getExternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getRawAddressC(){return Buffer.from(h(this.getCurrentAddress("C"))[2])}}export{l as MnemonicWalletVoid};
|
|
@@ -32,4 +32,4 @@ interface LedgerGetXpubResponse {
|
|
|
32
32
|
chain_code: Buffer;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export { LedgerGetXpubResponse, SignMessageRequest, SignTxBufferRequest, SignTxRequest, Signer };
|
|
35
|
+
export type { LedgerGetXpubResponse, SignMessageRequest, SignTxBufferRequest, SignTxRequest, Signer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{networks as a}from"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import"bip32";import"bip39";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";import"../Avalanche/wallets/WalletAbstract.js";import"../Avalanche/utils/addSignaturesToAvalancheTx.js";import"../Avalanche/utils/convertGlacierUtxo.js";import"../Avalanche/utils/createAvalancheEvmUnsignedTx.js";import"../Avalanche/utils/createAvalancheUnsignedTx.js";import"create-hash";import"@avalabs/avalanchejs";import"../Avalanche/utils/getAssetBalance.js";import"../Avalanche/utils/getUtxosByTxFromGlacier.js";import"../Avalanche/utils/parseAvalancheTx.js";import"../Avalanche/utils/populateCredential.js";import"../Avalanche/utils/txSizeLimits.js";import"bip32-path";import"@avalabs/hw-app-avalanche";import"../Avalanche/wallets/legacy/MnemonicWalletVoid.js";import"../Avalanche/wallets/legacy/LedgerWallet.js";import"../Avalanche/wallets/legacy/MnemonicWallet.js";import"../Avalanche/wallets/StaticSigner.js";import"../Avalanche/wallets/ledger/LedgerSigner.js";import"../Avalanche/wallets/ledger/SimpleLedgerSigner.js";import"../Avalanche/providers/AbstractProvider.js";import"../Avalanche/providers/constants.js";import"@avalabs/core-chains-sdk";import"@solana/kit";import"@solana-program/system";import"@solana-program/token";import"@solana-program/token-2022";import"@ledgerhq/hw-app-solana";import"@noble/curves/ed25519";import"@scure/base";import"micro-key-producer/slip10.js";import"hdkey";const e=a;export{e as BtcNetworks};
|
|
@@ -74,4 +74,4 @@ interface BitcoinTx {
|
|
|
74
74
|
}[];
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export { BitcoinHistoryTx, BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinLedgerInputUTXO, BitcoinOutputUTXO, BitcoinTx };
|
|
77
|
+
export type { BitcoinHistoryTx, BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinLedgerInputUTXO, BitcoinOutputUTXO, BitcoinTx };
|
|
@@ -8,12 +8,12 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
|
|
|
8
8
|
private readonly extraParams?;
|
|
9
9
|
constructor(isMainnet?: boolean, apiKey?: string, explorerUrl?: string, nodeUrl?: string, extraParams?: Record<string, string> | undefined);
|
|
10
10
|
getTxHex(txHash: string): Promise<string>;
|
|
11
|
-
getUTXOs(address: string, withScripts?: boolean): Promise<{
|
|
11
|
+
getUTXOs(address: string, withScripts?: boolean, skipBatch?: boolean): Promise<{
|
|
12
12
|
confirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
13
13
|
unconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
14
14
|
}>;
|
|
15
15
|
getAddressFromScript(script: string): Promise<string>;
|
|
16
|
-
getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[]): Promise<BitcoinInputUTXO[]>;
|
|
16
|
+
getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[], skipBatch?: boolean): Promise<BitcoinInputUTXO[]>;
|
|
17
17
|
private _parseUtxo;
|
|
18
18
|
getBalances(address: string): Promise<{
|
|
19
19
|
available: bigint;
|
|
@@ -21,7 +21,7 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
|
|
|
21
21
|
final: bigint;
|
|
22
22
|
}>;
|
|
23
23
|
getChainHeight(): Promise<number>;
|
|
24
|
-
getFeeRates(): Promise<{
|
|
24
|
+
getFeeRates(skipBatch?: boolean): Promise<{
|
|
25
25
|
low: number;
|
|
26
26
|
medium: number;
|
|
27
27
|
high: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BitcoinProviderAbstract as t}from"./BitcoinProviderAbstract.js";import{networks as e}from"bitcoinjs-lib";import{HttpClient as a}from"@avalabs/core-utils-sdk";import{URL_EXPLORER_MAINNET as s,URL_EXPLORER_TESTNET as r,URL_NODE_MAINNET as i,URL_NODE_TESTNET as n}from"./models.js";import{parseAddressFullTx as o}from"./utils/parseAddressFullTx.js";class l extends t{constructor(t=!0,e,o,l,c){super(),this.isMainnet=t,this.extraParams=c;const m=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,m);const d=t?i:n;this.#e=new a(l||d,m)}#t;#e;async#a(t){return this.isMainnet?(await Promise.all(t.map((t=>this.#e.post("",t,{},this.extraParams))))).flat():this.#e.post("",t,{},this.extraParams)}async getTxHex(t){return(await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams)).hex}async getUTXOs(t,e=!0){const
|
|
1
|
+
import{BitcoinProviderAbstract as t}from"./BitcoinProviderAbstract.js";import{networks as e}from"bitcoinjs-lib";import{HttpClient as a}from"@avalabs/core-utils-sdk";import{URL_EXPLORER_MAINNET as s,URL_EXPLORER_TESTNET as r,URL_NODE_MAINNET as i,URL_NODE_TESTNET as n}from"./models.js";import{parseAddressFullTx as o}from"./utils/parseAddressFullTx.js";class l extends t{constructor(t=!0,e,o,l,c){super(),this.isMainnet=t,this.extraParams=c;const m=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,m);const d=t?i:n;this.#e=new a(l||d,m)}#t;#e;async#a(t,e){return this.isMainnet||e?(await Promise.all(t.map((t=>this.#e.post("",t,{},this.extraParams))))).flat():this.#e.post("",t,{},this.extraParams)}async getTxHex(t){return(await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams)).hex}async getUTXOs(t,e=!0,a){const s=await this.#t.post(`/api/v2/utxo/${t}`,{},{},this.extraParams);if(!s?.length)return{confirmed:[],unconfirmed:[]};const r=s.map(this._parseUtxo),i=t=>({confirmed:t.filter((t=>t.confirmations>0)),unconfirmed:t.filter((t=>0===t.confirmations))});if(!e)return i(r);return i(await this.getScriptsForUtxos(r,a))}async getAddressFromScript(t){const e=await this.#e.post("",{jsonrpc:"2.0",id:`decode-script-${t}`,method:"decodescript",params:[t]},{},this.extraParams);if(e.result)return e.result.address;throw new Error(`Unable to resolve address for script: ${t}. ${e.error.message}`)}async getScriptsForUtxos(t,e){const[a,s]=t.reduce((([t,e],a)=>a.script?[[...t,a],e]:[t,[...e,a]]),[[],[]]),r=s.map(((t,e)=>({jsonrpc:"2.0",method:"gettxout",params:[t.txHash,t.index],id:`${e}`}))),i=r.length?(await this.#a(r,e)).sort(((t,e)=>Number(t.id)-Number(e.id))):[];return[...a,...s.map(((t,e)=>({...t,script:i[e]?.result?.scriptPubKey.hex})))]}_parseUtxo(t){return{...t,txHash:t.txid,index:t.vout,value:Number(t.value),blockHeight:t.height,script:t.script,confirmations:t.confirmations}}async getBalances(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams);return{available:BigInt(e.balance),pending:BigInt(e.unconfirmedBalance),final:BigInt(e.balance)+BigInt(e.unconfirmedBalance)}}async getChainHeight(){return(await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"getblockcount",params:[]},{},this.extraParams)).result}async getFeeRates(t){const e={jsonrpc:"2.0",method:"estimatesmartfee"},a=await this.#a([{...e,id:"1",params:[1]},{...e,id:"2",params:[3]},{...e,id:"3",params:[6]}],t).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.ceil(a[0]/1024)||1,medium:Math.ceil(a[1]/1024)||1,low:Math.ceil(a[2]/1024)||1}}getNetwork(){return this.isMainnet?e.bitcoin:e.testnet}async issueRawTx(t){return await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"sendrawtransaction",params:[t]},{},this.extraParams).then((t=>t.result))}async getTransaction(t){const e=await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams);return{block:e.blockHeight,fees:Number(e.fees),confirmations:e.confirmations,amount:Number(e.value),hash:e.txid,addresses:Array.from(new Set([...e.vin.map((t=>t.addresses||[])).flat(),...e.vout.map((t=>t.addresses||[])).flat()])),blockTime:e.blockTime,inputs:[...e.vin.map((t=>({...t,value:Number(t.value)})))],outputs:[...e.vout.map((t=>({...t,value:Number(t.value)})))]}}async getTxHistory(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams),a=e.txids?.slice(0,25)??[];return await Promise.allSettled(a.map((async e=>{try{const a=await this.#t.post(`/api/v2/tx/${e}`,{},{},this.extraParams);return o(t,a)}catch(t){console.log(`Unable to parse full tx ${e}.`)}}))).then((t=>t.map((t=>"fulfilled"===t.status&&t.value?t.value:void 0)).filter((t=>void 0!==t))))}async waitForTx(t,{maxAttempts:e=20,attempt:a=1,pollInterval:s=500}={}){try{return await this.getTransaction(t)}catch(r){if(a>=e)throw r;return await new Promise((t=>setTimeout(t,s))),this.waitForTx(t,{maxAttempts:e,attempt:a+1,pollInterval:s})}}}export{l as BitcoinProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@ledgerhq/hw-app-eth";import"ethers";import"
|
|
1
|
+
import"@ledgerhq/hw-app-eth";import"ethers";import"bip32";import{getAddressPublicKeyFromXPub as t}from"../../EVM/utils/getAddressPublicKeyFromXPub.js";import"bip39";import{getBech32Address as r}from"./getBech32Address.js";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";function e(e,i,o){const p=t(e,i);return r(p,o)}export{e as getBech32AddressFromXPub};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ECPair as t}from"bitcoinjs-lib";import{BitcoinWalletAbstract as r}from"./BitcoinWalletAbstract.js";import{createPsbt as e}from"../utils/createPsbt.js";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import{
|
|
1
|
+
import{ECPair as t}from"bitcoinjs-lib";import{BitcoinWalletAbstract as r}from"./BitcoinWalletAbstract.js";import{createPsbt as e}from"../utils/createPsbt.js";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as i}from"../../EVM/constants.js";import{fromSeed as o}from"bip32";import{validateMnemonic as s,mnemonicToSeed as n}from"bip39";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";import{getAddressDerivationPath as a}from"../../utils/getAddressDerivationPath.js";import"@avalabs/avalanchejs";import"hdkey";class p extends r{keypair;constructor(r,e){const i=t.fromPrivateKey(r);super(i.publicKey,e),this.keypair=i}static async fromMnemonic(t,r,e,m=i.BIP44){if(r<0)throw new Error("Account index must be >= 0");if(!s(t))throw new Error("Invalid mnemonic phrase.");const l=await n(t),c=o(l),h=a(r,"EVM",{pathSpec:m}),f=c.derivePath(h);if(!f.privateKey)throw new Error("Unable to derive private key from the given mnemonic.");return new p(f.privateKey,e)}signTx(t,r){const i=e(t,r,this.provider.getNetwork());return Promise.resolve(this.signPsbt(i))}static fromEthersWallet(t,r){const e=t.privateKey;if(!e)throw new Error("Unable to get private key from ethers wallet.");const i=Buffer.from(e.substring(2),"hex");return new p(i,r)}signPsbt(t){return t.signAllInputs(this.keypair),t.validateSignaturesOfAllInputs(),t.finalizeAllInputs(),t.extractTransaction()}}export{p as BitcoinWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BitcoinWalletAbstract as t}from"./BitcoinWalletAbstract.js";import i
|
|
1
|
+
import{BitcoinWalletAbstract as t}from"./BitcoinWalletAbstract.js";import{AppClient as i}from"ledger-bitcoin";import"bitcoinjs-lib";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import"bip32";import"bip39";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{createPSBTV2 as r}from"../utils/createPSBTV2.js";import{psbt2ToPsbt0 as e}from"../utils/psbt2ToPsbt0.js";class s extends t{constructor(t,i,r,e,s){super(t,r),this.derivationPath=i,this.transport=e,this.walletPolicyDetails=s}setTransport(t){this.transport=t}async signTx(t,s){const a=function(t){return new i(t)}(this.transport),o=this.ecPair.publicKey,n=this.provider.getNetwork(),p=await a.getMasterFingerprint(),l=r(t,s,n,Buffer.from(p,"hex"),o,this.derivationPath),{policy:c,hmac:h}=this.walletPolicyDetails,m=await a.signPsbt(l,c,h),u=e(l,n,o,this.derivationPath);if(m.forEach((t=>{const[i,r]=t;u.updateInput(i,{partialSig:[{signature:r.signature,pubkey:r.pubkey}]})})),!u.validateSignaturesOfAllInputs())throw new Error("Failed to validate signatures");return u.finalizeAllInputs(),u.extractTransaction()}}export{s as BitcoinLedgerWallet};
|
package/esm/EVM/LedgerSigner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AbstractSigner as t,defineProperties as s,getAddress as i,toUtf8Bytes as e,hexlify as r,Signature as a,Transaction as n,TypedDataEncoder as o}from"ethers";import{getAppEth as h}from"./utils/getAppEth.js";import{
|
|
1
|
+
import{AbstractSigner as t,defineProperties as s,getAddress as i,toUtf8Bytes as e,hexlify as r,Signature as a,Transaction as n,TypedDataEncoder as o}from"ethers";import{getAppEth as h}from"./utils/getAppEth.js";import{getEVMDerivationPath as p}from"./utils/getEvmDerivationPath.js";import"bip32";import"bip39";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import{TransportStatusError as c,StatusCodes as d}from"@ledgerhq/hw-transport";import{TypedDataUtils as m,SignTypedDataVersion as g}from"@metamask/eth-sig-util";class u extends t{type="default";path;provider=null;accountIndex;derivationSpec;transport;_eth;constructor(t=0,i,e,r){super(),this.path=p(t,e),this.accountIndex=t,this.transport=i,this.derivationSpec=e,this._eth=h(i),s(this,{path:this.path,type:"default",provider:r??null})}setTransport(t){this._eth=h(t),this.transport=t}async getAddress(){const t=await this._eth.getAddress(this.path);return i(t.address)}async signMessage(t){"string"==typeof t&&(t=e(t));const s=r(t).substring(2),i=await this._eth.signPersonalMessage(this.path,s);return i.r="0x"+i.r,i.s="0x"+i.s,a.from(i).serialized}async signTransaction(t){const s=await this.populateTransaction(t);delete s.from;const i=n.from(s),e=i.unsignedSerialized,r=await this._eth.signTransaction(this.path,e.slice(2),null);return i.signature={v:BigInt("0x"+r.v),r:"0x"+r.r,s:"0x"+r.s},i.serialized}connect(t){return new u(this.accountIndex,this.transport,this.derivationSpec,t)}async signTypedData(t,s,i){const{EIP712Domain:e,...r}=s,n=o.getPrimaryType(r);try{const e=await this._eth.signEIP712Message(this.path,{domain:{name:t.name||void 0,chainId:t.chainId?Number(t.chainId):void 0,version:t.version||void 0,verifyingContract:t.verifyingContract||void 0,salt:t.salt?.toString()||void 0},types:{EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],...s},primaryType:n,message:i});return e.r="0x"+e.r,e.s="0x"+e.s,a.from(e).serialized}catch(e){if(e instanceof c&&e.statusCode===d.INS_NOT_SUPPORTED){const e=m.hashStruct(n,i,s,g.V4),r=m.hashStruct("EIP712Domain",t,s,g.V4),o=await this._eth.signEIP712HashedMessage(this.path,r.toString("hex"),e.toString("hex"));return o.r="0x"+o.r,o.s="0x"+o.s,a.from(o).serialized}throw e}}}export{u as LedgerSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"
|
|
1
|
+
import e from"../../abis/erc20.abi.js";import{Interface as a}from"ethers";const o=async(e,a,o,s)=>{const n=new Set(e.map((e=>e.toLowerCase()))),c=new Set(a.map((e=>e.toLowerCase()))),f=async e=>{const a=await o.getBlock(e,!0);a?.prefetchedTransactions.forEach((function(e){e.to&&c.has(e.to.toLowerCase())&&t(e,n)?s(e,{type:"erc20",contractAddress:e.to}):r(e,n)&&s(e,{type:"native"})}))},i=await o.on("block",f);return{unsubscribe:()=>i.off("block",f)}},r=(e,a)=>a.has(e.from.toLowerCase())||a.has((e.to??"").toLowerCase()),t=(o,r)=>{const t=new a(e).parseTransaction({data:o.data,value:o.value});if(r.has(o.from.toLowerCase()))return!0;if("transfer"===t?.name)return r.has(t.args[0]?.toLowerCase());if("transferFrom"===t?.name){const e=r.has(t.args[0]?.toLowerCase()),a=r.has(t.args[1]?.toLowerCase());return e||a}return!1};export{t as isERC20Transfer,r as isNativeTxn,o as onBalanceChange};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DerivationPath as r}from"../constants.js";const e=(e,t,s=!0)=>{switch(t){case r.BIP44:return`${s?"m/":""}44'/60'/0'/0/${e}`;case r.LedgerLive:return`${s?"m/":""}44'/60'/${e}'/0/0`;default:throw new Error("Invalid path spec")}};export{e as getEVMDerivationPath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HDNodeWallet as r,Mnemonic as e}from"ethers";import{
|
|
1
|
+
import{HDNodeWallet as r,Mnemonic as e}from"ethers";import{getEVMDerivationPath as t}from"./getEvmDerivationPath.js";function o(o,n,i){if(!(n>=0&&n%1==0))throw new Error("Account index must be an integer greater than or equal to 0.");return r.fromMnemonic(e.fromPhrase(o),t(n,i))}export{o as getWalletFromMnemonic};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { CompilableTransactionMessage } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
declare const compileSolanaTx: (compilableTx: CompilableTransactionMessage) => Readonly<Readonly<{
|
|
5
|
+
messageBytes: _solana_kit.TransactionMessageBytes;
|
|
6
|
+
signatures: _solana_kit.SignaturesMap;
|
|
7
|
+
}> & _solana_kit.TransactionWithLifetime>;
|
|
8
|
+
|
|
9
|
+
export { compileSolanaTx };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{compileTransaction as o}from"@solana/kit";const t=t=>o(t);export{t as compileSolanaTx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=(o,t=!0)=>`${t?"m/":""}44'/501'/${o}'/0'`;export{o as getSolanaDerivationPath};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { SolanaProvider } from './solanaProvider.js';
|
|
3
|
+
|
|
4
|
+
declare const deserializeTransactionMessage: (payload: string, prov: SolanaProvider) => Promise<_solana_kit.CompilableTransactionMessage<_solana_kit.TransactionVersion, _solana_kit.IInstruction<string, readonly (_solana_kit.IAccountLookupMeta<string, string> | _solana_kit.IAccountMeta<string>)[]>>>;
|
|
5
|
+
|
|
6
|
+
export { deserializeTransactionMessage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getTransactionDecoder as e,getBase64Encoder as o,getCompiledTransactionMessageDecoder as t,decompileTransactionMessageFetchingLookupTables as s}from"@solana/kit";const c=(c,d)=>{const n=e().decode(o().encode(c)),r=t().decode(n.messageBytes);return s(r,d)};export{c as deserializeTransactionMessage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"@ledgerhq/hw-app-solana";import{getSolanaDerivationPath as t}from"./derivationPath.js";const a=async(a,e)=>{const o=new r(e),{address:s}=await o.getAddress(t(a,!1));return s};export{a as getSolanaPublicKeyFromLedger};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { Address } from '@solana/kit';
|
|
3
|
+
import { SolanaProvider } from './solanaProvider.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper to abstract confirming the existence of an Associated Token Account (ATA).
|
|
7
|
+
* Useful for transferring SPL tokens, as each wallet must have an ATA for each token they own.
|
|
8
|
+
* If a ATA does not exist, gas estimates must include a one-time rent-exempt minimum for creating
|
|
9
|
+
* and holding an ATA on-chain.
|
|
10
|
+
* @param mint - The mint address of the token.
|
|
11
|
+
* @param owner - The public key of the wallet owner.
|
|
12
|
+
* @param provider - An instance of SolanaProvider to interact with the Solana blockchain.
|
|
13
|
+
* @param tokenProgram - SPL Token program id for this mint (legacy or Token-2022). If omitted, it is resolved via RPC.
|
|
14
|
+
* @returns { ataAddress: string; exists: boolean; info: SolanaAccountInfo } - The ATA address, a boolean indicating if it exists, and the account info if it does.
|
|
15
|
+
*/
|
|
16
|
+
declare const maybeGetAssociatedTokenAccount: ({ mint, owner, provider, tokenProgram: tokenProgramOverride, }: {
|
|
17
|
+
mint: string;
|
|
18
|
+
owner: string;
|
|
19
|
+
provider: SolanaProvider;
|
|
20
|
+
tokenProgram?: Address<string> | undefined;
|
|
21
|
+
}) => Promise<{
|
|
22
|
+
address: Address<string>;
|
|
23
|
+
exists: boolean;
|
|
24
|
+
info: Readonly<{
|
|
25
|
+
context: Readonly<{
|
|
26
|
+
slot: bigint;
|
|
27
|
+
}>;
|
|
28
|
+
value: (Readonly<{
|
|
29
|
+
executable: boolean;
|
|
30
|
+
lamports: _solana_kit.Lamports;
|
|
31
|
+
owner: Address<string>;
|
|
32
|
+
rentEpoch: bigint;
|
|
33
|
+
space: bigint;
|
|
34
|
+
}> & Readonly<{
|
|
35
|
+
data: _solana_kit.Base64EncodedDataResponse;
|
|
36
|
+
}>) | null;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
|
|
40
|
+
export { maybeGetAssociatedTokenAccount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{findAssociatedTokenPda as o}from"@solana-program/token";import{address as r}from"@solana/kit";import{resolveTokenProgramForMint as n}from"./resolveTokenProgramForMint.js";const t=async({mint:t,owner:e,provider:a,tokenProgram:i})=>{const m=i??await n({mint:t,provider:a}),[s]=await o({mint:r(t),owner:r(e),tokenProgram:m}),p=await a.getAccountInfo(s,{encoding:"base64"}).send();return{address:s,exists:Boolean(p.value),info:p}};export{t as maybeGetAssociatedTokenAccount};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address } from '@solana/kit';
|
|
2
|
+
import { SolanaProvider } from './solanaProvider.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loads the mint account and returns the SPL Token program that owns it
|
|
6
|
+
* (legacy Tokenkeg... or Token-2022 TokenzQd...).
|
|
7
|
+
*/
|
|
8
|
+
declare const resolveTokenProgramForMint: ({ mint, provider, }: {
|
|
9
|
+
mint: string;
|
|
10
|
+
provider: SolanaProvider;
|
|
11
|
+
}) => Promise<Address>;
|
|
12
|
+
|
|
13
|
+
export { resolveTokenProgramForMint };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as o}from"@solana/kit";import{TOKEN_PROGRAM_ADDRESS as r}from"@solana-program/token";import{TOKEN_2022_PROGRAM_ADDRESS as n}from"@solana-program/token-2022";const t=(o,r)=>String(o)===String(r),e=async({mint:e,provider:i})=>{const a=o(e),{value:m}=await i.getAccountInfo(a,{encoding:"base64"}).send();if(!m)throw new Error(`Mint account not found: ${e}`);const p=m.owner;if(t(p,r))return r;if(t(p,n))return n;throw new Error(`Unsupported token program for mint ${e}: ${String(p)}`)};export{e as resolveTokenProgramForMint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getBase64EncodedWireTransaction as o}from"@solana/kit";const t=t=>o(t);export{t as serializeSolanaTx};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
|
|
3
|
+
type SolanaProvider = ReturnType<typeof getSolanaProvider>;
|
|
4
|
+
declare const isSolanaProvider: (something: unknown) => something is _solana_kit.RpcDevnet<(_solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi) | (_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi)> | _solana_kit.RpcMainnet<(_solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi) | (_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi)>;
|
|
5
|
+
declare const getSolanaProvider: ({ isTestnet, rpcUrl, }: {
|
|
6
|
+
isTestnet: boolean;
|
|
7
|
+
rpcUrl: string;
|
|
8
|
+
}) => _solana_kit.RpcDevnet<(_solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi) | (_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi)> | _solana_kit.RpcMainnet<(_solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi) | (_solana_kit.RequestAirdropApi & _solana_kit.GetAccountInfoApi & _solana_kit.GetBalanceApi & _solana_kit.GetBlockApi & _solana_kit.GetBlockCommitmentApi & _solana_kit.GetBlockHeightApi & _solana_kit.GetBlockProductionApi & _solana_kit.GetBlocksApi & _solana_kit.GetBlocksWithLimitApi & _solana_kit.GetBlockTimeApi & _solana_kit.GetClusterNodesApi & _solana_kit.GetEpochInfoApi & _solana_kit.GetEpochScheduleApi & _solana_kit.GetFeeForMessageApi & _solana_kit.GetFirstAvailableBlockApi & _solana_kit.GetGenesisHashApi & _solana_kit.GetHealthApi & _solana_kit.GetHighestSnapshotSlotApi & _solana_kit.GetIdentityApi & _solana_kit.GetInflationGovernorApi & _solana_kit.GetInflationRateApi & _solana_kit.GetInflationRewardApi & _solana_kit.GetLargestAccountsApi & _solana_kit.GetLatestBlockhashApi & _solana_kit.GetLeaderScheduleApi & _solana_kit.GetMaxRetransmitSlotApi & _solana_kit.GetMaxShredInsertSlotApi & _solana_kit.GetMinimumBalanceForRentExemptionApi & _solana_kit.GetMultipleAccountsApi & _solana_kit.GetProgramAccountsApi & _solana_kit.GetRecentPerformanceSamplesApi & _solana_kit.GetRecentPrioritizationFeesApi & _solana_kit.GetSignaturesForAddressApi & _solana_kit.GetSignatureStatusesApi & _solana_kit.GetSlotApi & _solana_kit.GetSlotLeaderApi & _solana_kit.GetSlotLeadersApi & _solana_kit.GetStakeMinimumDelegationApi & _solana_kit.GetSupplyApi & _solana_kit.GetTokenAccountBalanceApi & _solana_kit.GetTokenAccountsByDelegateApi & _solana_kit.GetTokenAccountsByOwnerApi & _solana_kit.GetTokenLargestAccountsApi & _solana_kit.GetTokenSupplyApi & _solana_kit.GetTransactionApi & _solana_kit.GetTransactionCountApi & _solana_kit.GetVersionApi & _solana_kit.GetVoteAccountsApi & _solana_kit.IsBlockhashValidApi & _solana_kit.MinimumLedgerSlotApi & _solana_kit.SendTransactionApi & _solana_kit.SimulateTransactionApi)>;
|
|
9
|
+
|
|
10
|
+
export { getSolanaProvider, isSolanaProvider };
|
|
11
|
+
export type { SolanaProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSolanaRpc as t,devnet as e,mainnet as o}from"@solana/kit";const n=Symbol(),r=t=>!(!t||"object"!=typeof t)&&!0===t[n],c=({isTestnet:r,rpcUrl:c})=>{const l=t(r?e(c):o(c));return new Proxy(l,{get:(t,e,o)=>e===n||("then"===e||"catch"===e||"finally"===e?t:Reflect.get(t,e,o))})};export{c as getSolanaProvider,r as isSolanaProvider};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { SolanaProvider } from './solanaProvider.js';
|
|
3
|
+
|
|
4
|
+
declare const transferSol: ({ from, to, amount, provider, }: {
|
|
5
|
+
from: string;
|
|
6
|
+
to: string;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
provider: SolanaProvider;
|
|
9
|
+
}) => Promise<_solana_kit.ITransactionMessageWithFeePayer<string> & Omit<_solana_kit.TransactionMessageWithBlockhashLifetime & Readonly<{
|
|
10
|
+
instructions: readonly _solana_kit.IInstruction<string, readonly (_solana_kit.IAccountLookupMeta<string, string> | _solana_kit.IAccountMeta<string>)[]>[];
|
|
11
|
+
version: 0;
|
|
12
|
+
}>, "feePayer">>;
|
|
13
|
+
|
|
14
|
+
export { transferSol };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as o,createNoopSigner as t,pipe as a,createTransactionMessage as r,setTransactionMessageLifetimeUsingBlockhash as s,setTransactionMessageFeePayer as n,appendTransactionMessageInstructions as e}from"@solana/kit";import{getTransferSolInstruction as m}from"@solana-program/system";const i=async({from:i,to:c,amount:p,provider:u})=>{const{value:l}=await u.getLatestBlockhash().send(),d=[m({source:t(o(i)),destination:o(c),amount:p})];return a(r({version:0}),(o=>s(l,o)),(t=>n(o(i),t)),(o=>e(d,o)))};export{i as transferSol};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as _solana_kit from '@solana/kit';
|
|
2
|
+
import { IInstruction } from '@solana/kit';
|
|
3
|
+
import { SolanaProvider } from './solanaProvider.js';
|
|
4
|
+
|
|
5
|
+
declare const transferToken: ({ from, to, mint, amount, decimals, provider, }: {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
mint: string;
|
|
9
|
+
amount: bigint;
|
|
10
|
+
decimals: number;
|
|
11
|
+
provider: SolanaProvider;
|
|
12
|
+
}) => Promise<_solana_kit.ITransactionMessageWithFeePayer<string> & Omit<_solana_kit.TransactionMessageWithBlockhashLifetime & Readonly<{
|
|
13
|
+
instructions: readonly IInstruction<string, readonly (_solana_kit.IAccountLookupMeta<string, string> | _solana_kit.IAccountMeta<string>)[]>[];
|
|
14
|
+
version: 0;
|
|
15
|
+
}>, "feePayer">>;
|
|
16
|
+
|
|
17
|
+
export { transferToken };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as t,createNoopSigner as o,pipe as r,createTransactionMessage as e,setTransactionMessageLifetimeUsingBlockhash as a,setTransactionMessageFeePayer as n,appendTransactionMessageInstructions as i}from"@solana/kit";import{getCreateAssociatedTokenIdempotentInstruction as s,getTransferCheckedInstruction as m}from"@solana-program/token";import{getCreateAssociatedTokenIdempotentInstruction as c,TOKEN_2022_PROGRAM_ADDRESS as d,getTransferCheckedInstruction as p}from"@solana-program/token-2022";import{maybeGetAssociatedTokenAccount as u}from"./maybeGetAssociatedTokenAccount.js";import{resolveTokenProgramForMint as g}from"./resolveTokenProgramForMint.js";const k=async({from:k,to:l,mint:w,amount:f,decimals:h,provider:v})=>{const y=await g({mint:w,provider:v}),P=String(y)===String(d);const{address:T}=await u({mint:w,owner:k,provider:v,tokenProgram:y}),{address:A,exists:I}=await u({mint:w,owner:l,provider:v,tokenProgram:y}),j=[];I||j.push(P?c({payer:o(t(k)),mint:t(w),owner:t(l),ata:A,tokenProgram:d}):s({payer:o(t(k)),mint:t(w),owner:t(l),ata:A})),j.push(P?p({amount:f,authority:o(t(k)),decimals:h,mint:t(w),destination:A,source:T}):m({amount:f,authority:o(t(k)),decimals:h,mint:t(w),destination:A,source:T}));const{value:x}=await v.getLatestBlockhash().send();return r(e({version:0}),(t=>a(x,t)),(o=>n(t(k),o)),(t=>i(j,t)))};export{k as transferToken};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
2
|
+
import { SolanaProvider } from '../utils/solanaProvider.js';
|
|
3
|
+
|
|
4
|
+
declare class SolanaLedgerSigner {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(accountIndex: number, transport: Transport);
|
|
7
|
+
signTx(base64EncodedTx: string, provider: SolanaProvider): Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { SolanaLedgerSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{base58 as r}from"@scure/base";import t from"@ledgerhq/hw-app-solana";import{compileTransaction as a,address as s,assertIsSignature as i,getBase64EncodedWireTransaction as e}from"@solana/kit";import{deserializeTransactionMessage as o}from"../utils/deserializeSolanaTx.js";import"@solana-program/system";import"@solana-program/token";import"@solana-program/token-2022";import{getSolanaDerivationPath as n}from"../utils/derivationPath.js";class m{#r;#t;constructor(r,t){this.#r=n(r,!1),this.#t=t}async signTx(n,m){const p=await o(n,m),{signatures:d,messageBytes:u,...g}=a(p),h=new t(this.#t),{address:c}=await h.getAddress(this.#r),f=s(r.encode(Uint8Array.from(c)));if(!this.#a(f,d))return n;const{signature:l}=await h.signTransaction(this.#r,Buffer.from(u)),y=r.encode(Uint8Array.from(l));return i(y),e({...g,messageBytes:u,signatures:{...d,[f]:r.decode(y)}})}#a(r,t){return r in t&&!t[r]}}export{m as SolanaLedgerSigner};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SolanaProvider } from '../utils/solanaProvider.js';
|
|
2
|
+
|
|
3
|
+
declare class SolanaSigner {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(privateKey: Buffer);
|
|
6
|
+
static fromMnemonic(mnemonic: string, accountIndex: number): SolanaSigner;
|
|
7
|
+
/**
|
|
8
|
+
* @param message Base-64 encoded message bytes
|
|
9
|
+
* @returns Base-64 encoded signature
|
|
10
|
+
*/
|
|
11
|
+
signMessage(message: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* @param base64EncodedTx Base-64 encoded transaction
|
|
14
|
+
* @param provider SolanaProvider
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
signTx(base64EncodedTx: string, provider: SolanaProvider): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { SolanaSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mnemonicToSeedSync as e}from"bip39";import{ed25519 as r}from"@noble/curves/ed25519";import{base58 as i,base64 as t}from"@scure/base";import{address as s,getCompiledTransactionMessageDecoder as n,compileTransaction as o,assertIsSignature as a,getBase64EncodedWireTransaction as c}from"@solana/kit";import u from"micro-key-producer/slip10.js";import{deserializeTransactionMessage as m}from"../utils/deserializeSolanaTx.js";class p{#e;#r;constructor(e){this.#e=Uint8Array.from(e),this.#r=s(i.encode(r.getPublicKey(this.#e)))}static fromMnemonic(r,i){const t=e(r),s=u.fromMasterSeed(Uint8Array.from(t)).derive(`m/44'/501'/${i}'/0'`);return new p(Buffer.from(s.privateKey))}#i(e){try{return n().decode(e),!0}catch{return!1}}async signMessage(e){const i=t.decode(e);if(this.#i(i))throw new Error("Cannot use signMessage() to sign transactions!");return t.encode(r.sign(i,this.#e))}async signTx(e,t){const s=await m(e,t),{signatures:n,messageBytes:u,...p}=o(s);if(!this.#t(n))return e;const y=i.encode(r.sign(Uint8Array.from(u),this.#e));return a(y),c({...p,messageBytes:u,signatures:{...n,[this.#r]:i.decode(y)}})}#t(e){return this.#r in e&&!e[this.#r]}}export{p as SolanaSigner};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];export{e as default};
|