@swapkit/wallets 3.0.0-beta.22 → 3.0.0-beta.24
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/{chunk-x5hgx9x9.js → chunk-0qaxr89s.js} +2 -2
- package/dist/{chunk-x5hgx9x9.js.map → chunk-0qaxr89s.js.map} +1 -1
- package/dist/chunk-bexr8da2.js +4 -0
- package/dist/chunk-bexr8da2.js.map +10 -0
- package/dist/chunk-dcj9twam.js +3 -0
- package/dist/chunk-dcj9twam.js.map +10 -0
- package/dist/{chunk-38ztynv0.js → chunk-qwd1kp32.js} +2 -2
- package/dist/{chunk-38ztynv0.js.map → chunk-qwd1kp32.js.map} +1 -1
- package/dist/chunk-sn6pgje5.js +3 -0
- package/dist/chunk-sn6pgje5.js.map +10 -0
- package/dist/chunk-wfattb4a.js +3 -0
- package/dist/chunk-wfattb4a.js.map +10 -0
- package/dist/{chunk-ebfkk1jn.js → chunk-zfnkndsr.js} +3 -3
- package/dist/{chunk-ebfkk1jn.js.map → chunk-zfnkndsr.js.map} +1 -1
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +1 -1
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +1 -1
- package/dist/src/cosmostation/index.js +2 -2
- package/dist/src/cosmostation/index.js.map +1 -1
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +4 -4
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +4 -4
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +1 -1
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +1 -1
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +1 -1
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +1 -1
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +3 -3
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +3 -3
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +7 -6
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +7 -6
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +4 -4
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +4 -4
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +1 -1
- package/dist/src/phantom/index.js +2 -2
- package/dist/src/phantom/index.js.map +2 -2
- package/dist/src/polkadotjs/index.js +2 -2
- package/dist/src/polkadotjs/index.js.map +1 -1
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +1 -1
- package/dist/src/talisman/index.js +2 -2
- package/dist/src/talisman/index.js.map +1 -1
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +1 -1
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +5 -6
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +5 -6
- package/package.json +5 -3
- package/src/ctrl/index.ts +83 -0
- package/src/ctrl/walletHelpers.ts +16 -0
- package/src/helpers/near-browser-provider.d.ts +286 -0
- package/src/helpers/near.ts +206 -0
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/near.ts +86 -0
- package/src/ledger/helpers/getLedgerAddress.ts +5 -0
- package/src/ledger/helpers/getLedgerClient.ts +7 -0
- package/src/ledger/index.ts +10 -0
- package/src/okx/helpers.ts +16 -0
- package/src/okx/index.ts +1 -0
- package/src/types.ts +11 -0
- package/src/walletconnect/constants.ts +2 -0
- package/src/walletconnect/helpers.ts +9 -2
- package/src/walletconnect/index.ts +68 -0
- /package/dist/{chunk-k9q04afa.js → chunk-ad832c7c.js} +0 -0
- /package/dist/{chunk-k9q04afa.js.map → chunk-ad832c7c.js.map} +0 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
//TBD @towan to be moved somewhere else
|
|
2
|
+
import { SwapKitError } from "@swapkit/helpers";
|
|
3
|
+
import type { NearSigner } from "@swapkit/toolboxes/near";
|
|
4
|
+
import type { Account } from "near-api-js";
|
|
5
|
+
import {
|
|
6
|
+
type Action,
|
|
7
|
+
type Signature,
|
|
8
|
+
SignedTransaction,
|
|
9
|
+
type Transaction,
|
|
10
|
+
} from "near-api-js/lib/transaction";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* NEAR Browser Wallet Provider Interface
|
|
14
|
+
* Common interface implemented by browser extension wallets
|
|
15
|
+
*/
|
|
16
|
+
export interface NearBrowserWalletProvider {
|
|
17
|
+
// Connection methods
|
|
18
|
+
connect(params?: { contractId?: string; methodNames?: string[] }): Promise<
|
|
19
|
+
Account[] | { accountId: string }
|
|
20
|
+
>;
|
|
21
|
+
disconnect?(): Promise<void>;
|
|
22
|
+
signOut?(): Promise<void>; // Alternative to disconnect
|
|
23
|
+
|
|
24
|
+
// Account methods
|
|
25
|
+
getAccountId(): string | Promise<string>;
|
|
26
|
+
getAccounts?(): Promise<Account[]>;
|
|
27
|
+
isSignedIn(): boolean;
|
|
28
|
+
getPublicKey?(): Promise<string>;
|
|
29
|
+
|
|
30
|
+
// Signing methods
|
|
31
|
+
signMessage?(params: any): Promise<any>;
|
|
32
|
+
signAndSendTransaction(params: {
|
|
33
|
+
receiverId: string;
|
|
34
|
+
actions: Action[];
|
|
35
|
+
signerId?: string;
|
|
36
|
+
}): Promise<any>;
|
|
37
|
+
signAndSendTransactions?(params: {
|
|
38
|
+
transactions: Transaction[];
|
|
39
|
+
}): Promise<any[]>;
|
|
40
|
+
|
|
41
|
+
// Optional utility methods
|
|
42
|
+
request<T>(params: { method: string; params?: any }): Promise<T>;
|
|
43
|
+
verifyOwner?(params: {
|
|
44
|
+
message: string;
|
|
45
|
+
callbackUrl?: string;
|
|
46
|
+
}): Promise<any>;
|
|
47
|
+
getNetwork?(): Promise<{ networkId: string; nodeUrl: string }>;
|
|
48
|
+
|
|
49
|
+
// Event handlers (optional)
|
|
50
|
+
on?(event: string, handler: Function): void;
|
|
51
|
+
off?(event: string, handler: Function): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Helper to create a NEAR signer from browser extension providers
|
|
56
|
+
*/
|
|
57
|
+
export async function createNearSignerFromProvider(
|
|
58
|
+
provider: NearBrowserWalletProvider,
|
|
59
|
+
walletName: string,
|
|
60
|
+
) {
|
|
61
|
+
const isConnected = provider.isSignedIn ? provider.isSignedIn() : false;
|
|
62
|
+
if (!isConnected) {
|
|
63
|
+
await provider.connect({ contractId: "", methodNames: [] });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const signer = {
|
|
67
|
+
...provider,
|
|
68
|
+
async getPublicKey() {
|
|
69
|
+
// Most browser wallets expose public key through message signing
|
|
70
|
+
const { utils } = await import("near-api-js");
|
|
71
|
+
|
|
72
|
+
if (provider.getPublicKey) {
|
|
73
|
+
const pubKey = await provider.getPublicKey();
|
|
74
|
+
return utils.PublicKey.from(pubKey);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!provider.signMessage) {
|
|
78
|
+
throw new SwapKitError("wallet_ledger_method_not_supported", {
|
|
79
|
+
wallet: walletName,
|
|
80
|
+
method: "getPublicKey",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Most browser wallets don't expose public key directly
|
|
85
|
+
// Return a dummy public key
|
|
86
|
+
const { PublicKey } = await import("near-api-js/lib/utils");
|
|
87
|
+
// Create a dummy ed25519 public key
|
|
88
|
+
const dummyKeyData = Buffer.alloc(32);
|
|
89
|
+
const dummyKey = `ed25519:${Buffer.from(dummyKeyData).toString("base64")}`;
|
|
90
|
+
return PublicKey.from(dummyKey);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
async signNep413Message(
|
|
94
|
+
message: string,
|
|
95
|
+
_accountId: string,
|
|
96
|
+
recipient: string,
|
|
97
|
+
nonce: Uint8Array,
|
|
98
|
+
callbackUrl?: string,
|
|
99
|
+
) {
|
|
100
|
+
if (!provider.signMessage) {
|
|
101
|
+
throw new SwapKitError("wallet_ledger_method_not_supported", {
|
|
102
|
+
wallet: walletName,
|
|
103
|
+
method: "signNep413Message",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// We know signMessage exists because we checked above
|
|
108
|
+
const result = await (
|
|
109
|
+
provider as Required<Pick<NearBrowserWalletProvider, "signMessage">>
|
|
110
|
+
).signMessage({
|
|
111
|
+
message,
|
|
112
|
+
recipient,
|
|
113
|
+
nonce: Buffer.from(nonce),
|
|
114
|
+
callbackUrl,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return result;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
async signTransaction(transaction: Transaction) {
|
|
121
|
+
if (!provider.request) {
|
|
122
|
+
throw new SwapKitError("wallet_near_method_not_supported", {
|
|
123
|
+
wallet: walletName,
|
|
124
|
+
method: "request",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Browser wallets typically sign and send in one operation
|
|
129
|
+
// This is a limitation of browser wallet APIs
|
|
130
|
+
const result = await provider.request<{ signatures: Signature }>({
|
|
131
|
+
method: "near_signTransactions",
|
|
132
|
+
params: {
|
|
133
|
+
transactions: [transaction], // must be Array type
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const signedTransaction = new SignedTransaction({
|
|
138
|
+
transaction,
|
|
139
|
+
signature: result.signatures,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return [result.signatures.data, signedTransaction] as [
|
|
143
|
+
Uint8Array<ArrayBufferLike>,
|
|
144
|
+
SignedTransaction,
|
|
145
|
+
];
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
signDelegateAction(_delegateAction: any) {
|
|
149
|
+
// Most browser wallets don't support delegate actions yet
|
|
150
|
+
return Promise.reject(
|
|
151
|
+
new SwapKitError("wallet_ledger_method_not_supported", {
|
|
152
|
+
wallet: walletName,
|
|
153
|
+
method: "signDelegateAction",
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
async getAddress() {
|
|
159
|
+
if (provider.getAccountId) {
|
|
160
|
+
return provider.getAccountId();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (provider.isSignedIn && !provider.isSignedIn()) {
|
|
164
|
+
// Try connect method for wallets that don't have requestSignIn
|
|
165
|
+
const result = await provider.connect();
|
|
166
|
+
if (Array.isArray(result) && result.length > 0 && result[0]) {
|
|
167
|
+
return typeof result[0] === "string" ? result[0] : result[0].accountId;
|
|
168
|
+
}
|
|
169
|
+
throw new SwapKitError("wallet_connection_rejected_by_user", {
|
|
170
|
+
wallet: walletName,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
throw new SwapKitError("wallet_connection_rejected_by_user", {
|
|
175
|
+
wallet: walletName,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return signer as NearSigner;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Detect if a wallet provider supports NEAR
|
|
185
|
+
*/
|
|
186
|
+
export function detectNearProvider(
|
|
187
|
+
window: any,
|
|
188
|
+
providerPath: string,
|
|
189
|
+
): NearBrowserWalletProvider | null {
|
|
190
|
+
const parts = providerPath.split(".");
|
|
191
|
+
let provider = window;
|
|
192
|
+
|
|
193
|
+
for (const part of parts) {
|
|
194
|
+
provider = provider?.[part];
|
|
195
|
+
if (!provider) return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return provider;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get NEAR chain ID for WalletConnect
|
|
203
|
+
*/
|
|
204
|
+
export function getNearChainId(isTestnet: boolean): string {
|
|
205
|
+
return isTestnet ? "near:testnet" : "near:mainnet";
|
|
206
|
+
}
|
package/src/keystore/index.ts
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
+
import type { DerivationPathArray } from "@swapkit/helpers";
|
|
3
|
+
import type { NearSigner } from "@swapkit/toolboxes/near";
|
|
4
|
+
import type { SignedTransaction, Transaction } from "near-api-js/lib/transaction";
|
|
5
|
+
|
|
6
|
+
export async function getNearLedgerClient(
|
|
7
|
+
transport: Transport,
|
|
8
|
+
derivationPath?: DerivationPathArray,
|
|
9
|
+
) {
|
|
10
|
+
const Near = await import("@ledgerhq/hw-app-near");
|
|
11
|
+
const { Chain, DerivationPath, derivationPathToString, SwapKitError } = await import(
|
|
12
|
+
"@swapkit/helpers"
|
|
13
|
+
);
|
|
14
|
+
const nearApp = new Near.default(transport);
|
|
15
|
+
|
|
16
|
+
// NEAR uses m/44'/397'/0'/0'/0' by default
|
|
17
|
+
const path = derivationPath ? derivationPathToString(derivationPath) : DerivationPath[Chain.Near];
|
|
18
|
+
|
|
19
|
+
// Get address and public key from Ledger
|
|
20
|
+
const { address, publicKey: pubKeyHex } = await nearApp.getAddress(path);
|
|
21
|
+
|
|
22
|
+
const signer = {
|
|
23
|
+
async getPublicKey() {
|
|
24
|
+
const { utils } = await import("near-api-js");
|
|
25
|
+
// Convert hex public key to NEAR PublicKey format
|
|
26
|
+
return utils.PublicKey.fromString(`ed25519:${pubKeyHex}`);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
signNep413Message(
|
|
30
|
+
_message: string,
|
|
31
|
+
_accountId: string,
|
|
32
|
+
_recipient: string,
|
|
33
|
+
_nonce: Uint8Array,
|
|
34
|
+
_callbackUrl?: string,
|
|
35
|
+
) {
|
|
36
|
+
// Most NEAR Ledger apps don't support arbitrary message signing
|
|
37
|
+
return Promise.reject(
|
|
38
|
+
new SwapKitError("wallet_ledger_method_not_supported", {
|
|
39
|
+
wallet: "Ledger",
|
|
40
|
+
method: "signNep413Message",
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
getAddress() {
|
|
46
|
+
return Promise.resolve(address);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
async signTransaction(transaction: Transaction) {
|
|
50
|
+
const { Signature, SignedTransaction } = await import("near-api-js/lib/transaction");
|
|
51
|
+
try {
|
|
52
|
+
const signatureArray = await nearApp.signTransaction(transaction.encode(), path);
|
|
53
|
+
if (!signatureArray) {
|
|
54
|
+
throw new Error("Signature undefined");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const signature = new Signature({
|
|
58
|
+
keyType: 0,
|
|
59
|
+
data: signatureArray,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const signedTransaction = new SignedTransaction({ transaction, signature });
|
|
63
|
+
|
|
64
|
+
return [signatureArray, signedTransaction] as [
|
|
65
|
+
Uint8Array<ArrayBufferLike>,
|
|
66
|
+
SignedTransaction,
|
|
67
|
+
];
|
|
68
|
+
} catch (error) {
|
|
69
|
+
throw new SwapKitError("wallet_ledger_signing_error", {
|
|
70
|
+
error,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
signDelegateAction(_delegateAction: any) {
|
|
76
|
+
return Promise.reject(
|
|
77
|
+
new SwapKitError("wallet_ledger_method_not_supported", {
|
|
78
|
+
wallet: "Ledger",
|
|
79
|
+
method: "signDelegateAction",
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return signer as NearSigner;
|
|
86
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Chain, SwapKitError, WalletOption } from "@swapkit/helpers";
|
|
2
2
|
|
|
3
|
+
import type { getNearLedgerClient } from "../clients/near";
|
|
3
4
|
import type { XRPLedger } from "../clients/xrp";
|
|
4
5
|
import type { LEDGER_SUPPORTED_CHAINS } from "../index";
|
|
5
6
|
import type { CosmosLedgerClients, EVMLedgerClients, UTXOLedgerClients } from "../types";
|
|
@@ -45,6 +46,10 @@ export const getLedgerAddress = async <
|
|
|
45
46
|
return chain === Chain.BitcoinCash ? address.replace("bitcoincash:", "") : address;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
case Chain.Near: {
|
|
50
|
+
return await (ledgerClient as Awaited<ReturnType<typeof getNearLedgerClient>>).getAddress();
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
case Chain.Ripple: {
|
|
49
54
|
return (ledgerClient as Awaited<ReturnType<typeof XRPLedger>>).address;
|
|
50
55
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
OptimismLedger,
|
|
17
17
|
PolygonLedger,
|
|
18
18
|
} from "../clients/evm";
|
|
19
|
+
import { getNearLedgerClient } from "../clients/near";
|
|
19
20
|
import { THORChainLedger } from "../clients/thorchain";
|
|
20
21
|
import {
|
|
21
22
|
BitcoinCashLedger,
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
LitecoinLedger,
|
|
26
27
|
} from "../clients/utxo";
|
|
27
28
|
import { XRPLedger } from "../clients/xrp";
|
|
29
|
+
import { getLedgerTransport } from "./getLedgerTransport";
|
|
28
30
|
|
|
29
31
|
type LedgerSignerMap = {
|
|
30
32
|
[Chain.Arbitrum]: ReturnType<typeof ArbitrumLedger>;
|
|
@@ -38,6 +40,7 @@ type LedgerSignerMap = {
|
|
|
38
40
|
[Chain.Dogecoin]: ReturnType<typeof DogecoinLedger>;
|
|
39
41
|
[Chain.Ethereum]: ReturnType<typeof EthereumLedger>;
|
|
40
42
|
[Chain.Litecoin]: ReturnType<typeof LitecoinLedger>;
|
|
43
|
+
[Chain.Near]: Awaited<ReturnType<typeof getNearLedgerClient>>;
|
|
41
44
|
[Chain.Optimism]: ReturnType<typeof OptimismLedger>;
|
|
42
45
|
[Chain.Polygon]: ReturnType<typeof PolygonLedger>;
|
|
43
46
|
[Chain.Ripple]: ReturnType<typeof XRPLedger>;
|
|
@@ -75,6 +78,10 @@ export const getLedgerClient = async <T extends LedgerSupportedChain>({
|
|
|
75
78
|
Promise.resolve(LitecoinLedger(derivationPath) as LedgerSignerMap[T]),
|
|
76
79
|
)
|
|
77
80
|
.with(Chain.Ripple, () => Promise.resolve(XRPLedger(derivationPath) as LedgerSignerMap[T]))
|
|
81
|
+
.with(Chain.Near, async () => {
|
|
82
|
+
const transport = await getLedgerTransport();
|
|
83
|
+
return getNearLedgerClient(transport, derivationPath) as unknown as LedgerSignerMap[T];
|
|
84
|
+
})
|
|
78
85
|
.with(
|
|
79
86
|
Chain.Arbitrum,
|
|
80
87
|
Chain.Avalanche,
|
package/src/ledger/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const ledgerWallet = createWallet({
|
|
|
31
31
|
Chain.Dogecoin,
|
|
32
32
|
Chain.Ethereum,
|
|
33
33
|
Chain.Litecoin,
|
|
34
|
+
Chain.Near,
|
|
34
35
|
Chain.Optimism,
|
|
35
36
|
Chain.Polygon,
|
|
36
37
|
Chain.Ripple,
|
|
@@ -269,6 +270,15 @@ async function getWalletMethods({
|
|
|
269
270
|
return { ...toolbox, address, deposit, transfer, signMessage };
|
|
270
271
|
}
|
|
271
272
|
|
|
273
|
+
case Chain.Near: {
|
|
274
|
+
const { getNearToolbox } = await import("@swapkit/toolboxes/near");
|
|
275
|
+
const signer = await getLedgerClient({ chain, derivationPath });
|
|
276
|
+
const accountId = await signer.getAddress();
|
|
277
|
+
const toolbox = await getNearToolbox({ signer });
|
|
278
|
+
|
|
279
|
+
return { ...toolbox, address: accountId };
|
|
280
|
+
}
|
|
281
|
+
|
|
272
282
|
case Chain.Ripple: {
|
|
273
283
|
const { getRippleToolbox } = await import("@swapkit/toolboxes/ripple");
|
|
274
284
|
const signer = await getLedgerClient({ chain, derivationPath });
|
package/src/okx/helpers.ts
CHANGED
|
@@ -123,6 +123,22 @@ export async function getWalletMethods(chain: Chain) {
|
|
|
123
123
|
return { ...toolbox, address, transfer: cosmosTransfer() };
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
case Chain.Near: {
|
|
127
|
+
if (!(window.okxwallet && "near" in window.okxwallet)) {
|
|
128
|
+
throw new SwapKitError("wallet_okx_not_found", { chain: Chain.Near });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const { createNearSignerFromProvider } = await import("../helpers/near");
|
|
132
|
+
const { getNearToolbox } = await import("@swapkit/toolboxes/near");
|
|
133
|
+
|
|
134
|
+
const provider = window.okxwallet.near;
|
|
135
|
+
const signer = await createNearSignerFromProvider(provider, "OKX");
|
|
136
|
+
const accountId = await signer.getAddress();
|
|
137
|
+
const toolbox = await getNearToolbox({ signer });
|
|
138
|
+
|
|
139
|
+
return { ...toolbox, address: accountId };
|
|
140
|
+
}
|
|
141
|
+
|
|
126
142
|
default:
|
|
127
143
|
throw new SwapKitError("wallet_okx_chain_not_supported", { chain });
|
|
128
144
|
}
|
package/src/okx/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { cosmostationWallet } from "./cosmostation";
|
|
|
16
16
|
import type { ctrlWallet } from "./ctrl";
|
|
17
17
|
import type { evmWallet } from "./evm-extensions";
|
|
18
18
|
import type { exodusWallet } from "./exodus";
|
|
19
|
+
import type { NearBrowserWalletProvider } from "./helpers/near";
|
|
19
20
|
import type { keepkeyWallet } from "./keepkey";
|
|
20
21
|
import type { keepkeyBexWallet } from "./keepkey-bex";
|
|
21
22
|
import type { keplrWallet } from "./keplr";
|
|
@@ -122,6 +123,7 @@ declare global {
|
|
|
122
123
|
thorchain: Eip1193Provider;
|
|
123
124
|
mayachain: Eip1193Provider;
|
|
124
125
|
solana: SolanaProvider & { isXDEFI: boolean };
|
|
126
|
+
near: NearBrowserWalletProvider;
|
|
125
127
|
};
|
|
126
128
|
|
|
127
129
|
bitkeep?: {
|
|
@@ -196,6 +198,15 @@ declare global {
|
|
|
196
198
|
) => Promise<boolean>;
|
|
197
199
|
getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
|
|
198
200
|
};
|
|
201
|
+
near: NearBrowserWalletProvider & {
|
|
202
|
+
requestSignIn: (params?: {
|
|
203
|
+
contractId?: string;
|
|
204
|
+
methodNames?: string[];
|
|
205
|
+
}) => Promise<{ accountId: string; accessKey?: any }>;
|
|
206
|
+
requestSignTransactions: (params: {
|
|
207
|
+
transactions: any[];
|
|
208
|
+
}) => Promise<any>;
|
|
209
|
+
};
|
|
199
210
|
}
|
|
200
211
|
| EthereumWindowProvider;
|
|
201
212
|
}
|
|
@@ -13,6 +13,8 @@ export const ARBITRUM_ONE_MAINNET_ID = "eip155:42161";
|
|
|
13
13
|
export const OPTIMISM_MAINNET_ID = "eip155:10";
|
|
14
14
|
export const POLYGON_MAINNET_ID = "eip155:137";
|
|
15
15
|
export const BASE_MAINNET_ID = "eip155:8453";
|
|
16
|
+
export const NEAR_MAINNET_ID = "near:mainnet";
|
|
17
|
+
export const NEAR_TESTNET_ID = "near:testnet";
|
|
16
18
|
|
|
17
19
|
export const DEFAULT_LOGGER = "debug";
|
|
18
20
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Chain, type EVMChain } from "@swapkit/helpers";
|
|
1
|
+
import { Chain, type EVMChain, SKConfig } from "@swapkit/helpers";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ARBITRUM_ONE_MAINNET_ID,
|
|
@@ -9,13 +9,15 @@ import {
|
|
|
9
9
|
ETHEREUM_MAINNET_ID,
|
|
10
10
|
KUJIRA_MAINNET_ID,
|
|
11
11
|
MAYACHAIN_MAINNET_ID,
|
|
12
|
+
NEAR_MAINNET_ID,
|
|
13
|
+
NEAR_TESTNET_ID,
|
|
12
14
|
OPTIMISM_MAINNET_ID,
|
|
13
15
|
POLYGON_MAINNET_ID,
|
|
14
16
|
THORCHAIN_MAINNET_ID,
|
|
15
17
|
} from "./constants";
|
|
16
18
|
|
|
17
19
|
export const getAddressByChain = (
|
|
18
|
-
chain: EVMChain | Chain.THORChain | Chain.Maya | Chain.Kujira | Chain.Cosmos,
|
|
20
|
+
chain: EVMChain | Chain.THORChain | Chain.Maya | Chain.Kujira | Chain.Cosmos | Chain.Near,
|
|
19
21
|
accounts: string[],
|
|
20
22
|
) => {
|
|
21
23
|
const account = accounts.find((account) => account.startsWith(chainToChainId(chain))) || "";
|
|
@@ -48,6 +50,11 @@ export const chainToChainId = (chain: Chain) => {
|
|
|
48
50
|
return COSMOS_HUB_MAINNET_ID;
|
|
49
51
|
case Chain.Kujira:
|
|
50
52
|
return KUJIRA_MAINNET_ID;
|
|
53
|
+
case Chain.Near: {
|
|
54
|
+
// Use testnet if stagenet is enabled
|
|
55
|
+
const { isStagenet } = SKConfig.get("envs");
|
|
56
|
+
return isStagenet ? NEAR_TESTNET_ID : NEAR_MAINNET_ID;
|
|
57
|
+
}
|
|
51
58
|
default:
|
|
52
59
|
return "";
|
|
53
60
|
}
|
|
@@ -10,8 +10,10 @@ import {
|
|
|
10
10
|
filterSupportedChains,
|
|
11
11
|
} from "@swapkit/helpers";
|
|
12
12
|
import type { ThorchainDepositParams, createThorchainToolbox } from "@swapkit/toolboxes/cosmos";
|
|
13
|
+
import type { NearSigner } from "@swapkit/toolboxes/near";
|
|
13
14
|
import type { WalletConnectModalSign } from "@walletconnect/modal-sign-html";
|
|
14
15
|
import type { SessionTypes, SignClientTypes } from "@walletconnect/types";
|
|
16
|
+
import type { Transaction } from "near-api-js/lib/transaction";
|
|
15
17
|
|
|
16
18
|
import { getWalletSupportedChains } from "../utils";
|
|
17
19
|
import {
|
|
@@ -40,6 +42,7 @@ export const walletconnectWallet = createWallet({
|
|
|
40
42
|
Chain.Ethereum,
|
|
41
43
|
Chain.Kujira,
|
|
42
44
|
Chain.Maya,
|
|
45
|
+
Chain.Near,
|
|
43
46
|
Chain.Optimism,
|
|
44
47
|
Chain.Polygon,
|
|
45
48
|
Chain.THORChain,
|
|
@@ -242,6 +245,71 @@ async function getToolbox<T extends (typeof WC_SUPPORTED_CHAINS)[number]>({
|
|
|
242
245
|
getAccount,
|
|
243
246
|
};
|
|
244
247
|
}
|
|
248
|
+
|
|
249
|
+
case Chain.Near: {
|
|
250
|
+
const { getNearToolbox } = await import("@swapkit/toolboxes/near");
|
|
251
|
+
const { DEFAULT_NEAR_METHODS } = await import("./constants");
|
|
252
|
+
|
|
253
|
+
// Create a NEAR signer that uses WalletConnect
|
|
254
|
+
const signer = {
|
|
255
|
+
getPublicKey() {
|
|
256
|
+
// WalletConnect NEAR doesn't expose public key directly
|
|
257
|
+
return Promise.reject(
|
|
258
|
+
new SwapKitError("wallet_walletconnect_method_not_supported", {
|
|
259
|
+
method: "getPublicKey",
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
signNep413Message(
|
|
265
|
+
_message: string,
|
|
266
|
+
_accountId: string,
|
|
267
|
+
_recipient: string,
|
|
268
|
+
_nonce: Uint8Array,
|
|
269
|
+
_callbackUrl?: string,
|
|
270
|
+
) {
|
|
271
|
+
// WalletConnect NEAR spec doesn't include NEP-413 message signing
|
|
272
|
+
return Promise.reject(
|
|
273
|
+
new SwapKitError("wallet_walletconnect_method_not_supported", {
|
|
274
|
+
method: "signNep413Message",
|
|
275
|
+
}),
|
|
276
|
+
);
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
async signTransaction(transaction: Transaction) {
|
|
280
|
+
if (!walletconnect) {
|
|
281
|
+
throw new SwapKitError("wallet_walletconnect_connection_not_established");
|
|
282
|
+
}
|
|
283
|
+
// WalletConnect signs and sends in one operation
|
|
284
|
+
const result = await walletconnect.client.request({
|
|
285
|
+
topic: session.topic,
|
|
286
|
+
chainId: chainToChainId(Chain.Near),
|
|
287
|
+
request: {
|
|
288
|
+
method: DEFAULT_NEAR_METHODS.NEAR_SIGN_AND_SEND_TRANSACTION,
|
|
289
|
+
params: { transaction },
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
// Return dummy hash and result
|
|
293
|
+
return [new Uint8Array(32), result];
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
signDelegateAction(_delegateAction: any) {
|
|
297
|
+
return Promise.reject(
|
|
298
|
+
new SwapKitError("wallet_walletconnect_method_not_supported", {
|
|
299
|
+
method: "signDelegateAction",
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
getAddress() {
|
|
305
|
+
return Promise.resolve(address);
|
|
306
|
+
},
|
|
307
|
+
} as NearSigner;
|
|
308
|
+
|
|
309
|
+
const toolbox = await getNearToolbox({ signer });
|
|
310
|
+
return toolbox;
|
|
311
|
+
}
|
|
312
|
+
|
|
245
313
|
default:
|
|
246
314
|
throw new SwapKitError({
|
|
247
315
|
errorKey: "wallet_chain_not_supported",
|
|
File without changes
|
|
File without changes
|