@vleap/warps-adapter-solana 0.1.0-beta.6 → 0.1.0-beta.7
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.d.cts +21 -23
- package/dist/index.d.ts +21 -23
- package/dist/index.js +218 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { WarpChainAsset,
|
|
1
|
+
import { WarpChainAsset, ChainAdapterFactory, WarpChain, WarpChainEnv, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionExecutionResult, AdapterWarpExplorer, AdapterWarpOutput, Warp, WarpActionIndex, WarpAdapterGenericRemoteTransaction, ResolvedInput, WarpNativeValue, WarpExecutionOutput, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, BaseWarpActionInputType, WarpAdapterGenericType, AdapterWarpWallet, WarpAdapterGenericTransaction, WarpWalletDetails } from '@vleap/warps';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
3
|
|
|
4
4
|
declare const NativeTokenSol: WarpChainAsset;
|
|
5
|
-
declare const
|
|
5
|
+
declare const SolanaAdapter: ChainAdapterFactory;
|
|
6
6
|
|
|
7
7
|
declare const WarpSolanaConstants: {
|
|
8
8
|
ComputeUnitLimit: {
|
|
@@ -50,21 +50,25 @@ declare const SolanaExplorerNames: {
|
|
|
50
50
|
readonly devnet: readonly [SolanaExplorers.SolscanDevnet, SolanaExplorers.SolanaExplorerDevnet];
|
|
51
51
|
};
|
|
52
52
|
declare const SolanaExplorerUrls: Record<ExplorerName, string>;
|
|
53
|
+
declare const X402SolanaNetworkIdentifiers: {
|
|
54
|
+
readonly Mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
55
|
+
readonly Devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
56
|
+
};
|
|
57
|
+
declare const SupportedX402SolanaNetworks: string[];
|
|
53
58
|
|
|
54
59
|
declare const KnownTokens: Record<WarpChain, Record<string, WarpChainAsset[]>>;
|
|
55
60
|
declare const findKnownTokenById: (chain: WarpChain, env: WarpChainEnv, id: string) => WarpChainAsset | null;
|
|
56
61
|
declare const getKnownTokensForChain: (chainName: string, env?: string) => WarpChainAsset[];
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
declare module '@solana/kit' {
|
|
64
|
+
export function createKeyPairSignerFromBytes(bytes: Uint8Array): Promise<{
|
|
65
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>
|
|
66
|
+
signTransaction: (transaction: unknown) => Promise<unknown>
|
|
67
|
+
}>
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
metadata: TokenMetadata;
|
|
69
|
+
|
|
70
|
+
declare module '@x402/svm/exact/client' {
|
|
71
|
+
export function registerExactSvmScheme(client: unknown, options: { signer: unknown }): void
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
declare class WarpSolanaDataLoader implements AdapterWarpDataLoader {
|
|
@@ -169,25 +173,19 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
169
173
|
private walletProvider;
|
|
170
174
|
private cachedAddress;
|
|
171
175
|
private cachedPublicKey;
|
|
172
|
-
constructor(config: WarpClientConfig, chain: WarpChainInfo
|
|
176
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
177
|
+
private createProvider;
|
|
173
178
|
private initializeCache;
|
|
174
179
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
175
180
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
176
181
|
signMessage(message: string): Promise<string>;
|
|
177
182
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
178
183
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
179
|
-
create(mnemonic: string):
|
|
180
|
-
|
|
181
|
-
privateKey: string;
|
|
182
|
-
mnemonic: string;
|
|
183
|
-
};
|
|
184
|
-
generate(): {
|
|
185
|
-
address: string;
|
|
186
|
-
privateKey: string;
|
|
187
|
-
mnemonic: string;
|
|
188
|
-
};
|
|
184
|
+
create(mnemonic: string): WarpWalletDetails;
|
|
185
|
+
generate(): WarpWalletDetails;
|
|
189
186
|
getAddress(): string | null;
|
|
190
187
|
getPublicKey(): string | null;
|
|
188
|
+
registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
|
|
191
189
|
}
|
|
192
190
|
|
|
193
|
-
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSol, SolanaExplorerMap, SolanaExplorerNames, SolanaExplorerUrls, SolanaExplorers,
|
|
191
|
+
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSol, SolanaAdapter, SolanaExplorerMap, SolanaExplorerNames, SolanaExplorerUrls, SolanaExplorers, SupportedX402SolanaNetworks, WarpSolanaConstants, WarpSolanaDataLoader, WarpSolanaExecutor, WarpSolanaExplorer, WarpSolanaOutput, WarpSolanaSerializer, WarpSolanaWallet, X402SolanaNetworkIdentifiers, findKnownTokenById, getKnownTokensForChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { WarpChainAsset,
|
|
1
|
+
import { WarpChainAsset, ChainAdapterFactory, WarpChain, WarpChainEnv, AdapterWarpDataLoader, WarpClientConfig, WarpChainInfo, WarpChainAccount, WarpChainAction, WarpDataLoaderOptions, AdapterWarpExecutor, WarpExecutable, WarpActionExecutionResult, AdapterWarpExplorer, AdapterWarpOutput, Warp, WarpActionIndex, WarpAdapterGenericRemoteTransaction, ResolvedInput, WarpNativeValue, WarpExecutionOutput, AdapterWarpSerializer, WarpSerializer, WarpActionInputType, BaseWarpActionInputType, WarpAdapterGenericType, AdapterWarpWallet, WarpAdapterGenericTransaction, WarpWalletDetails } from '@vleap/warps';
|
|
2
2
|
import { Transaction } from '@solana/web3.js';
|
|
3
3
|
|
|
4
4
|
declare const NativeTokenSol: WarpChainAsset;
|
|
5
|
-
declare const
|
|
5
|
+
declare const SolanaAdapter: ChainAdapterFactory;
|
|
6
6
|
|
|
7
7
|
declare const WarpSolanaConstants: {
|
|
8
8
|
ComputeUnitLimit: {
|
|
@@ -50,21 +50,25 @@ declare const SolanaExplorerNames: {
|
|
|
50
50
|
readonly devnet: readonly [SolanaExplorers.SolscanDevnet, SolanaExplorers.SolanaExplorerDevnet];
|
|
51
51
|
};
|
|
52
52
|
declare const SolanaExplorerUrls: Record<ExplorerName, string>;
|
|
53
|
+
declare const X402SolanaNetworkIdentifiers: {
|
|
54
|
+
readonly Mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
55
|
+
readonly Devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
56
|
+
};
|
|
57
|
+
declare const SupportedX402SolanaNetworks: string[];
|
|
53
58
|
|
|
54
59
|
declare const KnownTokens: Record<WarpChain, Record<string, WarpChainAsset[]>>;
|
|
55
60
|
declare const findKnownTokenById: (chain: WarpChain, env: WarpChainEnv, id: string) => WarpChainAsset | null;
|
|
56
61
|
declare const getKnownTokensForChain: (chainName: string, env?: string) => WarpChainAsset[];
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
declare module '@solana/kit' {
|
|
64
|
+
export function createKeyPairSignerFromBytes(bytes: Uint8Array): Promise<{
|
|
65
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>
|
|
66
|
+
signTransaction: (transaction: unknown) => Promise<unknown>
|
|
67
|
+
}>
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
metadata: TokenMetadata;
|
|
69
|
+
|
|
70
|
+
declare module '@x402/svm/exact/client' {
|
|
71
|
+
export function registerExactSvmScheme(client: unknown, options: { signer: unknown }): void
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
declare class WarpSolanaDataLoader implements AdapterWarpDataLoader {
|
|
@@ -169,25 +173,19 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
169
173
|
private walletProvider;
|
|
170
174
|
private cachedAddress;
|
|
171
175
|
private cachedPublicKey;
|
|
172
|
-
constructor(config: WarpClientConfig, chain: WarpChainInfo
|
|
176
|
+
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
177
|
+
private createProvider;
|
|
173
178
|
private initializeCache;
|
|
174
179
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
175
180
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
176
181
|
signMessage(message: string): Promise<string>;
|
|
177
182
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
178
183
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
179
|
-
create(mnemonic: string):
|
|
180
|
-
|
|
181
|
-
privateKey: string;
|
|
182
|
-
mnemonic: string;
|
|
183
|
-
};
|
|
184
|
-
generate(): {
|
|
185
|
-
address: string;
|
|
186
|
-
privateKey: string;
|
|
187
|
-
mnemonic: string;
|
|
188
|
-
};
|
|
184
|
+
create(mnemonic: string): WarpWalletDetails;
|
|
185
|
+
generate(): WarpWalletDetails;
|
|
189
186
|
getAddress(): string | null;
|
|
190
187
|
getPublicKey(): string | null;
|
|
188
|
+
registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
|
|
191
189
|
}
|
|
192
190
|
|
|
193
|
-
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSol, SolanaExplorerMap, SolanaExplorerNames, SolanaExplorerUrls, SolanaExplorers,
|
|
191
|
+
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenSol, SolanaAdapter, SolanaExplorerMap, SolanaExplorerNames, SolanaExplorerUrls, SolanaExplorers, SupportedX402SolanaNetworks, WarpSolanaConstants, WarpSolanaDataLoader, WarpSolanaExecutor, WarpSolanaExplorer, WarpSolanaOutput, WarpSolanaSerializer, WarpSolanaWallet, X402SolanaNetworkIdentifiers, findKnownTokenById, getKnownTokensForChain };
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,12 @@ __export(index_exports, {
|
|
|
33
33
|
ExplorerUrls: () => ExplorerUrls,
|
|
34
34
|
KnownTokens: () => KnownTokens,
|
|
35
35
|
NativeTokenSol: () => NativeTokenSol,
|
|
36
|
+
SolanaAdapter: () => SolanaAdapter,
|
|
36
37
|
SolanaExplorerMap: () => SolanaExplorerMap,
|
|
37
38
|
SolanaExplorerNames: () => SolanaExplorerNames,
|
|
38
39
|
SolanaExplorerUrls: () => SolanaExplorerUrls,
|
|
39
40
|
SolanaExplorers: () => SolanaExplorers,
|
|
41
|
+
SupportedX402SolanaNetworks: () => SupportedX402SolanaNetworks,
|
|
40
42
|
WarpSolanaConstants: () => WarpSolanaConstants,
|
|
41
43
|
WarpSolanaDataLoader: () => WarpSolanaDataLoader,
|
|
42
44
|
WarpSolanaExecutor: () => WarpSolanaExecutor,
|
|
@@ -44,14 +46,14 @@ __export(index_exports, {
|
|
|
44
46
|
WarpSolanaOutput: () => WarpSolanaOutput,
|
|
45
47
|
WarpSolanaSerializer: () => WarpSolanaSerializer,
|
|
46
48
|
WarpSolanaWallet: () => WarpSolanaWallet,
|
|
49
|
+
X402SolanaNetworkIdentifiers: () => X402SolanaNetworkIdentifiers,
|
|
47
50
|
findKnownTokenById: () => findKnownTokenById,
|
|
48
|
-
getKnownTokensForChain: () => getKnownTokensForChain
|
|
49
|
-
getSolanaAdapter: () => getSolanaAdapter
|
|
51
|
+
getKnownTokensForChain: () => getKnownTokensForChain
|
|
50
52
|
});
|
|
51
53
|
module.exports = __toCommonJS(index_exports);
|
|
52
54
|
|
|
53
55
|
// src/chains/solana.ts
|
|
54
|
-
var
|
|
56
|
+
var import_warps9 = require("@vleap/warps");
|
|
55
57
|
|
|
56
58
|
// src/WarpSolanaDataLoader.ts
|
|
57
59
|
var import_warps2 = require("@vleap/warps");
|
|
@@ -112,6 +114,11 @@ var SolanaExplorerNames = {
|
|
|
112
114
|
devnet: ["solscan_devnet" /* SolscanDevnet */, "solana_explorer_devnet" /* SolanaExplorerDevnet */]
|
|
113
115
|
};
|
|
114
116
|
var SolanaExplorerUrls = ExplorerUrls;
|
|
117
|
+
var X402SolanaNetworkIdentifiers = {
|
|
118
|
+
Mainnet: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
119
|
+
Devnet: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
120
|
+
};
|
|
121
|
+
var SupportedX402SolanaNetworks = [X402SolanaNetworkIdentifiers.Mainnet, X402SolanaNetworkIdentifiers.Devnet];
|
|
115
122
|
|
|
116
123
|
// src/tokens/solana.ts
|
|
117
124
|
var import_warps = require("@vleap/warps");
|
|
@@ -1271,18 +1278,18 @@ var WarpSolanaExplorer = class {
|
|
|
1271
1278
|
};
|
|
1272
1279
|
|
|
1273
1280
|
// src/WarpSolanaWallet.ts
|
|
1274
|
-
var
|
|
1275
|
-
var
|
|
1276
|
-
var
|
|
1277
|
-
var
|
|
1278
|
-
var import_bs583 = __toESM(require("bs58"), 1);
|
|
1281
|
+
var import_kit = require("@solana/kit");
|
|
1282
|
+
var import_web37 = require("@solana/web3.js");
|
|
1283
|
+
var import_warps8 = require("@vleap/warps");
|
|
1284
|
+
var import_client = require("@x402/svm/exact/client");
|
|
1279
1285
|
|
|
1280
|
-
// src/providers/
|
|
1281
|
-
var import_web35 = require("@solana/web3.js");
|
|
1286
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
1282
1287
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
1283
|
-
var
|
|
1288
|
+
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
1289
|
+
var import_web35 = require("@solana/web3.js");
|
|
1284
1290
|
var import_warps6 = require("@vleap/warps");
|
|
1285
|
-
var
|
|
1291
|
+
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1292
|
+
var MnemonicWalletProvider = class {
|
|
1286
1293
|
constructor(config, chain, connection) {
|
|
1287
1294
|
this.config = config;
|
|
1288
1295
|
this.chain = chain;
|
|
@@ -1290,6 +1297,8 @@ var SolanaWalletProvider = class {
|
|
|
1290
1297
|
this.keypair = null;
|
|
1291
1298
|
}
|
|
1292
1299
|
async getAddress() {
|
|
1300
|
+
const address = (0, import_warps6.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1301
|
+
if (address) return address;
|
|
1293
1302
|
try {
|
|
1294
1303
|
const keypair = this.getKeypair();
|
|
1295
1304
|
return keypair.publicKey.toBase58();
|
|
@@ -1351,58 +1360,191 @@ var SolanaWalletProvider = class {
|
|
|
1351
1360
|
getKeypairInstance() {
|
|
1352
1361
|
return this.getKeypair();
|
|
1353
1362
|
}
|
|
1363
|
+
create(mnemonic) {
|
|
1364
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1365
|
+
const keypair = import_web35.Keypair.fromSeed(seed.slice(0, 32));
|
|
1366
|
+
return {
|
|
1367
|
+
provider: "mnemonic",
|
|
1368
|
+
address: keypair.publicKey.toBase58(),
|
|
1369
|
+
privateKey: import_bs582.default.encode(keypair.secretKey),
|
|
1370
|
+
mnemonic
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
generate() {
|
|
1374
|
+
const keypair = import_web35.Keypair.generate();
|
|
1375
|
+
const entropy = keypair.secretKey.slice(0, 16);
|
|
1376
|
+
const mnemonic = bip39.entropyToMnemonic(entropy, import_english.wordlist);
|
|
1377
|
+
return {
|
|
1378
|
+
provider: "mnemonic",
|
|
1379
|
+
address: keypair.publicKey.toBase58(),
|
|
1380
|
+
privateKey: import_bs582.default.encode(keypair.secretKey),
|
|
1381
|
+
mnemonic
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1354
1384
|
getKeypair() {
|
|
1355
1385
|
if (this.keypair) return this.keypair;
|
|
1356
|
-
const
|
|
1357
|
-
if (
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1386
|
+
const mnemonic = (0, import_warps6.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1387
|
+
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
1388
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1389
|
+
this.keypair = import_web35.Keypair.fromSeed(seed.slice(0, 32));
|
|
1390
|
+
return this.keypair;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
// src/providers/PrivateKeyWalletProvider.ts
|
|
1395
|
+
var bip392 = __toESM(require("@scure/bip39"), 1);
|
|
1396
|
+
var import_english2 = require("@scure/bip39/wordlists/english.js");
|
|
1397
|
+
var import_web36 = require("@solana/web3.js");
|
|
1398
|
+
var import_warps7 = require("@vleap/warps");
|
|
1399
|
+
var import_bs583 = __toESM(require("bs58"), 1);
|
|
1400
|
+
var PrivateKeyWalletProvider = class {
|
|
1401
|
+
constructor(config, chain, connection) {
|
|
1402
|
+
this.config = config;
|
|
1403
|
+
this.chain = chain;
|
|
1404
|
+
this.connection = connection;
|
|
1405
|
+
this.keypair = null;
|
|
1406
|
+
}
|
|
1407
|
+
async getAddress() {
|
|
1408
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1409
|
+
if (address) return address;
|
|
1410
|
+
try {
|
|
1411
|
+
const keypair = this.getKeypair();
|
|
1412
|
+
return keypair.publicKey.toBase58();
|
|
1413
|
+
} catch {
|
|
1414
|
+
return null;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
async getPublicKey() {
|
|
1418
|
+
try {
|
|
1419
|
+
const keypair = this.getKeypair();
|
|
1420
|
+
return keypair.publicKey.toBase58();
|
|
1421
|
+
} catch {
|
|
1422
|
+
return null;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
async signTransaction(tx) {
|
|
1426
|
+
const keypair = this.getKeypair();
|
|
1427
|
+
if (tx instanceof import_web36.VersionedTransaction) {
|
|
1428
|
+
tx.sign([keypair]);
|
|
1429
|
+
return tx;
|
|
1430
|
+
}
|
|
1431
|
+
if (tx instanceof import_web36.Transaction) {
|
|
1432
|
+
tx.sign(keypair);
|
|
1433
|
+
return tx;
|
|
1434
|
+
}
|
|
1435
|
+
if (tx.transaction) {
|
|
1436
|
+
if (tx.transaction instanceof import_web36.Transaction) {
|
|
1437
|
+
tx.transaction.sign(keypair);
|
|
1438
|
+
return { ...tx, transaction: tx.transaction.serialize() };
|
|
1439
|
+
}
|
|
1440
|
+
if (typeof tx.transaction === "object") {
|
|
1441
|
+
try {
|
|
1442
|
+
const transaction = import_web36.Transaction.from(tx.transaction);
|
|
1443
|
+
transaction.sign(keypair);
|
|
1444
|
+
return { ...tx, transaction: transaction.serialize(), signature: transaction.signature };
|
|
1445
|
+
} catch {
|
|
1446
|
+
throw new Error("Invalid transaction format");
|
|
1372
1447
|
}
|
|
1373
|
-
throw new Error("Invalid private key format");
|
|
1374
1448
|
}
|
|
1375
1449
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1450
|
+
throw new Error("Invalid transaction format");
|
|
1451
|
+
}
|
|
1452
|
+
async signMessage(message) {
|
|
1453
|
+
const keypair = this.getKeypair();
|
|
1454
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1455
|
+
const nacl = await import("tweetnacl");
|
|
1456
|
+
const secretKey = keypair.secretKey;
|
|
1457
|
+
if (secretKey.length !== 64) {
|
|
1458
|
+
throw new Error(`Invalid secret key length: expected 64, got ${secretKey.length}`);
|
|
1459
|
+
}
|
|
1460
|
+
const privateKeySlice = secretKey.slice(0, 32);
|
|
1461
|
+
const privateKeyBytes = new Uint8Array(privateKeySlice);
|
|
1462
|
+
if (privateKeyBytes.length !== 32) {
|
|
1463
|
+
throw new Error(`Invalid private key length: expected 32, got ${privateKeyBytes.length}`);
|
|
1464
|
+
}
|
|
1465
|
+
const signature = nacl.sign.detached(messageBytes, privateKeyBytes);
|
|
1466
|
+
return import_bs583.default.encode(signature);
|
|
1467
|
+
}
|
|
1468
|
+
getKeypairInstance() {
|
|
1469
|
+
return this.getKeypair();
|
|
1470
|
+
}
|
|
1471
|
+
create(mnemonic) {
|
|
1472
|
+
const seed = bip392.mnemonicToSeedSync(mnemonic);
|
|
1473
|
+
const keypair = import_web36.Keypair.fromSeed(seed.slice(0, 32));
|
|
1474
|
+
return {
|
|
1475
|
+
provider: "privateKey",
|
|
1476
|
+
address: keypair.publicKey.toBase58(),
|
|
1477
|
+
privateKey: import_bs583.default.encode(keypair.secretKey),
|
|
1478
|
+
mnemonic
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
generate() {
|
|
1482
|
+
const keypair = import_web36.Keypair.generate();
|
|
1483
|
+
const entropy = keypair.secretKey.slice(0, 16);
|
|
1484
|
+
const mnemonic = bip392.entropyToMnemonic(entropy, import_english2.wordlist);
|
|
1485
|
+
return {
|
|
1486
|
+
provider: "privateKey",
|
|
1487
|
+
address: keypair.publicKey.toBase58(),
|
|
1488
|
+
privateKey: import_bs583.default.encode(keypair.secretKey),
|
|
1489
|
+
mnemonic
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
getKeypair() {
|
|
1493
|
+
if (this.keypair) return this.keypair;
|
|
1494
|
+
const privateKey = (0, import_warps7.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
1495
|
+
if (!privateKey) throw new Error("No private key provided");
|
|
1496
|
+
try {
|
|
1497
|
+
const secretKey = import_bs583.default.decode(privateKey);
|
|
1498
|
+
if (secretKey.length === 64) {
|
|
1499
|
+
this.keypair = import_web36.Keypair.fromSecretKey(secretKey);
|
|
1500
|
+
return this.keypair;
|
|
1501
|
+
} else if (secretKey.length === 32) {
|
|
1502
|
+
this.keypair = import_web36.Keypair.fromSeed(secretKey);
|
|
1503
|
+
return this.keypair;
|
|
1504
|
+
} else {
|
|
1505
|
+
throw new Error(`Invalid private key length: expected 32 or 64 bytes, got ${secretKey.length}`);
|
|
1506
|
+
}
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
if (error instanceof Error) {
|
|
1509
|
+
throw new Error(`Invalid private key format: ${error.message}`);
|
|
1510
|
+
}
|
|
1511
|
+
throw new Error("Invalid private key format");
|
|
1381
1512
|
}
|
|
1382
|
-
throw new Error("No private key or mnemonic provided");
|
|
1383
1513
|
}
|
|
1384
1514
|
};
|
|
1385
1515
|
|
|
1386
1516
|
// src/WarpSolanaWallet.ts
|
|
1387
1517
|
var WarpSolanaWallet = class {
|
|
1388
|
-
constructor(config, chain
|
|
1518
|
+
constructor(config, chain) {
|
|
1389
1519
|
this.config = config;
|
|
1390
1520
|
this.chain = chain;
|
|
1391
1521
|
this.cachedAddress = null;
|
|
1392
1522
|
this.cachedPublicKey = null;
|
|
1393
|
-
const providerConfig = (0,
|
|
1394
|
-
this.connection = new
|
|
1395
|
-
this.walletProvider =
|
|
1523
|
+
const providerConfig = (0, import_warps8.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1524
|
+
this.connection = new import_web37.Connection(providerConfig.url, "confirmed");
|
|
1525
|
+
this.walletProvider = this.createProvider();
|
|
1396
1526
|
this.initializeCache();
|
|
1397
1527
|
}
|
|
1528
|
+
createProvider() {
|
|
1529
|
+
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1530
|
+
if (!wallet) return null;
|
|
1531
|
+
if (typeof wallet === "string") throw new Error(`Wallet can not be used for signing: ${wallet}`);
|
|
1532
|
+
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
1533
|
+
const providerFactory = customWalletProviders?.[wallet.provider];
|
|
1534
|
+
if (providerFactory) return providerFactory(this.config, this.chain);
|
|
1535
|
+
if (wallet.provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain, this.connection);
|
|
1536
|
+
if (wallet.provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain, this.connection);
|
|
1537
|
+
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${wallet.provider}`);
|
|
1538
|
+
}
|
|
1398
1539
|
initializeCache() {
|
|
1399
|
-
(0,
|
|
1540
|
+
(0, import_warps8.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1400
1541
|
this.cachedAddress = cache.address;
|
|
1401
1542
|
this.cachedPublicKey = cache.publicKey;
|
|
1402
1543
|
});
|
|
1403
1544
|
}
|
|
1404
1545
|
async signTransaction(tx) {
|
|
1405
1546
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1547
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1406
1548
|
return await this.walletProvider.signTransaction(tx);
|
|
1407
1549
|
}
|
|
1408
1550
|
async signTransactions(txs) {
|
|
@@ -1410,28 +1552,29 @@ var WarpSolanaWallet = class {
|
|
|
1410
1552
|
return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
|
|
1411
1553
|
}
|
|
1412
1554
|
async signMessage(message) {
|
|
1555
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1413
1556
|
return await this.walletProvider.signMessage(message);
|
|
1414
1557
|
}
|
|
1415
1558
|
async sendTransaction(tx) {
|
|
1416
1559
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1417
1560
|
let transaction;
|
|
1418
|
-
if (tx instanceof
|
|
1561
|
+
if (tx instanceof import_web37.VersionedTransaction) {
|
|
1419
1562
|
transaction = tx;
|
|
1420
|
-
} else if (tx instanceof
|
|
1563
|
+
} else if (tx instanceof import_web37.Transaction) {
|
|
1421
1564
|
transaction = tx;
|
|
1422
1565
|
} else if (tx.transaction) {
|
|
1423
|
-
if (tx.transaction instanceof
|
|
1566
|
+
if (tx.transaction instanceof import_web37.Transaction) {
|
|
1424
1567
|
transaction = tx.transaction;
|
|
1425
|
-
} else if (tx.transaction instanceof
|
|
1568
|
+
} else if (tx.transaction instanceof import_web37.VersionedTransaction) {
|
|
1426
1569
|
transaction = tx.transaction;
|
|
1427
1570
|
} else if (typeof tx.transaction === "object") {
|
|
1428
1571
|
try {
|
|
1429
|
-
transaction =
|
|
1572
|
+
transaction = import_web37.Transaction.from(tx.transaction);
|
|
1430
1573
|
} catch {
|
|
1431
1574
|
throw new Error("Invalid transaction format");
|
|
1432
1575
|
}
|
|
1433
1576
|
} else if (Buffer.isBuffer(tx.transaction) || typeof tx.transaction === "string") {
|
|
1434
|
-
transaction =
|
|
1577
|
+
transaction = import_web37.Transaction.from(tx.transaction);
|
|
1435
1578
|
} else {
|
|
1436
1579
|
throw new Error("Transaction must be signed before sending");
|
|
1437
1580
|
}
|
|
@@ -1448,23 +1591,12 @@ var WarpSolanaWallet = class {
|
|
|
1448
1591
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1449
1592
|
}
|
|
1450
1593
|
create(mnemonic) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
return {
|
|
1454
|
-
address: keypair.publicKey.toBase58(),
|
|
1455
|
-
privateKey: import_bs583.default.encode(keypair.secretKey),
|
|
1456
|
-
mnemonic
|
|
1457
|
-
};
|
|
1594
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1595
|
+
return this.walletProvider.create(mnemonic);
|
|
1458
1596
|
}
|
|
1459
1597
|
generate() {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
const mnemonic = bip392.entropyToMnemonic(entropy, import_english.wordlist);
|
|
1463
|
-
return {
|
|
1464
|
-
address: keypair.publicKey.toBase58(),
|
|
1465
|
-
privateKey: import_bs583.default.encode(keypair.secretKey),
|
|
1466
|
-
mnemonic
|
|
1467
|
-
};
|
|
1598
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1599
|
+
return this.walletProvider.generate();
|
|
1468
1600
|
}
|
|
1469
1601
|
getAddress() {
|
|
1470
1602
|
return this.cachedAddress;
|
|
@@ -1472,6 +1604,22 @@ var WarpSolanaWallet = class {
|
|
|
1472
1604
|
getPublicKey() {
|
|
1473
1605
|
return this.cachedPublicKey;
|
|
1474
1606
|
}
|
|
1607
|
+
async registerX402Handlers(client) {
|
|
1608
|
+
if (!this.walletProvider) return {};
|
|
1609
|
+
const provider = this.walletProvider;
|
|
1610
|
+
const getKeypair = provider.getKeypairInstance;
|
|
1611
|
+
if (typeof getKeypair !== "function") return {};
|
|
1612
|
+
const keypair = getKeypair();
|
|
1613
|
+
if (!keypair || !keypair.secretKey) return {};
|
|
1614
|
+
const signer = await (0, import_kit.createKeyPairSignerFromBytes)(keypair.secretKey);
|
|
1615
|
+
const handlers = {};
|
|
1616
|
+
for (const network of SupportedX402SolanaNetworks) {
|
|
1617
|
+
handlers[network] = () => {
|
|
1618
|
+
(0, import_client.registerExactSvmScheme)(client, { signer });
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
return handlers;
|
|
1622
|
+
}
|
|
1475
1623
|
};
|
|
1476
1624
|
|
|
1477
1625
|
// src/chains/common.ts
|
|
@@ -1496,16 +1644,16 @@ var createSolanaAdapter = (chainName, chainInfos) => {
|
|
|
1496
1644
|
|
|
1497
1645
|
// src/chains/solana.ts
|
|
1498
1646
|
var NativeTokenSol = {
|
|
1499
|
-
chain:
|
|
1647
|
+
chain: import_warps9.WarpChainName.Solana,
|
|
1500
1648
|
identifier: "SOL",
|
|
1501
1649
|
symbol: "SOL",
|
|
1502
1650
|
name: "Solana",
|
|
1503
1651
|
decimals: 9,
|
|
1504
1652
|
logoUrl: "https://joai.ai/images/tokens/sol.svg"
|
|
1505
1653
|
};
|
|
1506
|
-
var
|
|
1654
|
+
var SolanaAdapter = createSolanaAdapter(import_warps9.WarpChainName.Solana, {
|
|
1507
1655
|
mainnet: {
|
|
1508
|
-
name:
|
|
1656
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1509
1657
|
displayName: "Solana Mainnet",
|
|
1510
1658
|
chainId: "101",
|
|
1511
1659
|
blockTime: 400,
|
|
@@ -1515,7 +1663,7 @@ var getSolanaAdapter = createSolanaAdapter(import_warps8.WarpChainName.Solana, {
|
|
|
1515
1663
|
nativeToken: NativeTokenSol
|
|
1516
1664
|
},
|
|
1517
1665
|
testnet: {
|
|
1518
|
-
name:
|
|
1666
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1519
1667
|
displayName: "Solana Testnet",
|
|
1520
1668
|
chainId: "103",
|
|
1521
1669
|
blockTime: 400,
|
|
@@ -1525,7 +1673,7 @@ var getSolanaAdapter = createSolanaAdapter(import_warps8.WarpChainName.Solana, {
|
|
|
1525
1673
|
nativeToken: NativeTokenSol
|
|
1526
1674
|
},
|
|
1527
1675
|
devnet: {
|
|
1528
|
-
name:
|
|
1676
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1529
1677
|
displayName: "Solana Devnet",
|
|
1530
1678
|
chainId: "103",
|
|
1531
1679
|
blockTime: 400,
|
|
@@ -1540,10 +1688,12 @@ var getSolanaAdapter = createSolanaAdapter(import_warps8.WarpChainName.Solana, {
|
|
|
1540
1688
|
ExplorerUrls,
|
|
1541
1689
|
KnownTokens,
|
|
1542
1690
|
NativeTokenSol,
|
|
1691
|
+
SolanaAdapter,
|
|
1543
1692
|
SolanaExplorerMap,
|
|
1544
1693
|
SolanaExplorerNames,
|
|
1545
1694
|
SolanaExplorerUrls,
|
|
1546
1695
|
SolanaExplorers,
|
|
1696
|
+
SupportedX402SolanaNetworks,
|
|
1547
1697
|
WarpSolanaConstants,
|
|
1548
1698
|
WarpSolanaDataLoader,
|
|
1549
1699
|
WarpSolanaExecutor,
|
|
@@ -1551,8 +1701,8 @@ var getSolanaAdapter = createSolanaAdapter(import_warps8.WarpChainName.Solana, {
|
|
|
1551
1701
|
WarpSolanaOutput,
|
|
1552
1702
|
WarpSolanaSerializer,
|
|
1553
1703
|
WarpSolanaWallet,
|
|
1704
|
+
X402SolanaNetworkIdentifiers,
|
|
1554
1705
|
findKnownTokenById,
|
|
1555
|
-
getKnownTokensForChain
|
|
1556
|
-
getSolanaAdapter
|
|
1706
|
+
getKnownTokensForChain
|
|
1557
1707
|
});
|
|
1558
1708
|
//# sourceMappingURL=index.js.map
|