@vleap/warps-adapter-solana 0.1.0-beta.5 → 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 +24 -23
- package/dist/index.d.ts +24 -23
- package/dist/index.js +271 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +268 -88
- 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 {
|
|
@@ -166,25 +170,22 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
166
170
|
private config;
|
|
167
171
|
private chain;
|
|
168
172
|
private connection;
|
|
173
|
+
private walletProvider;
|
|
174
|
+
private cachedAddress;
|
|
175
|
+
private cachedPublicKey;
|
|
169
176
|
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
177
|
+
private createProvider;
|
|
178
|
+
private initializeCache;
|
|
170
179
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
171
180
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
172
181
|
signMessage(message: string): Promise<string>;
|
|
173
182
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
174
183
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
175
|
-
create(mnemonic: string):
|
|
176
|
-
|
|
177
|
-
privateKey: string;
|
|
178
|
-
mnemonic: string;
|
|
179
|
-
};
|
|
180
|
-
generate(): {
|
|
181
|
-
address: string;
|
|
182
|
-
privateKey: string;
|
|
183
|
-
mnemonic: string;
|
|
184
|
-
};
|
|
184
|
+
create(mnemonic: string): WarpWalletDetails;
|
|
185
|
+
generate(): WarpWalletDetails;
|
|
185
186
|
getAddress(): string | null;
|
|
186
187
|
getPublicKey(): string | null;
|
|
187
|
-
|
|
188
|
+
registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
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 {
|
|
@@ -166,25 +170,22 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
166
170
|
private config;
|
|
167
171
|
private chain;
|
|
168
172
|
private connection;
|
|
173
|
+
private walletProvider;
|
|
174
|
+
private cachedAddress;
|
|
175
|
+
private cachedPublicKey;
|
|
169
176
|
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
177
|
+
private createProvider;
|
|
178
|
+
private initializeCache;
|
|
170
179
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
171
180
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
172
181
|
signMessage(message: string): Promise<string>;
|
|
173
182
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
174
183
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
175
|
-
create(mnemonic: string):
|
|
176
|
-
|
|
177
|
-
privateKey: string;
|
|
178
|
-
mnemonic: string;
|
|
179
|
-
};
|
|
180
|
-
generate(): {
|
|
181
|
-
address: string;
|
|
182
|
-
privateKey: string;
|
|
183
|
-
mnemonic: string;
|
|
184
|
-
};
|
|
184
|
+
create(mnemonic: string): WarpWalletDetails;
|
|
185
|
+
generate(): WarpWalletDetails;
|
|
185
186
|
getAddress(): string | null;
|
|
186
187
|
getPublicKey(): string | null;
|
|
187
|
-
|
|
188
|
+
registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
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,20 +1278,43 @@ var WarpSolanaExplorer = class {
|
|
|
1271
1278
|
};
|
|
1272
1279
|
|
|
1273
1280
|
// src/WarpSolanaWallet.ts
|
|
1274
|
-
var
|
|
1275
|
-
var
|
|
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");
|
|
1285
|
+
|
|
1286
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
1276
1287
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
1277
1288
|
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
1289
|
+
var import_web35 = require("@solana/web3.js");
|
|
1290
|
+
var import_warps6 = require("@vleap/warps");
|
|
1278
1291
|
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1279
|
-
var
|
|
1280
|
-
constructor(config, chain) {
|
|
1292
|
+
var MnemonicWalletProvider = class {
|
|
1293
|
+
constructor(config, chain, connection) {
|
|
1281
1294
|
this.config = config;
|
|
1282
1295
|
this.chain = chain;
|
|
1283
|
-
|
|
1284
|
-
this.
|
|
1296
|
+
this.connection = connection;
|
|
1297
|
+
this.keypair = null;
|
|
1298
|
+
}
|
|
1299
|
+
async getAddress() {
|
|
1300
|
+
const address = (0, import_warps6.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1301
|
+
if (address) return address;
|
|
1302
|
+
try {
|
|
1303
|
+
const keypair = this.getKeypair();
|
|
1304
|
+
return keypair.publicKey.toBase58();
|
|
1305
|
+
} catch {
|
|
1306
|
+
return null;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
async getPublicKey() {
|
|
1310
|
+
try {
|
|
1311
|
+
const keypair = this.getKeypair();
|
|
1312
|
+
return keypair.publicKey.toBase58();
|
|
1313
|
+
} catch {
|
|
1314
|
+
return null;
|
|
1315
|
+
}
|
|
1285
1316
|
}
|
|
1286
1317
|
async signTransaction(tx) {
|
|
1287
|
-
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1288
1318
|
const keypair = this.getKeypair();
|
|
1289
1319
|
if (tx instanceof import_web35.VersionedTransaction) {
|
|
1290
1320
|
tx.sign([keypair]);
|
|
@@ -1311,27 +1341,113 @@ var WarpSolanaWallet = class {
|
|
|
1311
1341
|
}
|
|
1312
1342
|
throw new Error("Invalid transaction format");
|
|
1313
1343
|
}
|
|
1314
|
-
async
|
|
1315
|
-
if (txs.length === 0) return [];
|
|
1344
|
+
async signMessage(message) {
|
|
1316
1345
|
const keypair = this.getKeypair();
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1346
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1347
|
+
const nacl = await import("tweetnacl");
|
|
1348
|
+
const secretKey = keypair.secretKey;
|
|
1349
|
+
if (secretKey.length !== 64) {
|
|
1350
|
+
throw new Error(`Invalid secret key length: expected 64, got ${secretKey.length}`);
|
|
1351
|
+
}
|
|
1352
|
+
const privateKeySlice = secretKey.slice(0, 32);
|
|
1353
|
+
const privateKeyBytes = new Uint8Array(privateKeySlice);
|
|
1354
|
+
if (privateKeyBytes.length !== 32) {
|
|
1355
|
+
throw new Error(`Invalid private key length: expected 32, got ${privateKeyBytes.length}`);
|
|
1356
|
+
}
|
|
1357
|
+
const signature = nacl.sign.detached(messageBytes, privateKeyBytes);
|
|
1358
|
+
return import_bs582.default.encode(signature);
|
|
1359
|
+
}
|
|
1360
|
+
getKeypairInstance() {
|
|
1361
|
+
return this.getKeypair();
|
|
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
|
+
}
|
|
1384
|
+
getKeypair() {
|
|
1385
|
+
if (this.keypair) return this.keypair;
|
|
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);
|
|
1329
1443
|
transaction.sign(keypair);
|
|
1330
|
-
return { ...tx, transaction: transaction.serialize() };
|
|
1444
|
+
return { ...tx, transaction: transaction.serialize(), signature: transaction.signature };
|
|
1445
|
+
} catch {
|
|
1446
|
+
throw new Error("Invalid transaction format");
|
|
1331
1447
|
}
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
throw new Error("Invalid transaction format");
|
|
1335
1451
|
}
|
|
1336
1452
|
async signMessage(message) {
|
|
1337
1453
|
const keypair = this.getKeypair();
|
|
@@ -1347,28 +1463,118 @@ var WarpSolanaWallet = class {
|
|
|
1347
1463
|
throw new Error(`Invalid private key length: expected 32, got ${privateKeyBytes.length}`);
|
|
1348
1464
|
}
|
|
1349
1465
|
const signature = nacl.sign.detached(messageBytes, privateKeyBytes);
|
|
1350
|
-
return
|
|
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");
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
// src/WarpSolanaWallet.ts
|
|
1517
|
+
var WarpSolanaWallet = class {
|
|
1518
|
+
constructor(config, chain) {
|
|
1519
|
+
this.config = config;
|
|
1520
|
+
this.chain = chain;
|
|
1521
|
+
this.cachedAddress = null;
|
|
1522
|
+
this.cachedPublicKey = null;
|
|
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();
|
|
1526
|
+
this.initializeCache();
|
|
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
|
+
}
|
|
1539
|
+
initializeCache() {
|
|
1540
|
+
(0, import_warps8.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1541
|
+
this.cachedAddress = cache.address;
|
|
1542
|
+
this.cachedPublicKey = cache.publicKey;
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
async signTransaction(tx) {
|
|
1546
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1547
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1548
|
+
return await this.walletProvider.signTransaction(tx);
|
|
1549
|
+
}
|
|
1550
|
+
async signTransactions(txs) {
|
|
1551
|
+
if (txs.length === 0) return [];
|
|
1552
|
+
return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
|
|
1553
|
+
}
|
|
1554
|
+
async signMessage(message) {
|
|
1555
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1556
|
+
return await this.walletProvider.signMessage(message);
|
|
1351
1557
|
}
|
|
1352
1558
|
async sendTransaction(tx) {
|
|
1353
1559
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1354
1560
|
let transaction;
|
|
1355
|
-
if (tx instanceof
|
|
1561
|
+
if (tx instanceof import_web37.VersionedTransaction) {
|
|
1356
1562
|
transaction = tx;
|
|
1357
|
-
} else if (tx instanceof
|
|
1563
|
+
} else if (tx instanceof import_web37.Transaction) {
|
|
1358
1564
|
transaction = tx;
|
|
1359
1565
|
} else if (tx.transaction) {
|
|
1360
|
-
if (tx.transaction instanceof
|
|
1566
|
+
if (tx.transaction instanceof import_web37.Transaction) {
|
|
1361
1567
|
transaction = tx.transaction;
|
|
1362
|
-
} else if (tx.transaction instanceof
|
|
1568
|
+
} else if (tx.transaction instanceof import_web37.VersionedTransaction) {
|
|
1363
1569
|
transaction = tx.transaction;
|
|
1364
1570
|
} else if (typeof tx.transaction === "object") {
|
|
1365
1571
|
try {
|
|
1366
|
-
transaction =
|
|
1572
|
+
transaction = import_web37.Transaction.from(tx.transaction);
|
|
1367
1573
|
} catch {
|
|
1368
1574
|
throw new Error("Invalid transaction format");
|
|
1369
1575
|
}
|
|
1370
1576
|
} else if (Buffer.isBuffer(tx.transaction) || typeof tx.transaction === "string") {
|
|
1371
|
-
transaction =
|
|
1577
|
+
transaction = import_web37.Transaction.from(tx.transaction);
|
|
1372
1578
|
} else {
|
|
1373
1579
|
throw new Error("Transaction must be signed before sending");
|
|
1374
1580
|
}
|
|
@@ -1385,65 +1591,34 @@ var WarpSolanaWallet = class {
|
|
|
1385
1591
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1386
1592
|
}
|
|
1387
1593
|
create(mnemonic) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
return {
|
|
1391
|
-
address: keypair.publicKey.toBase58(),
|
|
1392
|
-
privateKey: import_bs582.default.encode(keypair.secretKey),
|
|
1393
|
-
mnemonic
|
|
1394
|
-
};
|
|
1594
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1595
|
+
return this.walletProvider.create(mnemonic);
|
|
1395
1596
|
}
|
|
1396
1597
|
generate() {
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
const mnemonic = bip39.entropyToMnemonic(entropy, import_english.wordlist);
|
|
1400
|
-
return {
|
|
1401
|
-
address: keypair.publicKey.toBase58(),
|
|
1402
|
-
privateKey: import_bs582.default.encode(keypair.secretKey),
|
|
1403
|
-
mnemonic
|
|
1404
|
-
};
|
|
1598
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1599
|
+
return this.walletProvider.generate();
|
|
1405
1600
|
}
|
|
1406
1601
|
getAddress() {
|
|
1407
|
-
|
|
1408
|
-
const keypair = this.getKeypair();
|
|
1409
|
-
return keypair.publicKey.toBase58();
|
|
1410
|
-
} catch {
|
|
1411
|
-
return null;
|
|
1412
|
-
}
|
|
1602
|
+
return this.cachedAddress;
|
|
1413
1603
|
}
|
|
1414
1604
|
getPublicKey() {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
return import_web35.Keypair.fromSeed(secretKey);
|
|
1431
|
-
} else {
|
|
1432
|
-
throw new Error(`Invalid private key length: expected 32 or 64 bytes, got ${secretKey.length}`);
|
|
1433
|
-
}
|
|
1434
|
-
} catch (error) {
|
|
1435
|
-
if (error instanceof Error) {
|
|
1436
|
-
throw new Error(`Invalid private key format: ${error.message}`);
|
|
1437
|
-
}
|
|
1438
|
-
throw new Error("Invalid private key format");
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
const mnemonic = (0, import_warps6.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1442
|
-
if (mnemonic) {
|
|
1443
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1444
|
-
return import_web35.Keypair.fromSeed(seed.slice(0, 32));
|
|
1605
|
+
return this.cachedPublicKey;
|
|
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
|
+
};
|
|
1445
1620
|
}
|
|
1446
|
-
|
|
1621
|
+
return handlers;
|
|
1447
1622
|
}
|
|
1448
1623
|
};
|
|
1449
1624
|
|
|
@@ -1469,16 +1644,16 @@ var createSolanaAdapter = (chainName, chainInfos) => {
|
|
|
1469
1644
|
|
|
1470
1645
|
// src/chains/solana.ts
|
|
1471
1646
|
var NativeTokenSol = {
|
|
1472
|
-
chain:
|
|
1647
|
+
chain: import_warps9.WarpChainName.Solana,
|
|
1473
1648
|
identifier: "SOL",
|
|
1474
1649
|
symbol: "SOL",
|
|
1475
1650
|
name: "Solana",
|
|
1476
1651
|
decimals: 9,
|
|
1477
1652
|
logoUrl: "https://joai.ai/images/tokens/sol.svg"
|
|
1478
1653
|
};
|
|
1479
|
-
var
|
|
1654
|
+
var SolanaAdapter = createSolanaAdapter(import_warps9.WarpChainName.Solana, {
|
|
1480
1655
|
mainnet: {
|
|
1481
|
-
name:
|
|
1656
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1482
1657
|
displayName: "Solana Mainnet",
|
|
1483
1658
|
chainId: "101",
|
|
1484
1659
|
blockTime: 400,
|
|
@@ -1488,7 +1663,7 @@ var getSolanaAdapter = createSolanaAdapter(import_warps7.WarpChainName.Solana, {
|
|
|
1488
1663
|
nativeToken: NativeTokenSol
|
|
1489
1664
|
},
|
|
1490
1665
|
testnet: {
|
|
1491
|
-
name:
|
|
1666
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1492
1667
|
displayName: "Solana Testnet",
|
|
1493
1668
|
chainId: "103",
|
|
1494
1669
|
blockTime: 400,
|
|
@@ -1498,7 +1673,7 @@ var getSolanaAdapter = createSolanaAdapter(import_warps7.WarpChainName.Solana, {
|
|
|
1498
1673
|
nativeToken: NativeTokenSol
|
|
1499
1674
|
},
|
|
1500
1675
|
devnet: {
|
|
1501
|
-
name:
|
|
1676
|
+
name: import_warps9.WarpChainName.Solana,
|
|
1502
1677
|
displayName: "Solana Devnet",
|
|
1503
1678
|
chainId: "103",
|
|
1504
1679
|
blockTime: 400,
|
|
@@ -1513,10 +1688,12 @@ var getSolanaAdapter = createSolanaAdapter(import_warps7.WarpChainName.Solana, {
|
|
|
1513
1688
|
ExplorerUrls,
|
|
1514
1689
|
KnownTokens,
|
|
1515
1690
|
NativeTokenSol,
|
|
1691
|
+
SolanaAdapter,
|
|
1516
1692
|
SolanaExplorerMap,
|
|
1517
1693
|
SolanaExplorerNames,
|
|
1518
1694
|
SolanaExplorerUrls,
|
|
1519
1695
|
SolanaExplorers,
|
|
1696
|
+
SupportedX402SolanaNetworks,
|
|
1520
1697
|
WarpSolanaConstants,
|
|
1521
1698
|
WarpSolanaDataLoader,
|
|
1522
1699
|
WarpSolanaExecutor,
|
|
@@ -1524,8 +1701,8 @@ var getSolanaAdapter = createSolanaAdapter(import_warps7.WarpChainName.Solana, {
|
|
|
1524
1701
|
WarpSolanaOutput,
|
|
1525
1702
|
WarpSolanaSerializer,
|
|
1526
1703
|
WarpSolanaWallet,
|
|
1704
|
+
X402SolanaNetworkIdentifiers,
|
|
1527
1705
|
findKnownTokenById,
|
|
1528
|
-
getKnownTokensForChain
|
|
1529
|
-
getSolanaAdapter
|
|
1706
|
+
getKnownTokensForChain
|
|
1530
1707
|
});
|
|
1531
1708
|
//# sourceMappingURL=index.js.map
|