@vleap/warps-adapter-near 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 +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +83 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -46
- 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(mnemonic: string, provider: WarpWalletProvider): 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(mnemonic: string, provider: WarpWalletProvider): 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
|
@@ -929,7 +929,7 @@ var WarpNearExplorer = class {
|
|
|
929
929
|
};
|
|
930
930
|
|
|
931
931
|
// src/WarpNearWallet.ts
|
|
932
|
-
var
|
|
932
|
+
var import_warps8 = require("@vleap/warps");
|
|
933
933
|
var import_near_api_js6 = require("near-api-js");
|
|
934
934
|
|
|
935
935
|
// src/providers/MnemonicWalletProvider.ts
|
|
@@ -939,7 +939,7 @@ var import_english = require("@scure/bip39/wordlists/english.js");
|
|
|
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,39 @@ var PrivateKeyWalletProvider = class {
|
|
|
1098
1087
|
}
|
|
1099
1088
|
}
|
|
1100
1089
|
};
|
|
1090
|
+
_PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
|
|
1091
|
+
var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
1092
|
+
|
|
1093
|
+
// src/providers/ReadOnlyWalletProvider.ts
|
|
1094
|
+
var import_warps7 = require("@vleap/warps");
|
|
1095
|
+
var ReadOnlyWalletProvider = class {
|
|
1096
|
+
constructor(config, chain) {
|
|
1097
|
+
this.config = config;
|
|
1098
|
+
this.chain = chain;
|
|
1099
|
+
}
|
|
1100
|
+
async getAddress() {
|
|
1101
|
+
return (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1102
|
+
}
|
|
1103
|
+
async getPublicKey() {
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
async signTransaction(tx) {
|
|
1107
|
+
const address = await this.getAddress();
|
|
1108
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1109
|
+
}
|
|
1110
|
+
async signMessage(message) {
|
|
1111
|
+
const address = await this.getAddress();
|
|
1112
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1113
|
+
}
|
|
1114
|
+
create(mnemonic) {
|
|
1115
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1116
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1117
|
+
}
|
|
1118
|
+
generate() {
|
|
1119
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1120
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1101
1123
|
|
|
1102
1124
|
// src/WarpNearWallet.ts
|
|
1103
1125
|
var WarpNearWallet = class {
|
|
@@ -1106,7 +1128,7 @@ var WarpNearWallet = class {
|
|
|
1106
1128
|
this.chain = chain;
|
|
1107
1129
|
this.cachedAddress = null;
|
|
1108
1130
|
this.cachedPublicKey = null;
|
|
1109
|
-
const providerConfig = (0,
|
|
1131
|
+
const providerConfig = (0, import_warps8.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1110
1132
|
this.nearConfig = {
|
|
1111
1133
|
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
1112
1134
|
nodeUrl: providerConfig.url,
|
|
@@ -1115,26 +1137,10 @@ var WarpNearWallet = class {
|
|
|
1115
1137
|
this.walletProvider = this.createProvider();
|
|
1116
1138
|
this.initializeCache();
|
|
1117
1139
|
}
|
|
1118
|
-
createProvider() {
|
|
1119
|
-
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1120
|
-
if (!wallet) return null;
|
|
1121
|
-
if (typeof wallet === "string") throw new Error(`Wallet can not be used for signing: ${wallet}`);
|
|
1122
|
-
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
1123
|
-
const providerFactory = customWalletProviders?.[wallet.provider];
|
|
1124
|
-
if (providerFactory) return providerFactory(this.config, this.chain);
|
|
1125
|
-
if (wallet.provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain);
|
|
1126
|
-
if (wallet.provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain);
|
|
1127
|
-
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${wallet.provider}`);
|
|
1128
|
-
}
|
|
1129
|
-
initializeCache() {
|
|
1130
|
-
(0, import_warps7.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1131
|
-
this.cachedAddress = cache.address;
|
|
1132
|
-
this.cachedPublicKey = cache.publicKey;
|
|
1133
|
-
});
|
|
1134
|
-
}
|
|
1135
1140
|
async signTransaction(tx) {
|
|
1136
1141
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1137
1142
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1143
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
1138
1144
|
const accountId = this.getAddress();
|
|
1139
1145
|
if (!accountId) throw new Error("No account ID available");
|
|
1140
1146
|
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
@@ -1159,10 +1165,15 @@ var WarpNearWallet = class {
|
|
|
1159
1165
|
}
|
|
1160
1166
|
async signTransactions(txs) {
|
|
1161
1167
|
if (txs.length === 0) return [];
|
|
1162
|
-
|
|
1168
|
+
const signedTxs = [];
|
|
1169
|
+
for (const tx of txs) {
|
|
1170
|
+
signedTxs.push(await this.signTransaction(tx));
|
|
1171
|
+
}
|
|
1172
|
+
return signedTxs;
|
|
1163
1173
|
}
|
|
1164
1174
|
async signMessage(message) {
|
|
1165
1175
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1176
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
1166
1177
|
return await this.walletProvider.signMessage(message);
|
|
1167
1178
|
}
|
|
1168
1179
|
async sendTransaction(tx) {
|
|
@@ -1189,13 +1200,13 @@ var WarpNearWallet = class {
|
|
|
1189
1200
|
async sendTransactions(txs) {
|
|
1190
1201
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1191
1202
|
}
|
|
1192
|
-
create(mnemonic) {
|
|
1193
|
-
|
|
1194
|
-
return
|
|
1203
|
+
create(mnemonic, provider) {
|
|
1204
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1205
|
+
return walletProvider.create(mnemonic);
|
|
1195
1206
|
}
|
|
1196
|
-
generate() {
|
|
1197
|
-
|
|
1198
|
-
return
|
|
1207
|
+
generate(provider) {
|
|
1208
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1209
|
+
return walletProvider.generate();
|
|
1199
1210
|
}
|
|
1200
1211
|
getAddress() {
|
|
1201
1212
|
return this.cachedAddress;
|
|
@@ -1203,6 +1214,30 @@ var WarpNearWallet = class {
|
|
|
1203
1214
|
getPublicKey() {
|
|
1204
1215
|
return this.cachedPublicKey;
|
|
1205
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
|
+
}
|
|
1206
1241
|
};
|
|
1207
1242
|
|
|
1208
1243
|
// src/chains/common.ts
|