@hot-labs/kit 1.2.0-alpha.1 → 1.2.0-alpha.2
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/build/HotConnector.d.ts +104 -0
- package/build/HotConnector.js +306 -0
- package/build/HotConnector.js.map +1 -0
- package/build/OmniConnector.d.ts +85 -0
- package/build/OmniConnector.js +121 -0
- package/build/OmniConnector.js.map +1 -0
- package/build/OmniWallet.d.ts +42 -0
- package/build/OmniWallet.js +61 -0
- package/build/OmniWallet.js.map +1 -0
- package/build/activity.d.ts +18 -0
- package/build/activity.js +87 -0
- package/build/activity.js.map +1 -0
- package/build/core/Intents.d.ts +90 -0
- package/build/core/Intents.js +398 -0
- package/build/core/Intents.js.map +1 -0
- package/build/core/api.d.ts +32 -0
- package/build/core/api.js +75 -0
- package/build/core/api.js.map +1 -0
- package/build/core/bridge.d.ts +3 -0
- package/build/core/bridge.js +36 -0
- package/build/core/bridge.js.map +1 -0
- package/build/core/chains.d.ts +115 -0
- package/build/core/chains.js +381 -0
- package/build/core/chains.js.map +1 -0
- package/build/core/defaultTokens.d.ts +17 -0
- package/build/core/defaultTokens.js +1079 -0
- package/build/core/defaultTokens.js.map +1 -0
- package/build/core/events.d.ts +42 -0
- package/build/core/events.js +64 -0
- package/build/core/events.js.map +1 -0
- package/build/core/index.d.ts +10 -0
- package/build/core/index.js +11 -0
- package/build/core/index.js.map +1 -0
- package/build/core/nearRpc.d.ts +24 -0
- package/build/core/nearRpc.js +167 -0
- package/build/core/nearRpc.js.map +1 -0
- package/build/core/recipient.d.ts +10 -0
- package/build/core/recipient.js +40 -0
- package/build/core/recipient.js.map +1 -0
- package/build/core/token.d.ts +36 -0
- package/build/core/token.js +103 -0
- package/build/core/token.js.map +1 -0
- package/build/core/tokens.d.ts +14 -0
- package/build/core/tokens.js +59 -0
- package/build/core/tokens.js.map +1 -0
- package/build/core/types.d.ts +43 -0
- package/build/core/types.js +2 -0
- package/build/core/types.js.map +1 -0
- package/build/core/utils.d.ts +24 -0
- package/build/core/utils.js +150 -0
- package/build/core/utils.js.map +1 -0
- package/build/cosmos/connector.d.ts +36 -0
- package/build/cosmos/connector.js +215 -0
- package/build/cosmos/connector.js.map +1 -0
- package/build/cosmos/helpers.d.ts +2 -0
- package/build/cosmos/helpers.js +29 -0
- package/build/cosmos/helpers.js.map +1 -0
- package/build/cosmos/index.d.ts +6 -0
- package/build/cosmos/index.js +5 -0
- package/build/cosmos/index.js.map +1 -0
- package/build/cosmos/wallet.d.ts +28 -0
- package/build/cosmos/wallet.js +56 -0
- package/build/cosmos/wallet.js.map +1 -0
- package/build/defaults.d.ts +1 -0
- package/build/defaults.js +7 -0
- package/build/defaults.js.map +1 -0
- package/build/evm/abi.d.ts +17 -0
- package/build/evm/abi.js +38 -0
- package/build/evm/abi.js.map +1 -0
- package/build/evm/connector.d.ts +28 -0
- package/build/evm/connector.js +114 -0
- package/build/evm/connector.js.map +1 -0
- package/build/evm/index.d.ts +6 -0
- package/build/evm/index.js +5 -0
- package/build/evm/index.js.map +1 -0
- package/build/evm/injected.d.ts +1 -0
- package/build/evm/injected.js +33 -0
- package/build/evm/injected.js.map +1 -0
- package/build/evm/wallet.d.ts +41 -0
- package/build/evm/wallet.js +128 -0
- package/build/evm/wallet.js.map +1 -0
- package/build/exchange.d.ts +65 -0
- package/build/exchange.js +390 -0
- package/build/exchange.js.map +1 -0
- package/build/hot-wallet/google.d.ts +25 -0
- package/build/hot-wallet/google.js +112 -0
- package/build/hot-wallet/google.js.map +1 -0
- package/build/hot-wallet/iframe.d.ts +36 -0
- package/build/hot-wallet/iframe.js +140 -0
- package/build/hot-wallet/iframe.js.map +1 -0
- package/build/hot-wallet/index.d.ts +5 -0
- package/build/hot-wallet/index.js +4 -0
- package/build/hot-wallet/index.js.map +1 -0
- package/build/hot-wallet/proxy.d.ts +8 -0
- package/build/hot-wallet/proxy.js +45 -0
- package/build/hot-wallet/proxy.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/near/connector.d.ts +18 -0
- package/build/near/connector.js +58 -0
- package/build/near/connector.js.map +1 -0
- package/build/near/index.d.ts +7 -0
- package/build/near/index.js +5 -0
- package/build/near/index.js.map +1 -0
- package/build/near/wallet.d.ts +55 -0
- package/build/near/wallet.js +195 -0
- package/build/near/wallet.js.map +1 -0
- package/build/solana/connector.d.ts +30 -0
- package/build/solana/connector.js +138 -0
- package/build/solana/connector.js.map +1 -0
- package/build/solana/index.d.ts +6 -0
- package/build/solana/index.js +5 -0
- package/build/solana/index.js.map +1 -0
- package/build/solana/injected/account.d.ts +11 -0
- package/build/solana/injected/account.js +41 -0
- package/build/solana/injected/account.js.map +1 -0
- package/build/solana/injected/index.d.ts +1 -0
- package/build/solana/injected/index.js +82 -0
- package/build/solana/injected/index.js.map +1 -0
- package/build/solana/injected/register.d.ts +2 -0
- package/build/solana/injected/register.js +41 -0
- package/build/solana/injected/register.js.map +1 -0
- package/build/solana/injected/solana-wallet.d.ts +34 -0
- package/build/solana/injected/solana-wallet.js +223 -0
- package/build/solana/injected/solana-wallet.js.map +1 -0
- package/build/solana/injected/utils.d.ts +32 -0
- package/build/solana/injected/utils.js +36 -0
- package/build/solana/injected/utils.js.map +1 -0
- package/build/solana/protocol.d.ts +25 -0
- package/build/solana/protocol.js +56 -0
- package/build/solana/protocol.js.map +1 -0
- package/build/solana/wallet.d.ts +42 -0
- package/build/solana/wallet.js +190 -0
- package/build/solana/wallet.js.map +1 -0
- package/build/solana/wallets.d.ts +102 -0
- package/build/solana/wallets.js +150 -0
- package/build/solana/wallets.js.map +1 -0
- package/build/stellar/connector.d.ts +31 -0
- package/build/stellar/connector.js +67 -0
- package/build/stellar/connector.js.map +1 -0
- package/build/stellar/freigher.d.ts +46 -0
- package/build/stellar/freigher.js +110 -0
- package/build/stellar/freigher.js.map +1 -0
- package/build/stellar/hotWallet.d.ts +33 -0
- package/build/stellar/hotWallet.js +28 -0
- package/build/stellar/hotWallet.js.map +1 -0
- package/build/stellar/index.d.ts +6 -0
- package/build/stellar/index.js +5 -0
- package/build/stellar/index.js.map +1 -0
- package/build/stellar/wallet.d.ts +65 -0
- package/build/stellar/wallet.js +216 -0
- package/build/stellar/wallet.js.map +1 -0
- package/build/storage.d.ts +10 -0
- package/build/storage.js +12 -0
- package/build/storage.js.map +1 -0
- package/build/ton/connector.d.ts +25 -0
- package/build/ton/connector.js +114 -0
- package/build/ton/connector.js.map +1 -0
- package/build/ton/index.d.ts +7 -0
- package/build/ton/index.js +5 -0
- package/build/ton/index.js.map +1 -0
- package/build/ton/injected.d.ts +1 -0
- package/build/ton/injected.js +49 -0
- package/build/ton/injected.js.map +1 -0
- package/build/ton/utils.d.ts +45 -0
- package/build/ton/utils.js +63 -0
- package/build/ton/utils.js.map +1 -0
- package/build/ton/wallet.d.ts +55 -0
- package/build/ton/wallet.js +139 -0
- package/build/ton/wallet.js.map +1 -0
- package/build/ui/Popup.d.ts +12 -0
- package/build/ui/Popup.js +39 -0
- package/build/ui/Popup.js.map +1 -0
- package/build/ui/connect/AuthPopup.d.ts +2 -0
- package/build/ui/connect/AuthPopup.js +48 -0
- package/build/ui/connect/AuthPopup.js.map +1 -0
- package/build/ui/connect/ConnectWallet.d.ts +9 -0
- package/build/ui/connect/ConnectWallet.js +22 -0
- package/build/ui/connect/ConnectWallet.js.map +1 -0
- package/build/ui/connect/LogoutPopup.d.ts +10 -0
- package/build/ui/connect/LogoutPopup.js +8 -0
- package/build/ui/connect/LogoutPopup.js.map +1 -0
- package/build/ui/connect/WCPopup.d.ts +13 -0
- package/build/ui/connect/WCPopup.js +81 -0
- package/build/ui/connect/WCPopup.js.map +1 -0
- package/build/ui/connect/WCRequest.d.ts +9 -0
- package/build/ui/connect/WCRequest.js +13 -0
- package/build/ui/connect/WCRequest.js.map +1 -0
- package/build/ui/connect/WalletPicker.d.ts +11 -0
- package/build/ui/connect/WalletPicker.js +48 -0
- package/build/ui/connect/WalletPicker.js.map +1 -0
- package/build/ui/icons/arrow-right.d.ts +1 -0
- package/build/ui/icons/arrow-right.js +5 -0
- package/build/ui/icons/arrow-right.js.map +1 -0
- package/build/ui/icons/close.d.ts +1 -0
- package/build/ui/icons/close.js +5 -0
- package/build/ui/icons/close.js.map +1 -0
- package/build/ui/icons/exchange.d.ts +6 -0
- package/build/ui/icons/exchange.js +6 -0
- package/build/ui/icons/exchange.js.map +1 -0
- package/build/ui/icons/logout.d.ts +1 -0
- package/build/ui/icons/logout.js +3 -0
- package/build/ui/icons/logout.js.map +1 -0
- package/build/ui/icons/pending.d.ts +1 -0
- package/build/ui/icons/pending.js +5 -0
- package/build/ui/icons/pending.js.map +1 -0
- package/build/ui/icons/qr.d.ts +1 -0
- package/build/ui/icons/qr.js +5 -0
- package/build/ui/icons/qr.js.map +1 -0
- package/build/ui/icons/search.d.ts +1 -0
- package/build/ui/icons/search.js +5 -0
- package/build/ui/icons/search.js.map +1 -0
- package/build/ui/icons/switch.d.ts +1 -0
- package/build/ui/icons/switch.js +5 -0
- package/build/ui/icons/switch.js.map +1 -0
- package/build/ui/icons/wallet.d.ts +1 -0
- package/build/ui/icons/wallet.js +5 -0
- package/build/ui/icons/wallet.js.map +1 -0
- package/build/ui/payment/Bridge.d.ts +29 -0
- package/build/ui/payment/Bridge.js +358 -0
- package/build/ui/payment/Bridge.js.map +1 -0
- package/build/ui/payment/DepositQR.d.ts +9 -0
- package/build/ui/payment/DepositQR.js +56 -0
- package/build/ui/payment/DepositQR.js.map +1 -0
- package/build/ui/payment/Payment.d.ts +16 -0
- package/build/ui/payment/Payment.js +50 -0
- package/build/ui/payment/Payment.js.map +1 -0
- package/build/ui/payment/Profile.d.ts +8 -0
- package/build/ui/payment/Profile.js +110 -0
- package/build/ui/payment/Profile.js.map +1 -0
- package/build/ui/payment/SelectRecipient.d.ts +14 -0
- package/build/ui/payment/SelectRecipient.js +68 -0
- package/build/ui/payment/SelectRecipient.js.map +1 -0
- package/build/ui/payment/SelectSender.d.ts +13 -0
- package/build/ui/payment/SelectSender.js +23 -0
- package/build/ui/payment/SelectSender.js.map +1 -0
- package/build/ui/payment/SelectToken.d.ts +13 -0
- package/build/ui/payment/SelectToken.js +92 -0
- package/build/ui/payment/SelectToken.js.map +1 -0
- package/build/ui/payment/TokenCard.d.ts +23 -0
- package/build/ui/payment/TokenCard.js +63 -0
- package/build/ui/payment/TokenCard.js.map +1 -0
- package/build/ui/router.d.ts +37 -0
- package/build/ui/router.js +56 -0
- package/build/ui/router.js.map +1 -0
- package/build/ui/styles.d.ts +13 -0
- package/build/ui/styles.js +288 -0
- package/build/ui/styles.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { IdentifierString } from "@wallet-standard/base";
|
|
3
|
+
interface Indexed<T> {
|
|
4
|
+
length: number;
|
|
5
|
+
[index: number]: T;
|
|
6
|
+
}
|
|
7
|
+
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
8
|
+
export declare function arraysEqual<T>(a: Indexed<T>, b: Indexed<T>): boolean;
|
|
9
|
+
export declare const GhostNamespace = "hot:";
|
|
10
|
+
export type GhostFeature = {
|
|
11
|
+
[GhostNamespace]: {
|
|
12
|
+
ghost: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
|
|
16
|
+
export declare const SOLANA_MAINNET_CHAIN = "solana:mainnet";
|
|
17
|
+
/** Solana Devnet cluster, e.g. https://api.devnet.solana.com */
|
|
18
|
+
export declare const SOLANA_DEVNET_CHAIN = "solana:devnet";
|
|
19
|
+
/** Solana Testnet cluster, e.g. https://api.testnet.solana.com */
|
|
20
|
+
export declare const SOLANA_TESTNET_CHAIN = "solana:testnet";
|
|
21
|
+
/** Solana Localnet cluster, e.g. http://localhost:8899 */
|
|
22
|
+
export declare const SOLANA_LOCALNET_CHAIN = "solana:localnet";
|
|
23
|
+
/** Array of all Solana clusters */
|
|
24
|
+
export declare const SOLANA_CHAINS: readonly ["solana:mainnet", "solana:mainnet-beta"];
|
|
25
|
+
/** Type of all Solana clusters */
|
|
26
|
+
export type SolanaChain = (typeof SOLANA_CHAINS)[number];
|
|
27
|
+
/**
|
|
28
|
+
* Check if a chain corresponds with one of the Solana clusters.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isSolanaChain(chain: IdentifierString): chain is SolanaChain;
|
|
31
|
+
export declare function isVersionedTransaction(transaction: Transaction | VersionedTransaction): transaction is VersionedTransaction;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function bytesEqual(a, b) {
|
|
2
|
+
return arraysEqual(a, b);
|
|
3
|
+
}
|
|
4
|
+
export function arraysEqual(a, b) {
|
|
5
|
+
if (a === b)
|
|
6
|
+
return true;
|
|
7
|
+
const length = a.length;
|
|
8
|
+
if (length !== b.length)
|
|
9
|
+
return false;
|
|
10
|
+
for (let i = 0; i < length; i++) {
|
|
11
|
+
if (a[i] !== b[i])
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
export const GhostNamespace = "hot:";
|
|
17
|
+
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
|
|
18
|
+
export const SOLANA_MAINNET_CHAIN = "solana:mainnet";
|
|
19
|
+
/** Solana Devnet cluster, e.g. https://api.devnet.solana.com */
|
|
20
|
+
export const SOLANA_DEVNET_CHAIN = "solana:devnet";
|
|
21
|
+
/** Solana Testnet cluster, e.g. https://api.testnet.solana.com */
|
|
22
|
+
export const SOLANA_TESTNET_CHAIN = "solana:testnet";
|
|
23
|
+
/** Solana Localnet cluster, e.g. http://localhost:8899 */
|
|
24
|
+
export const SOLANA_LOCALNET_CHAIN = "solana:localnet";
|
|
25
|
+
/** Array of all Solana clusters */
|
|
26
|
+
export const SOLANA_CHAINS = ["solana:mainnet", "solana:mainnet-beta"];
|
|
27
|
+
/**
|
|
28
|
+
* Check if a chain corresponds with one of the Solana clusters.
|
|
29
|
+
*/
|
|
30
|
+
export function isSolanaChain(chain) {
|
|
31
|
+
return SOLANA_CHAINS.includes(chain);
|
|
32
|
+
}
|
|
33
|
+
export function isVersionedTransaction(transaction) {
|
|
34
|
+
return "version" in transaction;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/solana/injected/utils.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,UAAU,CAAC,CAAa,EAAE,CAAa;IACrD,OAAO,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,CAAa,EAAE,CAAa;IACzD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,IAAI,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAClC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAGrC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAEnD,kEAAkE;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAErD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD,mCAAmC;AACnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,gBAAgB,EAAE,qBAAqB,CAAU,CAAC;AAKhF;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAuB;IACnD,OAAO,aAAa,CAAC,QAAQ,CAAC,KAAoB,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,WAA+C;IACpF,OAAO,SAAS,IAAI,WAAW,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Connection, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { Wallet } from "@wallet-standard/base";
|
|
3
|
+
export interface ISolanaProtocolWallet {
|
|
4
|
+
address: string;
|
|
5
|
+
sendTransaction?: (transaction: Transaction | VersionedTransaction, connection: Connection, options?: any) => Promise<string>;
|
|
6
|
+
signMessage?: (message: string) => Promise<Uint8Array>;
|
|
7
|
+
disconnect?: (data?: {
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
declare class SolanaProtocolWallet implements ISolanaProtocolWallet {
|
|
12
|
+
readonly wallet: Wallet;
|
|
13
|
+
readonly address: string;
|
|
14
|
+
constructor(wallet: Wallet, address: string);
|
|
15
|
+
static connect(wallet: Wallet, { silent }?: {
|
|
16
|
+
silent?: boolean;
|
|
17
|
+
}): Promise<ISolanaProtocolWallet>;
|
|
18
|
+
getAccount({ silent }?: {
|
|
19
|
+
silent?: boolean;
|
|
20
|
+
}): Promise<import("@wallet-standard/base").WalletAccount>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
sendTransaction(transaction: Transaction | VersionedTransaction, connection: Connection, options?: any): Promise<string>;
|
|
23
|
+
signMessage(message: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
24
|
+
}
|
|
25
|
+
export default SolanaProtocolWallet;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class SolanaProtocolWallet {
|
|
2
|
+
wallet;
|
|
3
|
+
address;
|
|
4
|
+
constructor(wallet, address) {
|
|
5
|
+
this.wallet = wallet;
|
|
6
|
+
this.address = address;
|
|
7
|
+
}
|
|
8
|
+
static async connect(wallet, { silent = false } = {}) {
|
|
9
|
+
const a = new SolanaProtocolWallet(wallet, "");
|
|
10
|
+
const account = await a.getAccount({ silent });
|
|
11
|
+
return new SolanaProtocolWallet(wallet, account.address);
|
|
12
|
+
}
|
|
13
|
+
async getAccount({ silent = false } = {}) {
|
|
14
|
+
let accounts = this.wallet.accounts || [];
|
|
15
|
+
if (!accounts.length) {
|
|
16
|
+
const connect = this.wallet.features["standard:connect"]?.connect;
|
|
17
|
+
if (!connect)
|
|
18
|
+
throw new Error("Wallet does not support standard:connect");
|
|
19
|
+
const { accounts: connectedAccounts } = await connect({ silent });
|
|
20
|
+
accounts = connectedAccounts || [];
|
|
21
|
+
}
|
|
22
|
+
if (!accounts.length)
|
|
23
|
+
throw new Error("No account found");
|
|
24
|
+
return accounts[0];
|
|
25
|
+
}
|
|
26
|
+
async disconnect() {
|
|
27
|
+
const disconnect = this.wallet.features["standard:disconnect"]?.disconnect;
|
|
28
|
+
if (disconnect)
|
|
29
|
+
await disconnect();
|
|
30
|
+
}
|
|
31
|
+
async sendTransaction(transaction, connection, options) {
|
|
32
|
+
const account = await this.getAccount();
|
|
33
|
+
const features = this.wallet.features;
|
|
34
|
+
const signTx = features["solana:signTransaction"]?.signTransaction;
|
|
35
|
+
const [signed] = await signTx({ account, chain: account.chains[0], transaction: transaction.serialize() });
|
|
36
|
+
const signedTx = signed.signedTransaction;
|
|
37
|
+
const raw = signedTx instanceof Uint8Array ? signedTx : signedTx.serialize();
|
|
38
|
+
const sig = await connection.sendRawTransaction(raw, options);
|
|
39
|
+
return sig;
|
|
40
|
+
}
|
|
41
|
+
async signMessage(message) {
|
|
42
|
+
const account = await this.getAccount();
|
|
43
|
+
const features = this.wallet.features;
|
|
44
|
+
const signMessageFeature = features["solana:signMessage"]?.signMessage;
|
|
45
|
+
if (!signMessageFeature)
|
|
46
|
+
throw new Error("Wallet does not support solana:signMessage");
|
|
47
|
+
const [result] = await signMessageFeature({ account, message: new TextEncoder().encode(message) });
|
|
48
|
+
if (result.signature)
|
|
49
|
+
return result.signature;
|
|
50
|
+
if (Array.isArray(result) && result[0]?.signature)
|
|
51
|
+
return result[0].signature;
|
|
52
|
+
throw new Error("Unexpected signMessage result");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default SolanaProtocolWallet;
|
|
56
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/solana/protocol.ts"],"names":[],"mappings":"AAYA,MAAM,oBAAoB;IACH;IAAyB;IAA9C,YAAqB,MAAc,EAAW,OAAe;QAAxC,WAAM,GAAN,MAAM,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEjE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,EAAE,MAAM,GAAG,KAAK,KAA2B,EAAE;QAChF,MAAM,CAAC,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,KAA2B,EAAE;QAC5D,IAAI,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;QAE1C,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACrB,MAAM,OAAO,GAAI,IAAI,CAAC,MAAM,CAAC,QAAgB,CAAC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U,CAAC,kBAAkB,CAAC,GAAiB,EAAE,OAAc,CAAC,CAAC;QACnF,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAe,CAAC;QAC7C,MAAM,kBAAkB,GAAG,QAAQ,CAAC,oBAAoB,CAAC,EAAE,WAAsC,CAAC;QAElG,IAAI,CAAC,kBAAkB;YAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QACvF,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAEnG,IAAI,MAAM,CAAC,SAAS;YAAE,OAAO,MAAM,CAAC,SAAS,CAAC;QAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS;YAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,SAAuB,CAAC;QAC5F,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;CACF;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { WalletType } from "../core/chains";
|
|
3
|
+
import { OmniConnector } from "../OmniConnector";
|
|
4
|
+
import { OmniWallet } from "../OmniWallet";
|
|
5
|
+
import { Token } from "../core/token";
|
|
6
|
+
import { ReviewFee } from "../core/bridge";
|
|
7
|
+
import { Commitment } from "../core";
|
|
8
|
+
import { ISolanaProtocolWallet } from "./protocol";
|
|
9
|
+
declare class SolanaWallet extends OmniWallet {
|
|
10
|
+
readonly connector: OmniConnector;
|
|
11
|
+
readonly wallet: ISolanaProtocolWallet;
|
|
12
|
+
readonly type = WalletType.SOLANA;
|
|
13
|
+
constructor(connector: OmniConnector, wallet: ISolanaProtocolWallet);
|
|
14
|
+
getConnection(): Connection;
|
|
15
|
+
get address(): string;
|
|
16
|
+
get publicKey(): string;
|
|
17
|
+
get omniAddress(): string;
|
|
18
|
+
fetchBalance(_: number, address: string): Promise<bigint>;
|
|
19
|
+
disconnect(): Promise<void>;
|
|
20
|
+
buildTranferInstructions(token: Token, amount: bigint, receiver: string, fee?: ReviewFee): Promise<{
|
|
21
|
+
reserve: number;
|
|
22
|
+
additionalFee: bigint;
|
|
23
|
+
instructions: TransactionInstruction[];
|
|
24
|
+
}>;
|
|
25
|
+
transferFee(token: Token, receiver: string): Promise<ReviewFee>;
|
|
26
|
+
getPriorityFeeEstimate(params: any): Promise<any>;
|
|
27
|
+
transfer(args: {
|
|
28
|
+
token: Token;
|
|
29
|
+
receiver: string;
|
|
30
|
+
amount: bigint;
|
|
31
|
+
comment?: string;
|
|
32
|
+
gasFee?: ReviewFee;
|
|
33
|
+
}): Promise<string>;
|
|
34
|
+
sendTransaction(instructions: TransactionInstruction[]): Promise<string>;
|
|
35
|
+
fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>>;
|
|
36
|
+
signMessage(message: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
37
|
+
signIntents(intents: Record<string, any>[], options?: {
|
|
38
|
+
deadline?: number;
|
|
39
|
+
nonce?: Uint8Array;
|
|
40
|
+
}): Promise<Commitment>;
|
|
41
|
+
}
|
|
42
|
+
export default SolanaWallet;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Connection, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { ComputeBudgetProgram, PublicKey, SystemProgram, TransactionMessage } from "@solana/web3.js";
|
|
3
|
+
import { base64, base58, hex } from "@scure/base";
|
|
4
|
+
import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getMinimumBalanceForRentExemptAccount, createAssociatedTokenAccountInstruction, createTransferInstruction, getAccount, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, createTransferCheckedInstruction, } from "@solana/spl-token";
|
|
5
|
+
import { Network, WalletType } from "../core/chains";
|
|
6
|
+
import { OmniWallet } from "../OmniWallet";
|
|
7
|
+
import { formatter } from "../core/utils";
|
|
8
|
+
import { ReviewFee } from "../core/bridge";
|
|
9
|
+
import { api } from "../core/api";
|
|
10
|
+
class SolanaWallet extends OmniWallet {
|
|
11
|
+
connector;
|
|
12
|
+
wallet;
|
|
13
|
+
type = WalletType.SOLANA;
|
|
14
|
+
constructor(connector, wallet) {
|
|
15
|
+
super(connector);
|
|
16
|
+
this.connector = connector;
|
|
17
|
+
this.wallet = wallet;
|
|
18
|
+
}
|
|
19
|
+
getConnection() {
|
|
20
|
+
return new Connection(api.getRpcUrl(Network.Solana), {
|
|
21
|
+
httpHeaders: { "Api-Key": api.apiKey },
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
get address() {
|
|
25
|
+
return this.wallet.address;
|
|
26
|
+
}
|
|
27
|
+
get publicKey() {
|
|
28
|
+
return this.wallet.address;
|
|
29
|
+
}
|
|
30
|
+
get omniAddress() {
|
|
31
|
+
return hex.encode(base58.decode(this.address)).toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
async fetchBalance(_, address) {
|
|
34
|
+
const connection = this.getConnection();
|
|
35
|
+
if (address === "native") {
|
|
36
|
+
const balance = await connection.getBalance(new PublicKey(this.address));
|
|
37
|
+
return BigInt(balance);
|
|
38
|
+
}
|
|
39
|
+
const ATA = getAssociatedTokenAddressSync(new PublicKey(address), new PublicKey(this.address));
|
|
40
|
+
const meta = await connection.getTokenAccountBalance(ATA);
|
|
41
|
+
return BigInt(meta.value.amount);
|
|
42
|
+
}
|
|
43
|
+
async disconnect() {
|
|
44
|
+
await this.wallet.disconnect?.();
|
|
45
|
+
super.disconnect();
|
|
46
|
+
}
|
|
47
|
+
async buildTranferInstructions(token, amount, receiver, fee) {
|
|
48
|
+
const destination = new PublicKey(receiver);
|
|
49
|
+
const owner = new PublicKey(this.address);
|
|
50
|
+
const connection = this.getConnection();
|
|
51
|
+
const reserve = await connection.getMinimumBalanceForRentExemption(0);
|
|
52
|
+
let additionalFee = 0n;
|
|
53
|
+
if (token.address === "native") {
|
|
54
|
+
return {
|
|
55
|
+
reserve,
|
|
56
|
+
additionalFee,
|
|
57
|
+
instructions: [
|
|
58
|
+
fee ? ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.priorityFee) }) : undefined,
|
|
59
|
+
fee ? ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) }) : undefined,
|
|
60
|
+
SystemProgram.transfer({ fromPubkey: owner, toPubkey: destination, lamports: amount }),
|
|
61
|
+
].filter(Boolean),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const mint = new PublicKey(token.address);
|
|
65
|
+
const mintAccount = await connection.getAccountInfo(mint);
|
|
66
|
+
const tokenProgramId = mintAccount?.owner.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
|
|
67
|
+
const tokenFrom = getAssociatedTokenAddressSync(mint, owner, false, tokenProgramId);
|
|
68
|
+
const tokenTo = getAssociatedTokenAddressSync(mint, destination, false, tokenProgramId);
|
|
69
|
+
const instructions = [];
|
|
70
|
+
if (fee) {
|
|
71
|
+
instructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.baseFee) }));
|
|
72
|
+
instructions.push(ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) }));
|
|
73
|
+
}
|
|
74
|
+
const isRegistered = await getAccount(connection, tokenTo, "confirmed", tokenProgramId).catch(() => null);
|
|
75
|
+
if (isRegistered == null) {
|
|
76
|
+
const inst = createAssociatedTokenAccountInstruction(new PublicKey(this.address), tokenTo, destination, mint, tokenProgramId, ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
77
|
+
instructions.push(inst);
|
|
78
|
+
additionalFee += BigInt(await getMinimumBalanceForRentExemptAccount(connection));
|
|
79
|
+
}
|
|
80
|
+
if (tokenProgramId === TOKEN_2022_PROGRAM_ID) {
|
|
81
|
+
instructions.push(createTransferCheckedInstruction(tokenFrom, mint, tokenTo, owner, amount, token.decimals, [], tokenProgramId));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
instructions.push(createTransferInstruction(tokenFrom, tokenTo, owner, amount, [], tokenProgramId));
|
|
85
|
+
}
|
|
86
|
+
return { instructions, additionalFee, reserve };
|
|
87
|
+
}
|
|
88
|
+
async transferFee(token, receiver) {
|
|
89
|
+
const connection = this.getConnection();
|
|
90
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
91
|
+
const fee = new ReviewFee({ chain: Network.Solana, gasLimit: 1400000n, baseFee: 100n });
|
|
92
|
+
const { instructions, additionalFee, reserve } = await this.buildTranferInstructions(token, 1n, receiver, fee);
|
|
93
|
+
const msgForEstimate = new TransactionMessage({ payerKey: new PublicKey(this.address), recentBlockhash: blockhash, instructions }).compileToV0Message();
|
|
94
|
+
const tx = new VersionedTransaction(msgForEstimate);
|
|
95
|
+
const priorityFeeData = await this.getPriorityFeeEstimate({
|
|
96
|
+
options: { includeAllPriorityFeeLevels: true },
|
|
97
|
+
transaction: base58.encode(tx.serialize()),
|
|
98
|
+
});
|
|
99
|
+
if (priorityFeeData?.priorityFeeLevels == null)
|
|
100
|
+
throw "Failed to fetch gas";
|
|
101
|
+
const simulate = await connection.simulateTransaction(tx).catch(() => null);
|
|
102
|
+
const unitsConsumed = formatter.bigIntMax(BigInt(simulate?.value.unitsConsumed || 10000n), 10000n);
|
|
103
|
+
const msgFee = await connection.getFeeForMessage(msgForEstimate);
|
|
104
|
+
const medium = BigInt(priorityFeeData.priorityFeeLevels.medium);
|
|
105
|
+
const high = BigInt(priorityFeeData.priorityFeeLevels.high);
|
|
106
|
+
const veryHigh = BigInt(priorityFeeData.priorityFeeLevels.veryHigh);
|
|
107
|
+
const baseFee = BigInt(msgFee.value || 0);
|
|
108
|
+
return new ReviewFee({
|
|
109
|
+
chain: Network.Solana,
|
|
110
|
+
reserve: BigInt(reserve) + additionalFee,
|
|
111
|
+
gasLimit: unitsConsumed,
|
|
112
|
+
baseFee,
|
|
113
|
+
priorityFee: medium,
|
|
114
|
+
options: [
|
|
115
|
+
{ priorityFee: medium, baseFee },
|
|
116
|
+
{ priorityFee: high, baseFee },
|
|
117
|
+
{ priorityFee: veryHigh, baseFee },
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async getPriorityFeeEstimate(params) {
|
|
122
|
+
const response = await fetch("https://api0.herewallet.app/api/v1/evm/helius/staked", {
|
|
123
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: "helius-sdk", method: "getPriorityFeeEstimate", params: [params] }),
|
|
124
|
+
headers: { "Content-Type": "application/json" },
|
|
125
|
+
method: "POST",
|
|
126
|
+
});
|
|
127
|
+
if (!response.ok)
|
|
128
|
+
throw "Server error";
|
|
129
|
+
const { result, error } = await response.json();
|
|
130
|
+
if (error)
|
|
131
|
+
throw error.message;
|
|
132
|
+
if (result.error)
|
|
133
|
+
throw result.error.message;
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
async transfer(args) {
|
|
137
|
+
const { instructions } = await this.buildTranferInstructions(args.token, args.amount, args.receiver, args.gasFee);
|
|
138
|
+
return await this.sendTransaction(instructions);
|
|
139
|
+
}
|
|
140
|
+
async sendTransaction(instructions) {
|
|
141
|
+
if (!this.wallet.sendTransaction)
|
|
142
|
+
throw "not impl";
|
|
143
|
+
const connection = this.getConnection();
|
|
144
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
145
|
+
const message = new TransactionMessage({ payerKey: new PublicKey(this.address), recentBlockhash: blockhash, instructions });
|
|
146
|
+
const transaction = new VersionedTransaction(message.compileToV0Message());
|
|
147
|
+
return await this.wallet.sendTransaction(transaction, connection, { preflightCommitment: "confirmed" });
|
|
148
|
+
}
|
|
149
|
+
async fetchBalances(chain, whitelist) {
|
|
150
|
+
const native = await this.fetchBalance(chain, "native");
|
|
151
|
+
const connection = this.getConnection();
|
|
152
|
+
try {
|
|
153
|
+
const res = await fetch(`https://api0.herewallet.app/api/v1/user/balances/${chain}/${this.address}`, { body: JSON.stringify({ whitelist }), method: "POST" });
|
|
154
|
+
const { balances } = await res.json();
|
|
155
|
+
return { ...balances, native };
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
const tokenAccounts = await connection.getParsedTokenAccountsByOwner(new PublicKey(this.address), { programId: TOKEN_PROGRAM_ID });
|
|
159
|
+
const balances = Object.fromEntries(tokenAccounts.value.map((account) => {
|
|
160
|
+
const { mint, tokenAmount } = account.account.data.parsed.info;
|
|
161
|
+
return [mint, tokenAmount.amount];
|
|
162
|
+
}));
|
|
163
|
+
return { ...balances, native };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async signMessage(message) {
|
|
167
|
+
if (!this.wallet.signMessage)
|
|
168
|
+
throw "not impl";
|
|
169
|
+
return this.wallet.signMessage(message);
|
|
170
|
+
}
|
|
171
|
+
async signIntents(intents, options) {
|
|
172
|
+
const nonce = new Uint8Array(options?.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
|
|
173
|
+
const message = JSON.stringify({
|
|
174
|
+
deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
|
|
175
|
+
nonce: base64.encode(nonce),
|
|
176
|
+
verifying_contract: "intents.near",
|
|
177
|
+
signer_id: this.omniAddress,
|
|
178
|
+
intents: intents,
|
|
179
|
+
});
|
|
180
|
+
const signature = await this.signMessage(message);
|
|
181
|
+
return {
|
|
182
|
+
signature: `ed25519:${base58.encode(signature)}`,
|
|
183
|
+
public_key: `ed25519:${this.publicKey}`,
|
|
184
|
+
standard: "raw_ed25519",
|
|
185
|
+
payload: message,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export default SolanaWallet;
|
|
190
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/solana/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,qCAAqC,EACrC,uCAAuC,EACvC,yBAAyB,EACzB,UAAU,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,gCAAgC,GACjC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAIlC,MAAM,YAAa,SAAQ,UAAU;IAGd;IAAmC;IAF/C,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC;IAElC,YAAqB,SAAwB,EAAW,MAA6B;QACnF,KAAK,CAAC,SAAS,CAAC,CAAC;QADE,cAAS,GAAT,SAAS,CAAe;QAAW,WAAM,GAAN,MAAM,CAAuB;IAErF,CAAC;IAED,aAAa;QACX,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACnD,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,M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CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAA8B,EAAE,OAAmD;QACnG,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAElG,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7B,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,0BAA0B;YACnG,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,kBAAkB,EAAE,cAAc;YAClC,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO;YACL,SAAS,EAAE,WAAW,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YAChD,UAAU,EAAE,WAAW,IAAI,CAAC,SAAS,EAAE;YACvC,QAAQ,EAAE,aAAa;YACvB,OAAO,EAAE,OAAO;SACjB,CAAC;IACJ,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Wallet } from "@wallet-standard/base";
|
|
2
|
+
/**
|
|
3
|
+
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
|
|
4
|
+
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
|
|
5
|
+
*
|
|
6
|
+
* When called for the first time --
|
|
7
|
+
*
|
|
8
|
+
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
|
|
9
|
+
* to register it.
|
|
10
|
+
*
|
|
11
|
+
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
|
|
12
|
+
* from each Wallet that the Wallet is ready to be registered by the app.
|
|
13
|
+
*
|
|
14
|
+
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
|
|
15
|
+
* as the app is ready whether the app loads before or after each Wallet.
|
|
16
|
+
*
|
|
17
|
+
* @return API for getting, listening for, and registering Wallets.
|
|
18
|
+
*
|
|
19
|
+
* @group App
|
|
20
|
+
*/
|
|
21
|
+
export declare function getWallets(): Wallets;
|
|
22
|
+
/**
|
|
23
|
+
* API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
|
|
24
|
+
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
|
|
25
|
+
*
|
|
26
|
+
* @group App
|
|
27
|
+
*/
|
|
28
|
+
export interface Wallets {
|
|
29
|
+
/**
|
|
30
|
+
* Get all Wallets that have been registered.
|
|
31
|
+
*
|
|
32
|
+
* @return Registered Wallets.
|
|
33
|
+
*/
|
|
34
|
+
get(): readonly (Wallet & {
|
|
35
|
+
url?: string;
|
|
36
|
+
})[];
|
|
37
|
+
/**
|
|
38
|
+
* Add an event listener and subscribe to events for Wallets that are
|
|
39
|
+
* {@link WalletsEventsListeners.register | registered} and
|
|
40
|
+
* {@link WalletsEventsListeners.unregister | unregistered}.
|
|
41
|
+
*
|
|
42
|
+
* @param event Event type to listen for. {@link WalletsEventsListeners.register | `register`} and
|
|
43
|
+
* {@link WalletsEventsListeners.unregister | `unregister`} are the only event types.
|
|
44
|
+
* @param listener Function that will be called when an event of the type is emitted.
|
|
45
|
+
*
|
|
46
|
+
* @return
|
|
47
|
+
* `off` function which may be called to remove the event listener and unsubscribe from events.
|
|
48
|
+
*
|
|
49
|
+
* As with all event listeners, be careful to avoid memory leaks.
|
|
50
|
+
*/
|
|
51
|
+
on<E extends WalletsEventNames>(event: E, listener: WalletsEventsListeners[E]): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Register Wallets. This can be used to programmatically wrap non-standard wallets as Standard Wallets.
|
|
54
|
+
*
|
|
55
|
+
* Apps generally do not need to, and should not, call this.
|
|
56
|
+
*
|
|
57
|
+
* @param wallets Wallets to register.
|
|
58
|
+
*
|
|
59
|
+
* @return
|
|
60
|
+
* `unregister` function which may be called to programmatically unregister the registered Wallets.
|
|
61
|
+
*
|
|
62
|
+
* Apps generally do not need to, and should not, call this.
|
|
63
|
+
*/
|
|
64
|
+
register(...wallets: Wallet[]): () => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Types of event listeners of the {@link Wallets} API.
|
|
68
|
+
*
|
|
69
|
+
* @group App
|
|
70
|
+
*/
|
|
71
|
+
export interface WalletsEventsListeners {
|
|
72
|
+
/**
|
|
73
|
+
* Emitted when Wallets are registered.
|
|
74
|
+
*
|
|
75
|
+
* @param wallets Wallets that were registered.
|
|
76
|
+
*/
|
|
77
|
+
register(...wallets: Wallet[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* Emitted when Wallets are unregistered.
|
|
80
|
+
*
|
|
81
|
+
* @param wallets Wallets that were unregistered.
|
|
82
|
+
*/
|
|
83
|
+
unregister(...wallets: Wallet[]): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Names of {@link WalletsEventsListeners} that can be listened for.
|
|
87
|
+
*
|
|
88
|
+
* @group App
|
|
89
|
+
*/
|
|
90
|
+
export type WalletsEventNames = keyof WalletsEventsListeners;
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated Use {@link WalletsEventsListeners} instead.
|
|
93
|
+
*
|
|
94
|
+
* @group Deprecated
|
|
95
|
+
*/
|
|
96
|
+
export type WalletsEvents = WalletsEventsListeners;
|
|
97
|
+
/**
|
|
98
|
+
* @deprecated Use {@link getWallets} instead.
|
|
99
|
+
*
|
|
100
|
+
* @group Deprecated
|
|
101
|
+
*/
|
|
102
|
+
export declare function DEPRECATED_getWallets(): Wallets;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
let wallets = undefined;
|
|
2
|
+
const registeredWalletsSet = new Set();
|
|
3
|
+
function addRegisteredWallet(wallet) {
|
|
4
|
+
cachedWalletsArray = undefined;
|
|
5
|
+
registeredWalletsSet.add(wallet);
|
|
6
|
+
}
|
|
7
|
+
function removeRegisteredWallet(wallet) {
|
|
8
|
+
cachedWalletsArray = undefined;
|
|
9
|
+
registeredWalletsSet.delete(wallet);
|
|
10
|
+
}
|
|
11
|
+
const listeners = {};
|
|
12
|
+
/**
|
|
13
|
+
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
|
|
14
|
+
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
|
|
15
|
+
*
|
|
16
|
+
* When called for the first time --
|
|
17
|
+
*
|
|
18
|
+
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
|
|
19
|
+
* to register it.
|
|
20
|
+
*
|
|
21
|
+
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
|
|
22
|
+
* from each Wallet that the Wallet is ready to be registered by the app.
|
|
23
|
+
*
|
|
24
|
+
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
|
|
25
|
+
* as the app is ready whether the app loads before or after each Wallet.
|
|
26
|
+
*
|
|
27
|
+
* @return API for getting, listening for, and registering Wallets.
|
|
28
|
+
*
|
|
29
|
+
* @group App
|
|
30
|
+
*/
|
|
31
|
+
export function getWallets() {
|
|
32
|
+
if (wallets)
|
|
33
|
+
return wallets;
|
|
34
|
+
wallets = Object.freeze({ register, get, on });
|
|
35
|
+
if (typeof window === "undefined")
|
|
36
|
+
return wallets;
|
|
37
|
+
const api = Object.freeze({ register });
|
|
38
|
+
try {
|
|
39
|
+
window.addEventListener("wallet-standard:register-wallet", ({ detail: callback }) => callback(api));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error("wallet-standard:register-wallet event listener could not be added\n", error);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
window.dispatchEvent(new AppReadyEvent(api));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("wallet-standard:app-ready event could not be dispatched\n", error);
|
|
49
|
+
}
|
|
50
|
+
return wallets;
|
|
51
|
+
}
|
|
52
|
+
function register(...wallets) {
|
|
53
|
+
// Filter out wallets that have already been registered.
|
|
54
|
+
// This prevents the same wallet from being registered twice, but it also prevents wallets from being
|
|
55
|
+
// unregistered by reusing a reference to the wallet to obtain the unregister function for it.
|
|
56
|
+
wallets = wallets.filter((wallet) => !registeredWalletsSet.has(wallet));
|
|
57
|
+
// If there are no new wallets to register, just return a no-op unregister function.
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
59
|
+
if (!wallets.length)
|
|
60
|
+
return () => { };
|
|
61
|
+
wallets.forEach((wallet) => addRegisteredWallet(wallet));
|
|
62
|
+
listeners["register"]?.forEach((listener) => guard(() => listener(...wallets)));
|
|
63
|
+
// Return a function that unregisters the registered wallets.
|
|
64
|
+
return function unregister() {
|
|
65
|
+
wallets.forEach((wallet) => removeRegisteredWallet(wallet));
|
|
66
|
+
listeners["unregister"]?.forEach((listener) => guard(() => listener(...wallets)));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
let cachedWalletsArray;
|
|
70
|
+
function get() {
|
|
71
|
+
if (!cachedWalletsArray) {
|
|
72
|
+
cachedWalletsArray = [...registeredWalletsSet];
|
|
73
|
+
}
|
|
74
|
+
return cachedWalletsArray;
|
|
75
|
+
}
|
|
76
|
+
function on(event, listener) {
|
|
77
|
+
listeners[event]?.push(listener) || (listeners[event] = [listener]);
|
|
78
|
+
// Return a function that removes the event listener.
|
|
79
|
+
return function off() {
|
|
80
|
+
listeners[event] = listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function guard(callback) {
|
|
84
|
+
try {
|
|
85
|
+
callback();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class AppReadyEvent extends Event {
|
|
92
|
+
#detail;
|
|
93
|
+
get detail() {
|
|
94
|
+
return this.#detail;
|
|
95
|
+
}
|
|
96
|
+
get type() {
|
|
97
|
+
return "wallet-standard:app-ready";
|
|
98
|
+
}
|
|
99
|
+
constructor(api) {
|
|
100
|
+
super("wallet-standard:app-ready", {
|
|
101
|
+
bubbles: false,
|
|
102
|
+
cancelable: false,
|
|
103
|
+
composed: false,
|
|
104
|
+
});
|
|
105
|
+
this.#detail = api;
|
|
106
|
+
}
|
|
107
|
+
/** @deprecated */
|
|
108
|
+
preventDefault() {
|
|
109
|
+
throw new Error("preventDefault cannot be called");
|
|
110
|
+
}
|
|
111
|
+
/** @deprecated */
|
|
112
|
+
stopImmediatePropagation() {
|
|
113
|
+
throw new Error("stopImmediatePropagation cannot be called");
|
|
114
|
+
}
|
|
115
|
+
/** @deprecated */
|
|
116
|
+
stopPropagation() {
|
|
117
|
+
throw new Error("stopPropagation cannot be called");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated Use {@link getWallets} instead.
|
|
122
|
+
*
|
|
123
|
+
* @group Deprecated
|
|
124
|
+
*/
|
|
125
|
+
export function DEPRECATED_getWallets() {
|
|
126
|
+
if (wallets)
|
|
127
|
+
return wallets;
|
|
128
|
+
wallets = getWallets();
|
|
129
|
+
if (typeof window === "undefined")
|
|
130
|
+
return wallets;
|
|
131
|
+
const callbacks = window.navigator.wallets || [];
|
|
132
|
+
if (!Array.isArray(callbacks)) {
|
|
133
|
+
console.error("window.navigator.wallets is not an array");
|
|
134
|
+
return wallets;
|
|
135
|
+
}
|
|
136
|
+
const { register } = wallets;
|
|
137
|
+
const push = (...callbacks) => callbacks.forEach((callback) => guard(() => callback({ register })));
|
|
138
|
+
try {
|
|
139
|
+
Object.defineProperty(window.navigator, "wallets", {
|
|
140
|
+
value: Object.freeze({ push }),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error("window.navigator.wallets could not be set");
|
|
145
|
+
return wallets;
|
|
146
|
+
}
|
|
147
|
+
push(...callbacks);
|
|
148
|
+
return wallets;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=wallets.js.map
|