@vleap/warps-adapter-near 0.1.0-beta.6 → 0.1.0-beta.8
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 +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +44 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -48
- 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, 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';
|
|
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, WarpWalletProvider, WarpWalletDetails } from '@vleap/warps';
|
|
2
2
|
|
|
3
3
|
declare const NativeTokenNear: WarpChainAsset;
|
|
4
4
|
declare const NearAdapter: ChainAdapterFactory;
|
|
@@ -135,17 +135,18 @@ declare class WarpNearWallet implements AdapterWarpWallet {
|
|
|
135
135
|
private cachedAddress;
|
|
136
136
|
private cachedPublicKey;
|
|
137
137
|
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
138
|
-
private createProvider;
|
|
139
|
-
private initializeCache;
|
|
140
138
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
141
139
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
142
140
|
signMessage(message: string): Promise<string>;
|
|
143
141
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
144
142
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
145
|
-
create(mnemonic: string): WarpWalletDetails;
|
|
146
|
-
generate(): WarpWalletDetails;
|
|
143
|
+
create(provider: WarpWalletProvider, mnemonic: string): WarpWalletDetails;
|
|
144
|
+
generate(provider: WarpWalletProvider): WarpWalletDetails;
|
|
147
145
|
getAddress(): string | null;
|
|
148
146
|
getPublicKey(): string | null;
|
|
147
|
+
private createProvider;
|
|
148
|
+
private initializeCache;
|
|
149
|
+
private createProviderForOperation;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenNear, NearAdapter, NearExplorerMap, NearExplorerNames, NearExplorerUrls, NearExplorers, NearTokens, WarpNearConstants, WarpNearDataLoader, WarpNearExecutor, WarpNearExplorer, WarpNearOutput, WarpNearSerializer, WarpNearWallet, findKnownTokenById, getKnownTokensForChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, WarpWalletProvider, WarpWalletDetails } from '@vleap/warps';
|
|
2
2
|
|
|
3
3
|
declare const NativeTokenNear: WarpChainAsset;
|
|
4
4
|
declare const NearAdapter: ChainAdapterFactory;
|
|
@@ -135,17 +135,18 @@ declare class WarpNearWallet implements AdapterWarpWallet {
|
|
|
135
135
|
private cachedAddress;
|
|
136
136
|
private cachedPublicKey;
|
|
137
137
|
constructor(config: WarpClientConfig, chain: WarpChainInfo);
|
|
138
|
-
private createProvider;
|
|
139
|
-
private initializeCache;
|
|
140
138
|
signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
|
|
141
139
|
signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
|
|
142
140
|
signMessage(message: string): Promise<string>;
|
|
143
141
|
sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
|
|
144
142
|
sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
|
|
145
|
-
create(mnemonic: string): WarpWalletDetails;
|
|
146
|
-
generate(): WarpWalletDetails;
|
|
143
|
+
create(provider: WarpWalletProvider, mnemonic: string): WarpWalletDetails;
|
|
144
|
+
generate(provider: WarpWalletProvider): WarpWalletDetails;
|
|
147
145
|
getAddress(): string | null;
|
|
148
146
|
getPublicKey(): string | null;
|
|
147
|
+
private createProvider;
|
|
148
|
+
private initializeCache;
|
|
149
|
+
private createProviderForOperation;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenNear, NearAdapter, NearExplorerMap, NearExplorerNames, NearExplorerUrls, NearExplorers, NearTokens, WarpNearConstants, WarpNearDataLoader, WarpNearExecutor, WarpNearExplorer, WarpNearOutput, WarpNearSerializer, WarpNearWallet, findKnownTokenById, getKnownTokensForChain };
|
package/dist/index.js
CHANGED
|
@@ -935,11 +935,11 @@ var import_near_api_js6 = require("near-api-js");
|
|
|
935
935
|
// src/providers/MnemonicWalletProvider.ts
|
|
936
936
|
var import_crypto = require("@near-js/crypto");
|
|
937
937
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
938
|
-
var import_english = require("@scure/bip39/wordlists/english
|
|
938
|
+
var import_english = require("@scure/bip39/wordlists/english");
|
|
939
939
|
var import_warps5 = require("@vleap/warps");
|
|
940
940
|
var import_bs58 = __toESM(require("bs58"), 1);
|
|
941
941
|
var import_near_api_js4 = require("near-api-js");
|
|
942
|
-
var
|
|
942
|
+
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
943
943
|
constructor(config, chain) {
|
|
944
944
|
this.config = config;
|
|
945
945
|
this.chain = chain;
|
|
@@ -984,9 +984,9 @@ var MnemonicWalletProvider = class {
|
|
|
984
984
|
const publicKey = keyPair.getPublicKey();
|
|
985
985
|
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
986
986
|
return {
|
|
987
|
-
provider:
|
|
987
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
988
988
|
address: accountId,
|
|
989
|
-
privateKey:
|
|
989
|
+
privateKey: null,
|
|
990
990
|
mnemonic
|
|
991
991
|
};
|
|
992
992
|
}
|
|
@@ -997,9 +997,9 @@ var MnemonicWalletProvider = class {
|
|
|
997
997
|
const publicKey = keyPair.getPublicKey();
|
|
998
998
|
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
999
999
|
return {
|
|
1000
|
-
provider:
|
|
1000
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1001
1001
|
address: accountId,
|
|
1002
|
-
privateKey:
|
|
1002
|
+
privateKey: null,
|
|
1003
1003
|
mnemonic
|
|
1004
1004
|
};
|
|
1005
1005
|
}
|
|
@@ -1012,15 +1012,15 @@ var MnemonicWalletProvider = class {
|
|
|
1012
1012
|
return this.keypair;
|
|
1013
1013
|
}
|
|
1014
1014
|
};
|
|
1015
|
+
_MnemonicWalletProvider.PROVIDER_NAME = "mnemonic";
|
|
1016
|
+
var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
1015
1017
|
|
|
1016
1018
|
// src/providers/PrivateKeyWalletProvider.ts
|
|
1017
1019
|
var import_crypto2 = require("@near-js/crypto");
|
|
1018
|
-
var bip392 = __toESM(require("@scure/bip39"), 1);
|
|
1019
|
-
var import_english2 = require("@scure/bip39/wordlists/english.js");
|
|
1020
1020
|
var import_warps6 = require("@vleap/warps");
|
|
1021
1021
|
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1022
1022
|
var import_near_api_js5 = require("near-api-js");
|
|
1023
|
-
var
|
|
1023
|
+
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
1024
1024
|
constructor(config, chain) {
|
|
1025
1025
|
this.config = config;
|
|
1026
1026
|
this.chain = chain;
|
|
@@ -1060,28 +1060,17 @@ var PrivateKeyWalletProvider = class {
|
|
|
1060
1060
|
return this.getKeyPair();
|
|
1061
1061
|
}
|
|
1062
1062
|
create(mnemonic) {
|
|
1063
|
-
|
|
1064
|
-
const keyPair = import_near_api_js5.KeyPair.fromRandom("ed25519");
|
|
1065
|
-
const publicKey = keyPair.getPublicKey();
|
|
1066
|
-
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1067
|
-
return {
|
|
1068
|
-
provider: "privateKey",
|
|
1069
|
-
address: accountId,
|
|
1070
|
-
privateKey: keyPair.toString(),
|
|
1071
|
-
mnemonic
|
|
1072
|
-
};
|
|
1063
|
+
throw new Error("PrivateKeyWalletProvider does not support creating wallets from mnemonics. Use MnemonicWalletProvider instead.");
|
|
1073
1064
|
}
|
|
1074
1065
|
generate() {
|
|
1075
|
-
const mnemonic = bip392.generateMnemonic(import_english2.wordlist);
|
|
1076
|
-
const seed = bip392.mnemonicToSeedSync(mnemonic);
|
|
1077
1066
|
const keyPair = import_near_api_js5.KeyPair.fromRandom("ed25519");
|
|
1078
1067
|
const publicKey = keyPair.getPublicKey();
|
|
1079
1068
|
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1080
1069
|
return {
|
|
1081
|
-
provider:
|
|
1070
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1082
1071
|
address: accountId,
|
|
1083
1072
|
privateKey: keyPair.toString(),
|
|
1084
|
-
mnemonic
|
|
1073
|
+
mnemonic: null
|
|
1085
1074
|
};
|
|
1086
1075
|
}
|
|
1087
1076
|
getKeyPair() {
|
|
@@ -1098,6 +1087,8 @@ var PrivateKeyWalletProvider = class {
|
|
|
1098
1087
|
}
|
|
1099
1088
|
}
|
|
1100
1089
|
};
|
|
1090
|
+
_PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
|
|
1091
|
+
var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
1101
1092
|
|
|
1102
1093
|
// src/providers/ReadOnlyWalletProvider.ts
|
|
1103
1094
|
var import_warps7 = require("@vleap/warps");
|
|
@@ -1146,23 +1137,6 @@ var WarpNearWallet = class {
|
|
|
1146
1137
|
this.walletProvider = this.createProvider();
|
|
1147
1138
|
this.initializeCache();
|
|
1148
1139
|
}
|
|
1149
|
-
createProvider() {
|
|
1150
|
-
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1151
|
-
if (!wallet) return null;
|
|
1152
|
-
if (typeof wallet === "string") return new ReadOnlyWalletProvider(this.config, this.chain);
|
|
1153
|
-
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
1154
|
-
const providerFactory = customWalletProviders?.[wallet.provider];
|
|
1155
|
-
if (providerFactory) return providerFactory(this.config, this.chain);
|
|
1156
|
-
if (wallet.provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain);
|
|
1157
|
-
if (wallet.provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain);
|
|
1158
|
-
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${wallet.provider}`);
|
|
1159
|
-
}
|
|
1160
|
-
initializeCache() {
|
|
1161
|
-
(0, import_warps8.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1162
|
-
this.cachedAddress = cache.address;
|
|
1163
|
-
this.cachedPublicKey = cache.publicKey;
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
1140
|
async signTransaction(tx) {
|
|
1167
1141
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1168
1142
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
@@ -1226,15 +1200,13 @@ var WarpNearWallet = class {
|
|
|
1226
1200
|
async sendTransactions(txs) {
|
|
1227
1201
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1228
1202
|
}
|
|
1229
|
-
create(mnemonic) {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
return this.walletProvider.create(mnemonic);
|
|
1203
|
+
create(provider, mnemonic) {
|
|
1204
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1205
|
+
return walletProvider.create(mnemonic);
|
|
1233
1206
|
}
|
|
1234
|
-
generate() {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
return this.walletProvider.generate();
|
|
1207
|
+
generate(provider) {
|
|
1208
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1209
|
+
return walletProvider.generate();
|
|
1238
1210
|
}
|
|
1239
1211
|
getAddress() {
|
|
1240
1212
|
return this.cachedAddress;
|
|
@@ -1242,6 +1214,30 @@ var WarpNearWallet = class {
|
|
|
1242
1214
|
getPublicKey() {
|
|
1243
1215
|
return this.cachedPublicKey;
|
|
1244
1216
|
}
|
|
1217
|
+
createProvider() {
|
|
1218
|
+
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1219
|
+
if (!wallet) return null;
|
|
1220
|
+
if (typeof wallet === "string") return new ReadOnlyWalletProvider(this.config, this.chain);
|
|
1221
|
+
return this.createProviderForOperation(wallet.provider);
|
|
1222
|
+
}
|
|
1223
|
+
initializeCache() {
|
|
1224
|
+
(0, import_warps8.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1225
|
+
this.cachedAddress = cache.address;
|
|
1226
|
+
this.cachedPublicKey = cache.publicKey;
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
createProviderForOperation(provider) {
|
|
1230
|
+
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
1231
|
+
const providerFactory = customWalletProviders?.[provider];
|
|
1232
|
+
if (providerFactory) {
|
|
1233
|
+
const walletProvider = providerFactory(this.config, this.chain);
|
|
1234
|
+
if (!walletProvider) throw new Error(`Custom wallet provider factory returned null for ${provider}`);
|
|
1235
|
+
return walletProvider;
|
|
1236
|
+
}
|
|
1237
|
+
if (provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain);
|
|
1238
|
+
if (provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain);
|
|
1239
|
+
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${provider}`);
|
|
1240
|
+
}
|
|
1245
1241
|
};
|
|
1246
1242
|
|
|
1247
1243
|
// src/chains/common.ts
|