@vleap/warps-adapter-near 0.1.0-beta.11 → 0.1.0-beta.13
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 +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +148 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChainAsset, ChainAdapterFactory,
|
|
1
|
+
import { WarpChainAsset, ChainAdapterFactory, WarpChainName, 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, WarpWalletProvider } from '@vleap/warps';
|
|
2
2
|
|
|
3
3
|
declare const NativeTokenNear: WarpChainAsset;
|
|
4
4
|
declare const NearAdapter: ChainAdapterFactory;
|
|
@@ -36,9 +36,9 @@ declare const NearExplorerNames: {
|
|
|
36
36
|
declare const NearExplorerUrls: Record<ExplorerName, string>;
|
|
37
37
|
|
|
38
38
|
declare const NearTokens: WarpChainAsset[];
|
|
39
|
-
declare const KnownTokens: Record<
|
|
40
|
-
declare const findKnownTokenById: (chain:
|
|
41
|
-
declare const getKnownTokensForChain: (chainName:
|
|
39
|
+
declare const KnownTokens: Partial<Record<WarpChainName, Record<string, WarpChainAsset[]>>>;
|
|
40
|
+
declare const findKnownTokenById: (chain: WarpChainName, env: WarpChainEnv, id: string) => WarpChainAsset | null;
|
|
41
|
+
declare const getKnownTokensForChain: (chainName: WarpChainName, env?: string) => WarpChainAsset[];
|
|
42
42
|
|
|
43
43
|
declare class WarpNearDataLoader implements AdapterWarpDataLoader {
|
|
44
44
|
private readonly config;
|
|
@@ -140,8 +140,10 @@ declare class WarpNearWallet implements AdapterWarpWallet {
|
|
|
140
140
|
signMessage(message: string): Promise<string>;
|
|
141
141
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
142
142
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
importFromMnemonic(mnemonic: string): Promise<WarpWalletDetails>;
|
|
144
|
+
importFromPrivateKey(privateKey: string): Promise<WarpWalletDetails>;
|
|
145
|
+
export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
146
|
+
generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
145
147
|
getAddress(): string | null;
|
|
146
148
|
getPublicKey(): string | null;
|
|
147
149
|
private createProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChainAsset, ChainAdapterFactory,
|
|
1
|
+
import { WarpChainAsset, ChainAdapterFactory, WarpChainName, 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, WarpWalletProvider } from '@vleap/warps';
|
|
2
2
|
|
|
3
3
|
declare const NativeTokenNear: WarpChainAsset;
|
|
4
4
|
declare const NearAdapter: ChainAdapterFactory;
|
|
@@ -36,9 +36,9 @@ declare const NearExplorerNames: {
|
|
|
36
36
|
declare const NearExplorerUrls: Record<ExplorerName, string>;
|
|
37
37
|
|
|
38
38
|
declare const NearTokens: WarpChainAsset[];
|
|
39
|
-
declare const KnownTokens: Record<
|
|
40
|
-
declare const findKnownTokenById: (chain:
|
|
41
|
-
declare const getKnownTokensForChain: (chainName:
|
|
39
|
+
declare const KnownTokens: Partial<Record<WarpChainName, Record<string, WarpChainAsset[]>>>;
|
|
40
|
+
declare const findKnownTokenById: (chain: WarpChainName, env: WarpChainEnv, id: string) => WarpChainAsset | null;
|
|
41
|
+
declare const getKnownTokensForChain: (chainName: WarpChainName, env?: string) => WarpChainAsset[];
|
|
42
42
|
|
|
43
43
|
declare class WarpNearDataLoader implements AdapterWarpDataLoader {
|
|
44
44
|
private readonly config;
|
|
@@ -140,8 +140,10 @@ declare class WarpNearWallet implements AdapterWarpWallet {
|
|
|
140
140
|
signMessage(message: string): Promise<string>;
|
|
141
141
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
142
142
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
importFromMnemonic(mnemonic: string): Promise<WarpWalletDetails>;
|
|
144
|
+
importFromPrivateKey(privateKey: string): Promise<WarpWalletDetails>;
|
|
145
|
+
export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
146
|
+
generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
|
|
145
147
|
getAddress(): string | null;
|
|
146
148
|
getPublicKey(): string | null;
|
|
147
149
|
private createProvider;
|
package/dist/index.js
CHANGED
|
@@ -51,8 +51,11 @@ __export(index_exports, {
|
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(index_exports);
|
|
53
53
|
|
|
54
|
+
// src/chains/near.ts
|
|
55
|
+
var import_warps10 = require("@vleap/warps");
|
|
56
|
+
|
|
54
57
|
// src/WarpNearDataLoader.ts
|
|
55
|
-
var
|
|
58
|
+
var import_warps2 = require("@vleap/warps");
|
|
56
59
|
var import_near_api_js = require("near-api-js");
|
|
57
60
|
|
|
58
61
|
// src/constants.ts
|
|
@@ -93,9 +96,10 @@ var NearExplorerNames = {
|
|
|
93
96
|
var NearExplorerUrls = ExplorerUrls;
|
|
94
97
|
|
|
95
98
|
// src/tokens.ts
|
|
99
|
+
var import_warps = require("@vleap/warps");
|
|
96
100
|
var NearTokens = [];
|
|
97
101
|
var KnownTokens = {
|
|
98
|
-
|
|
102
|
+
[import_warps.WarpChainName.Near]: {
|
|
99
103
|
mainnet: NearTokens,
|
|
100
104
|
testnet: NearTokens,
|
|
101
105
|
devnet: NearTokens
|
|
@@ -114,8 +118,8 @@ var WarpNearDataLoader = class {
|
|
|
114
118
|
constructor(config, chain) {
|
|
115
119
|
this.config = config;
|
|
116
120
|
this.chain = chain;
|
|
117
|
-
this.cache = new
|
|
118
|
-
const providerConfig = (0,
|
|
121
|
+
this.cache = new import_warps2.WarpCache(config.cache?.type);
|
|
122
|
+
const providerConfig = (0, import_warps2.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
119
123
|
this.nearConfig = {
|
|
120
124
|
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
121
125
|
nodeUrl: providerConfig.url,
|
|
@@ -171,7 +175,7 @@ var WarpNearDataLoader = class {
|
|
|
171
175
|
if (identifier === this.chain.nativeToken.identifier || identifier === WarpNearConstants.NativeToken.Identifier) {
|
|
172
176
|
return this.chain.nativeToken;
|
|
173
177
|
}
|
|
174
|
-
const cacheKey =
|
|
178
|
+
const cacheKey = import_warps2.WarpCacheKey.Asset(this.config.env, this.chain.name, identifier);
|
|
175
179
|
const cachedAsset = this.cache.get(cacheKey);
|
|
176
180
|
if (cachedAsset) {
|
|
177
181
|
return cachedAsset;
|
|
@@ -206,7 +210,7 @@ var WarpNearDataLoader = class {
|
|
|
206
210
|
decimals: metadata.decimals || WarpNearConstants.NativeToken.Decimals,
|
|
207
211
|
logoUrl: metadata.icon || ""
|
|
208
212
|
};
|
|
209
|
-
this.cache.set(cacheKey, asset,
|
|
213
|
+
this.cache.set(cacheKey, asset, import_warps2.CacheTtl.OneHour);
|
|
210
214
|
return asset;
|
|
211
215
|
} catch {
|
|
212
216
|
const asset = {
|
|
@@ -259,18 +263,18 @@ var WarpNearDataLoader = class {
|
|
|
259
263
|
};
|
|
260
264
|
|
|
261
265
|
// src/WarpNearExecutor.ts
|
|
262
|
-
var
|
|
266
|
+
var import_warps5 = require("@vleap/warps");
|
|
263
267
|
var import_near_api_js3 = require("near-api-js");
|
|
264
268
|
|
|
265
269
|
// src/WarpNearOutput.ts
|
|
266
|
-
var
|
|
270
|
+
var import_warps4 = require("@vleap/warps");
|
|
267
271
|
var import_near_api_js2 = require("near-api-js");
|
|
268
272
|
|
|
269
273
|
// src/WarpNearSerializer.ts
|
|
270
|
-
var
|
|
274
|
+
var import_warps3 = require("@vleap/warps");
|
|
271
275
|
var WarpNearSerializer = class {
|
|
272
276
|
constructor() {
|
|
273
|
-
this.coreSerializer = new
|
|
277
|
+
this.coreSerializer = new import_warps3.WarpSerializer();
|
|
274
278
|
}
|
|
275
279
|
typedToString(value) {
|
|
276
280
|
if (typeof value === "string") {
|
|
@@ -303,15 +307,15 @@ var WarpNearSerializer = class {
|
|
|
303
307
|
if (typeof value === "object" && value !== null && "identifier" in value && "amount" in value) {
|
|
304
308
|
const asset = value;
|
|
305
309
|
if (asset.decimals !== void 0) {
|
|
306
|
-
return `asset:${asset.identifier}${
|
|
310
|
+
return `asset:${asset.identifier}${import_warps3.WarpConstants.ArgCompositeSeparator}${asset.amount.toString()}${import_warps3.WarpConstants.ArgCompositeSeparator}${asset.decimals}`;
|
|
307
311
|
}
|
|
308
|
-
return `asset:${asset.identifier}${
|
|
312
|
+
return `asset:${asset.identifier}${import_warps3.WarpConstants.ArgCompositeSeparator}${asset.amount.toString()}`;
|
|
309
313
|
}
|
|
310
314
|
if (Array.isArray(value)) {
|
|
311
315
|
if (value.length === 0) return `list:string:`;
|
|
312
|
-
const types = value.map((item) => this.typedToString(item).split(
|
|
316
|
+
const types = value.map((item) => this.typedToString(item).split(import_warps3.WarpConstants.ArgParamsSeparator)[0]);
|
|
313
317
|
const type = types[0];
|
|
314
|
-
const values = value.map((item) => this.typedToString(item).split(
|
|
318
|
+
const values = value.map((item) => this.typedToString(item).split(import_warps3.WarpConstants.ArgParamsSeparator)[1]);
|
|
315
319
|
return `list:${type}:${values.join(",")}`;
|
|
316
320
|
}
|
|
317
321
|
if (value === null || value === void 0) {
|
|
@@ -321,8 +325,8 @@ var WarpNearSerializer = class {
|
|
|
321
325
|
}
|
|
322
326
|
typedToNative(value) {
|
|
323
327
|
const stringValue = this.typedToString(value);
|
|
324
|
-
const [type, ...valueParts] = stringValue.split(
|
|
325
|
-
const nativeValue = valueParts.join(
|
|
328
|
+
const [type, ...valueParts] = stringValue.split(import_warps3.WarpConstants.ArgParamsSeparator);
|
|
329
|
+
const nativeValue = valueParts.join(import_warps3.WarpConstants.ArgParamsSeparator);
|
|
326
330
|
return [type, this.parseNativeValue(type, nativeValue)];
|
|
327
331
|
}
|
|
328
332
|
nativeToTyped(type, value) {
|
|
@@ -378,7 +382,7 @@ var WarpNearSerializer = class {
|
|
|
378
382
|
}
|
|
379
383
|
}
|
|
380
384
|
stringToTyped(value) {
|
|
381
|
-
const parts = value.split(
|
|
385
|
+
const parts = value.split(import_warps3.WarpConstants.ArgParamsSeparator, 2);
|
|
382
386
|
if (parts.length < 2) {
|
|
383
387
|
return value;
|
|
384
388
|
}
|
|
@@ -400,7 +404,7 @@ var WarpNearSerializer = class {
|
|
|
400
404
|
case "hex":
|
|
401
405
|
return stringValue;
|
|
402
406
|
case "asset":
|
|
403
|
-
const assetParts = stringValue.split(
|
|
407
|
+
const assetParts = stringValue.split(import_warps3.WarpConstants.ArgCompositeSeparator);
|
|
404
408
|
const identifier = assetParts[0] || "";
|
|
405
409
|
const amount = assetParts[1] ? BigInt(assetParts[1]) : 0n;
|
|
406
410
|
const decimals = assetParts[2] ? parseInt(assetParts[2], 10) : void 0;
|
|
@@ -443,17 +447,17 @@ var WarpNearOutput = class {
|
|
|
443
447
|
this.config = config;
|
|
444
448
|
this.chain = chain;
|
|
445
449
|
this.serializer = new WarpNearSerializer();
|
|
446
|
-
const providerConfig = (0,
|
|
450
|
+
const providerConfig = (0, import_warps4.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
447
451
|
this.nearConfig = {
|
|
448
452
|
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
449
453
|
nodeUrl: providerConfig.url,
|
|
450
454
|
keyStore: new import_near_api_js2.keyStores.InMemoryKeyStore()
|
|
451
455
|
};
|
|
452
|
-
this.cache = new
|
|
456
|
+
this.cache = new import_warps4.WarpCache(config.cache?.type);
|
|
453
457
|
}
|
|
454
458
|
async getActionExecution(warp, actionIndex, tx) {
|
|
455
|
-
const inputs = this.cache.get(
|
|
456
|
-
const resolvedInputs = (0,
|
|
459
|
+
const inputs = this.cache.get(import_warps4.WarpCacheKey.WarpExecutable(this.config.env, warp.meta?.hash || "", actionIndex)) ?? [];
|
|
460
|
+
const resolvedInputs = (0, import_warps4.extractResolvedInputValues)(inputs);
|
|
457
461
|
if (!tx) {
|
|
458
462
|
return this.createFailedExecution(warp, actionIndex, resolvedInputs);
|
|
459
463
|
}
|
|
@@ -470,7 +474,7 @@ var WarpNearOutput = class {
|
|
|
470
474
|
status: "error",
|
|
471
475
|
warp,
|
|
472
476
|
action: actionIndex,
|
|
473
|
-
user: (0,
|
|
477
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
474
478
|
txHash: "",
|
|
475
479
|
tx: null,
|
|
476
480
|
next: null,
|
|
@@ -490,7 +494,7 @@ var WarpNearOutput = class {
|
|
|
490
494
|
status: success ? "success" : "error",
|
|
491
495
|
warp,
|
|
492
496
|
action: actionIndex,
|
|
493
|
-
user: (0,
|
|
497
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
494
498
|
txHash: transactionHash,
|
|
495
499
|
tx,
|
|
496
500
|
next: null,
|
|
@@ -517,7 +521,7 @@ var WarpNearOutput = class {
|
|
|
517
521
|
status: success ? "success" : "error",
|
|
518
522
|
warp,
|
|
519
523
|
action: actionIndex,
|
|
520
|
-
user: (0,
|
|
524
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
521
525
|
txHash: hash,
|
|
522
526
|
tx: {
|
|
523
527
|
hash,
|
|
@@ -552,8 +556,8 @@ var WarpNearOutput = class {
|
|
|
552
556
|
return value;
|
|
553
557
|
};
|
|
554
558
|
for (const [key, path] of Object.entries(warp.output)) {
|
|
555
|
-
if (path.startsWith(
|
|
556
|
-
const currentActionIndex = (0,
|
|
559
|
+
if (path.startsWith(import_warps4.WarpConstants.Transform.Prefix)) continue;
|
|
560
|
+
const currentActionIndex = (0, import_warps4.parseOutputOutIndex)(path);
|
|
557
561
|
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
558
562
|
output[key] = null;
|
|
559
563
|
continue;
|
|
@@ -564,7 +568,7 @@ var WarpNearOutput = class {
|
|
|
564
568
|
output[key] = path;
|
|
565
569
|
}
|
|
566
570
|
}
|
|
567
|
-
return { values, output: await (0,
|
|
571
|
+
return { values, output: await (0, import_warps4.evaluateOutputCommon)(warp, output, actionIndex, inputs, this.serializer.coreSerializer, this.config) };
|
|
568
572
|
}
|
|
569
573
|
async getTransactionStatus(txHash) {
|
|
570
574
|
try {
|
|
@@ -608,7 +612,7 @@ var WarpNearExecutor = class {
|
|
|
608
612
|
this.config = config;
|
|
609
613
|
this.chain = chain;
|
|
610
614
|
this.serializer = new WarpNearSerializer();
|
|
611
|
-
const providerConfig = (0,
|
|
615
|
+
const providerConfig = (0, import_warps5.getProviderConfig)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
612
616
|
this.nearConfig = {
|
|
613
617
|
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
614
618
|
nodeUrl: providerConfig.url,
|
|
@@ -617,7 +621,7 @@ var WarpNearExecutor = class {
|
|
|
617
621
|
this.output = new WarpNearOutput(config, this.chain);
|
|
618
622
|
}
|
|
619
623
|
async createTransaction(executable) {
|
|
620
|
-
const action = (0,
|
|
624
|
+
const action = (0, import_warps5.getWarpActionByIndex)(executable.warp, executable.action);
|
|
621
625
|
let tx = null;
|
|
622
626
|
if (action.type === "transfer") {
|
|
623
627
|
tx = await this.createTransferTransaction(executable);
|
|
@@ -632,7 +636,7 @@ var WarpNearExecutor = class {
|
|
|
632
636
|
return tx;
|
|
633
637
|
}
|
|
634
638
|
async createTransferTransaction(executable) {
|
|
635
|
-
const userWallet = (0,
|
|
639
|
+
const userWallet = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
636
640
|
if (!userWallet) throw new Error("WarpNearExecutor: createTransfer - user address not set");
|
|
637
641
|
if (!executable.destination) throw new Error("WarpNearExecutor: Destination address is required");
|
|
638
642
|
if (executable.transfers && executable.transfers.length > 0) {
|
|
@@ -653,9 +657,9 @@ var WarpNearExecutor = class {
|
|
|
653
657
|
};
|
|
654
658
|
}
|
|
655
659
|
async createContractCallTransaction(executable) {
|
|
656
|
-
const userWallet = (0,
|
|
660
|
+
const userWallet = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
657
661
|
if (!userWallet) throw new Error("WarpNearExecutor: createContractCall - user address not set");
|
|
658
|
-
const action = (0,
|
|
662
|
+
const action = (0, import_warps5.getWarpActionByIndex)(executable.warp, executable.action);
|
|
659
663
|
if (!action || !("func" in action) || !action.func) throw new Error("WarpNearExecutor: Contract action must have a function name");
|
|
660
664
|
if (!executable.destination) throw new Error("WarpNearExecutor: Contract address is required");
|
|
661
665
|
try {
|
|
@@ -714,7 +718,7 @@ var WarpNearExecutor = class {
|
|
|
714
718
|
}
|
|
715
719
|
async createSingleTokenTransfer(executable, transfer) {
|
|
716
720
|
if (!executable.destination) throw new Error("WarpNearExecutor: Destination address is required");
|
|
717
|
-
const userWallet = (0,
|
|
721
|
+
const userWallet = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
718
722
|
if (!userWallet) throw new Error("WarpNearExecutor: User wallet not set");
|
|
719
723
|
const args = {
|
|
720
724
|
receiver_id: executable.destination,
|
|
@@ -736,7 +740,7 @@ var WarpNearExecutor = class {
|
|
|
736
740
|
};
|
|
737
741
|
}
|
|
738
742
|
async executeQuery(executable) {
|
|
739
|
-
const action = (0,
|
|
743
|
+
const action = (0, import_warps5.getWarpActionByIndex)(executable.warp, executable.action);
|
|
740
744
|
if (action.type !== "query") throw new Error(`WarpNearExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
741
745
|
if (!action.func) throw new Error("WarpNearExecutor: Query action must have a function name");
|
|
742
746
|
let queryAddress;
|
|
@@ -762,21 +766,21 @@ var WarpNearExecutor = class {
|
|
|
762
766
|
executable.action,
|
|
763
767
|
executable.resolvedInputs
|
|
764
768
|
);
|
|
765
|
-
const next = (0,
|
|
769
|
+
const next = (0, import_warps5.getNextInfo)(this.config, [], executable.warp, executable.action, output);
|
|
766
770
|
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
767
771
|
const destination = destinationInput?.value || executable.destination;
|
|
768
|
-
const resolvedInputs = (0,
|
|
772
|
+
const resolvedInputs = (0, import_warps5.extractResolvedInputValues)(executable.resolvedInputs);
|
|
769
773
|
return {
|
|
770
774
|
status: "success",
|
|
771
775
|
warp: executable.warp,
|
|
772
776
|
action: executable.action,
|
|
773
|
-
user: (0,
|
|
777
|
+
user: (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name),
|
|
774
778
|
txHash: null,
|
|
775
779
|
tx: null,
|
|
776
780
|
next,
|
|
777
781
|
values,
|
|
778
782
|
output: { ...output, _DATA: result },
|
|
779
|
-
messages: (0,
|
|
783
|
+
messages: (0, import_warps5.applyOutputToMessages)(executable.warp, output, this.config),
|
|
780
784
|
destination,
|
|
781
785
|
resolvedInputs
|
|
782
786
|
};
|
|
@@ -784,12 +788,12 @@ var WarpNearExecutor = class {
|
|
|
784
788
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
785
789
|
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
786
790
|
const destination = destinationInput?.value || executable.destination;
|
|
787
|
-
const resolvedInputs = (0,
|
|
791
|
+
const resolvedInputs = (0, import_warps5.extractResolvedInputValues)(executable.resolvedInputs);
|
|
788
792
|
return {
|
|
789
793
|
status: "error",
|
|
790
794
|
warp: executable.warp,
|
|
791
795
|
action: executable.action,
|
|
792
|
-
user: (0,
|
|
796
|
+
user: (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name),
|
|
793
797
|
txHash: null,
|
|
794
798
|
tx: null,
|
|
795
799
|
next: null,
|
|
@@ -929,14 +933,14 @@ var WarpNearExplorer = class {
|
|
|
929
933
|
};
|
|
930
934
|
|
|
931
935
|
// src/WarpNearWallet.ts
|
|
932
|
-
var
|
|
936
|
+
var import_warps9 = require("@vleap/warps");
|
|
933
937
|
var import_near_api_js6 = require("near-api-js");
|
|
934
938
|
|
|
935
939
|
// src/providers/MnemonicWalletProvider.ts
|
|
936
940
|
var import_crypto = require("@near-js/crypto");
|
|
937
941
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
938
942
|
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
939
|
-
var
|
|
943
|
+
var import_warps6 = require("@vleap/warps");
|
|
940
944
|
var import_bs58 = __toESM(require("bs58"), 1);
|
|
941
945
|
var import_near_api_js4 = require("near-api-js");
|
|
942
946
|
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
@@ -946,7 +950,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
946
950
|
this.keypair = null;
|
|
947
951
|
}
|
|
948
952
|
async getAddress() {
|
|
949
|
-
const address = (0,
|
|
953
|
+
const address = (0, import_warps6.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
950
954
|
if (address) return address;
|
|
951
955
|
try {
|
|
952
956
|
const keypair = this.getKeyPair();
|
|
@@ -978,20 +982,48 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
978
982
|
getKeyPairInstance() {
|
|
979
983
|
return this.getKeyPair();
|
|
980
984
|
}
|
|
981
|
-
|
|
985
|
+
async importFromMnemonic(mnemonic) {
|
|
982
986
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
983
987
|
const secretKey = seed.slice(0, 32);
|
|
984
988
|
const keyPair = import_near_api_js4.KeyPair.fromString(import_bs58.default.encode(secretKey));
|
|
985
989
|
const publicKey = keyPair.getPublicKey();
|
|
986
990
|
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
987
|
-
|
|
991
|
+
const walletDetails = {
|
|
988
992
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
989
993
|
address: accountId,
|
|
990
|
-
privateKey:
|
|
994
|
+
privateKey: keyPair.toString(),
|
|
991
995
|
mnemonic
|
|
992
996
|
};
|
|
997
|
+
(0, import_warps6.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
|
|
998
|
+
return walletDetails;
|
|
999
|
+
}
|
|
1000
|
+
async importFromPrivateKey(privateKey) {
|
|
1001
|
+
const keyPair = import_near_api_js4.KeyPair.fromString(privateKey);
|
|
1002
|
+
const publicKey = keyPair.getPublicKey();
|
|
1003
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
1004
|
+
const walletDetails = {
|
|
1005
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1006
|
+
address: accountId,
|
|
1007
|
+
privateKey: keyPair.toString(),
|
|
1008
|
+
mnemonic: null
|
|
1009
|
+
};
|
|
1010
|
+
(0, import_warps6.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
|
|
1011
|
+
return walletDetails;
|
|
1012
|
+
}
|
|
1013
|
+
async export() {
|
|
1014
|
+
const keypair = this.getKeyPair();
|
|
1015
|
+
const mnemonic = (0, import_warps6.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1016
|
+
const privateKey = (0, import_warps6.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
1017
|
+
const publicKey = keypair.getPublicKey();
|
|
1018
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
1019
|
+
return {
|
|
1020
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1021
|
+
address: accountId,
|
|
1022
|
+
privateKey: privateKey || null,
|
|
1023
|
+
mnemonic: mnemonic || null
|
|
1024
|
+
};
|
|
993
1025
|
}
|
|
994
|
-
generate() {
|
|
1026
|
+
async generate() {
|
|
995
1027
|
const mnemonic = bip39.generateMnemonic(import_english.wordlist);
|
|
996
1028
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
997
1029
|
const secretKey = seed.slice(0, 32);
|
|
@@ -1007,7 +1039,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1007
1039
|
}
|
|
1008
1040
|
getKeyPair() {
|
|
1009
1041
|
if (this.keypair) return this.keypair;
|
|
1010
|
-
const mnemonic = (0,
|
|
1042
|
+
const mnemonic = (0, import_warps6.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1011
1043
|
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
1012
1044
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1013
1045
|
const secretKey = seed.slice(0, 32);
|
|
@@ -1021,7 +1053,7 @@ var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
|
1021
1053
|
// src/providers/PrivateKeyWalletProvider.ts
|
|
1022
1054
|
var import_crypto2 = require("@near-js/crypto");
|
|
1023
1055
|
var bip392 = __toESM(require("@scure/bip39"), 1);
|
|
1024
|
-
var
|
|
1056
|
+
var import_warps7 = require("@vleap/warps");
|
|
1025
1057
|
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1026
1058
|
var import_near_api_js5 = require("near-api-js");
|
|
1027
1059
|
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
@@ -1031,7 +1063,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1031
1063
|
this.keypair = null;
|
|
1032
1064
|
}
|
|
1033
1065
|
async getAddress() {
|
|
1034
|
-
const address = (0,
|
|
1066
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1035
1067
|
if (address) return address;
|
|
1036
1068
|
try {
|
|
1037
1069
|
const keypair = this.getKeyPair();
|
|
@@ -1063,20 +1095,48 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1063
1095
|
getKeyPairInstance() {
|
|
1064
1096
|
return this.getKeyPair();
|
|
1065
1097
|
}
|
|
1066
|
-
|
|
1098
|
+
async importFromMnemonic(mnemonic) {
|
|
1067
1099
|
const seed = bip392.mnemonicToSeedSync(mnemonic);
|
|
1068
1100
|
const secretKey = seed.slice(0, 32);
|
|
1069
1101
|
const keyPair = import_near_api_js5.KeyPair.fromString(import_bs582.default.encode(secretKey));
|
|
1070
1102
|
const publicKey = keyPair.getPublicKey();
|
|
1071
1103
|
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1072
|
-
|
|
1104
|
+
const walletDetails = {
|
|
1105
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1106
|
+
address: accountId,
|
|
1107
|
+
privateKey: keyPair.toString(),
|
|
1108
|
+
mnemonic
|
|
1109
|
+
};
|
|
1110
|
+
(0, import_warps7.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
|
|
1111
|
+
return walletDetails;
|
|
1112
|
+
}
|
|
1113
|
+
async importFromPrivateKey(privateKey) {
|
|
1114
|
+
const keyPair = import_near_api_js5.KeyPair.fromString(privateKey);
|
|
1115
|
+
const publicKey = keyPair.getPublicKey();
|
|
1116
|
+
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1117
|
+
const walletDetails = {
|
|
1073
1118
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1074
1119
|
address: accountId,
|
|
1075
1120
|
privateKey: keyPair.toString(),
|
|
1076
1121
|
mnemonic: null
|
|
1077
1122
|
};
|
|
1123
|
+
(0, import_warps7.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
|
|
1124
|
+
return walletDetails;
|
|
1078
1125
|
}
|
|
1079
|
-
|
|
1126
|
+
async export() {
|
|
1127
|
+
const keypair = this.getKeyPair();
|
|
1128
|
+
const privateKey = (0, import_warps7.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
1129
|
+
const mnemonic = (0, import_warps7.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1130
|
+
const publicKey = keypair.getPublicKey();
|
|
1131
|
+
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1132
|
+
return {
|
|
1133
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1134
|
+
address: accountId,
|
|
1135
|
+
privateKey: privateKey || null,
|
|
1136
|
+
mnemonic: mnemonic || null
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
async generate() {
|
|
1080
1140
|
const keyPair = import_near_api_js5.KeyPair.fromRandom("ed25519");
|
|
1081
1141
|
const publicKey = keyPair.getPublicKey();
|
|
1082
1142
|
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
@@ -1089,7 +1149,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1089
1149
|
}
|
|
1090
1150
|
getKeyPair() {
|
|
1091
1151
|
if (this.keypair) return this.keypair;
|
|
1092
|
-
const privateKey = (0,
|
|
1152
|
+
const privateKey = (0, import_warps7.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
1093
1153
|
if (!privateKey) throw new Error("No private key provided");
|
|
1094
1154
|
try {
|
|
1095
1155
|
return import_near_api_js5.KeyPair.fromString(privateKey);
|
|
@@ -1105,14 +1165,14 @@ _PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
|
|
|
1105
1165
|
var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
1106
1166
|
|
|
1107
1167
|
// src/providers/ReadOnlyWalletProvider.ts
|
|
1108
|
-
var
|
|
1168
|
+
var import_warps8 = require("@vleap/warps");
|
|
1109
1169
|
var ReadOnlyWalletProvider = class {
|
|
1110
1170
|
constructor(config, chain) {
|
|
1111
1171
|
this.config = config;
|
|
1112
1172
|
this.chain = chain;
|
|
1113
1173
|
}
|
|
1114
1174
|
async getAddress() {
|
|
1115
|
-
return (0,
|
|
1175
|
+
return (0, import_warps8.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1116
1176
|
}
|
|
1117
1177
|
async getPublicKey() {
|
|
1118
1178
|
return null;
|
|
@@ -1125,12 +1185,20 @@ var ReadOnlyWalletProvider = class {
|
|
|
1125
1185
|
const address = await this.getAddress();
|
|
1126
1186
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1127
1187
|
}
|
|
1128
|
-
|
|
1129
|
-
const address = (0,
|
|
1188
|
+
async importFromMnemonic(mnemonic) {
|
|
1189
|
+
const address = (0, import_warps8.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1130
1190
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1131
1191
|
}
|
|
1132
|
-
|
|
1133
|
-
const address = (0,
|
|
1192
|
+
async importFromPrivateKey(privateKey) {
|
|
1193
|
+
const address = (0, import_warps8.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1194
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1195
|
+
}
|
|
1196
|
+
async export() {
|
|
1197
|
+
const address = (0, import_warps8.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1198
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1199
|
+
}
|
|
1200
|
+
async generate() {
|
|
1201
|
+
const address = (0, import_warps8.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1134
1202
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1135
1203
|
}
|
|
1136
1204
|
};
|
|
@@ -1142,7 +1210,7 @@ var WarpNearWallet = class {
|
|
|
1142
1210
|
this.chain = chain;
|
|
1143
1211
|
this.cachedAddress = null;
|
|
1144
1212
|
this.cachedPublicKey = null;
|
|
1145
|
-
const providerConfig = (0,
|
|
1213
|
+
const providerConfig = (0, import_warps9.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1146
1214
|
this.nearConfig = {
|
|
1147
1215
|
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
1148
1216
|
nodeUrl: providerConfig.url,
|
|
@@ -1214,13 +1282,21 @@ var WarpNearWallet = class {
|
|
|
1214
1282
|
async sendTransactions(txs) {
|
|
1215
1283
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1216
1284
|
}
|
|
1217
|
-
|
|
1285
|
+
async importFromMnemonic(mnemonic) {
|
|
1286
|
+
const walletProvider = this.createProviderForOperation("mnemonic");
|
|
1287
|
+
return await walletProvider.importFromMnemonic(mnemonic);
|
|
1288
|
+
}
|
|
1289
|
+
async importFromPrivateKey(privateKey) {
|
|
1290
|
+
const walletProvider = this.createProviderForOperation("privateKey");
|
|
1291
|
+
return await walletProvider.importFromPrivateKey(privateKey);
|
|
1292
|
+
}
|
|
1293
|
+
async export(provider) {
|
|
1218
1294
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1219
|
-
return walletProvider.
|
|
1295
|
+
return await walletProvider.export();
|
|
1220
1296
|
}
|
|
1221
|
-
generate(provider) {
|
|
1297
|
+
async generate(provider) {
|
|
1222
1298
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1223
|
-
return walletProvider.generate();
|
|
1299
|
+
return await walletProvider.generate();
|
|
1224
1300
|
}
|
|
1225
1301
|
getAddress() {
|
|
1226
1302
|
return this.cachedAddress;
|
|
@@ -1235,7 +1311,7 @@ var WarpNearWallet = class {
|
|
|
1235
1311
|
return this.createProviderForOperation(wallet.provider);
|
|
1236
1312
|
}
|
|
1237
1313
|
initializeCache() {
|
|
1238
|
-
(0,
|
|
1314
|
+
(0, import_warps9.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1239
1315
|
this.cachedAddress = cache.address;
|
|
1240
1316
|
this.cachedPublicKey = cache.publicKey;
|
|
1241
1317
|
});
|
|
@@ -1276,7 +1352,7 @@ var createNearAdapter = (chainName, chainInfos) => {
|
|
|
1276
1352
|
|
|
1277
1353
|
// src/chains/near.ts
|
|
1278
1354
|
var NativeTokenNear = {
|
|
1279
|
-
chain:
|
|
1355
|
+
chain: import_warps10.WarpChainName.Near,
|
|
1280
1356
|
identifier: "NEAR",
|
|
1281
1357
|
symbol: "NEAR",
|
|
1282
1358
|
name: "NEAR",
|
|
@@ -1286,9 +1362,9 @@ var NativeTokenNear = {
|
|
|
1286
1362
|
dark: "https://joai.ai/images/tokens/near-black.svg"
|
|
1287
1363
|
}
|
|
1288
1364
|
};
|
|
1289
|
-
var NearAdapter = createNearAdapter(
|
|
1365
|
+
var NearAdapter = createNearAdapter(import_warps10.WarpChainName.Near, {
|
|
1290
1366
|
mainnet: {
|
|
1291
|
-
name:
|
|
1367
|
+
name: import_warps10.WarpChainName.Near,
|
|
1292
1368
|
displayName: "NEAR Mainnet",
|
|
1293
1369
|
chainId: "mainnet",
|
|
1294
1370
|
blockTime: 1200,
|
|
@@ -1301,7 +1377,7 @@ var NearAdapter = createNearAdapter("near", {
|
|
|
1301
1377
|
nativeToken: NativeTokenNear
|
|
1302
1378
|
},
|
|
1303
1379
|
testnet: {
|
|
1304
|
-
name:
|
|
1380
|
+
name: import_warps10.WarpChainName.Near,
|
|
1305
1381
|
displayName: "NEAR Testnet",
|
|
1306
1382
|
chainId: "testnet",
|
|
1307
1383
|
blockTime: 1200,
|
|
@@ -1314,7 +1390,7 @@ var NearAdapter = createNearAdapter("near", {
|
|
|
1314
1390
|
nativeToken: NativeTokenNear
|
|
1315
1391
|
},
|
|
1316
1392
|
devnet: {
|
|
1317
|
-
name:
|
|
1393
|
+
name: import_warps10.WarpChainName.Near,
|
|
1318
1394
|
displayName: "NEAR Devnet",
|
|
1319
1395
|
chainId: "testnet",
|
|
1320
1396
|
blockTime: 1200,
|