@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.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/chains/near.ts
|
|
2
|
+
import { WarpChainName as WarpChainName2 } from "@vleap/warps";
|
|
3
|
+
|
|
1
4
|
// src/WarpNearDataLoader.ts
|
|
2
5
|
import {
|
|
3
6
|
CacheTtl,
|
|
@@ -45,9 +48,10 @@ var NearExplorerNames = {
|
|
|
45
48
|
var NearExplorerUrls = ExplorerUrls;
|
|
46
49
|
|
|
47
50
|
// src/tokens.ts
|
|
51
|
+
import { WarpChainName } from "@vleap/warps";
|
|
48
52
|
var NearTokens = [];
|
|
49
53
|
var KnownTokens = {
|
|
50
|
-
|
|
54
|
+
[WarpChainName.Near]: {
|
|
51
55
|
mainnet: NearTokens,
|
|
52
56
|
testnet: NearTokens,
|
|
53
57
|
devnet: NearTokens
|
|
@@ -910,7 +914,12 @@ import { connect as connect4, keyStores as keyStores4 } from "near-api-js";
|
|
|
910
914
|
import { keyToImplicitAddress } from "@near-js/crypto";
|
|
911
915
|
import * as bip39 from "@scure/bip39";
|
|
912
916
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
913
|
-
import {
|
|
917
|
+
import {
|
|
918
|
+
getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3,
|
|
919
|
+
getWarpWalletMnemonicFromConfig,
|
|
920
|
+
getWarpWalletPrivateKeyFromConfig,
|
|
921
|
+
setWarpWalletInConfig
|
|
922
|
+
} from "@vleap/warps";
|
|
914
923
|
import bs58 from "bs58";
|
|
915
924
|
import { KeyPair } from "near-api-js";
|
|
916
925
|
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
@@ -952,20 +961,48 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
952
961
|
getKeyPairInstance() {
|
|
953
962
|
return this.getKeyPair();
|
|
954
963
|
}
|
|
955
|
-
|
|
964
|
+
async importFromMnemonic(mnemonic) {
|
|
956
965
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
957
966
|
const secretKey = seed.slice(0, 32);
|
|
958
967
|
const keyPair = KeyPair.fromString(bs58.encode(secretKey));
|
|
959
968
|
const publicKey = keyPair.getPublicKey();
|
|
960
969
|
const accountId = keyToImplicitAddress(publicKey.toString());
|
|
961
|
-
|
|
970
|
+
const walletDetails = {
|
|
962
971
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
963
972
|
address: accountId,
|
|
964
|
-
privateKey:
|
|
973
|
+
privateKey: keyPair.toString(),
|
|
965
974
|
mnemonic
|
|
966
975
|
};
|
|
976
|
+
setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
|
|
977
|
+
return walletDetails;
|
|
978
|
+
}
|
|
979
|
+
async importFromPrivateKey(privateKey) {
|
|
980
|
+
const keyPair = KeyPair.fromString(privateKey);
|
|
981
|
+
const publicKey = keyPair.getPublicKey();
|
|
982
|
+
const accountId = keyToImplicitAddress(publicKey.toString());
|
|
983
|
+
const walletDetails = {
|
|
984
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
985
|
+
address: accountId,
|
|
986
|
+
privateKey: keyPair.toString(),
|
|
987
|
+
mnemonic: null
|
|
988
|
+
};
|
|
989
|
+
setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
|
|
990
|
+
return walletDetails;
|
|
967
991
|
}
|
|
968
|
-
|
|
992
|
+
async export() {
|
|
993
|
+
const keypair = this.getKeyPair();
|
|
994
|
+
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
995
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
996
|
+
const publicKey = keypair.getPublicKey();
|
|
997
|
+
const accountId = keyToImplicitAddress(publicKey.toString());
|
|
998
|
+
return {
|
|
999
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1000
|
+
address: accountId,
|
|
1001
|
+
privateKey: privateKey || null,
|
|
1002
|
+
mnemonic: mnemonic || null
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
async generate() {
|
|
969
1006
|
const mnemonic = bip39.generateMnemonic(wordlist);
|
|
970
1007
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
971
1008
|
const secretKey = seed.slice(0, 32);
|
|
@@ -995,7 +1032,12 @@ var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
|
995
1032
|
// src/providers/PrivateKeyWalletProvider.ts
|
|
996
1033
|
import { keyToImplicitAddress as keyToImplicitAddress2 } from "@near-js/crypto";
|
|
997
1034
|
import * as bip392 from "@scure/bip39";
|
|
998
|
-
import {
|
|
1035
|
+
import {
|
|
1036
|
+
getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig4,
|
|
1037
|
+
getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
|
|
1038
|
+
getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
|
|
1039
|
+
setWarpWalletInConfig as setWarpWalletInConfig2
|
|
1040
|
+
} from "@vleap/warps";
|
|
999
1041
|
import bs582 from "bs58";
|
|
1000
1042
|
import { KeyPair as KeyPair2 } from "near-api-js";
|
|
1001
1043
|
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
@@ -1037,20 +1079,48 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1037
1079
|
getKeyPairInstance() {
|
|
1038
1080
|
return this.getKeyPair();
|
|
1039
1081
|
}
|
|
1040
|
-
|
|
1082
|
+
async importFromMnemonic(mnemonic) {
|
|
1041
1083
|
const seed = bip392.mnemonicToSeedSync(mnemonic);
|
|
1042
1084
|
const secretKey = seed.slice(0, 32);
|
|
1043
1085
|
const keyPair = KeyPair2.fromString(bs582.encode(secretKey));
|
|
1044
1086
|
const publicKey = keyPair.getPublicKey();
|
|
1045
1087
|
const accountId = keyToImplicitAddress2(publicKey.toString());
|
|
1046
|
-
|
|
1088
|
+
const walletDetails = {
|
|
1089
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1090
|
+
address: accountId,
|
|
1091
|
+
privateKey: keyPair.toString(),
|
|
1092
|
+
mnemonic
|
|
1093
|
+
};
|
|
1094
|
+
setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
|
|
1095
|
+
return walletDetails;
|
|
1096
|
+
}
|
|
1097
|
+
async importFromPrivateKey(privateKey) {
|
|
1098
|
+
const keyPair = KeyPair2.fromString(privateKey);
|
|
1099
|
+
const publicKey = keyPair.getPublicKey();
|
|
1100
|
+
const accountId = keyToImplicitAddress2(publicKey.toString());
|
|
1101
|
+
const walletDetails = {
|
|
1047
1102
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1048
1103
|
address: accountId,
|
|
1049
1104
|
privateKey: keyPair.toString(),
|
|
1050
1105
|
mnemonic: null
|
|
1051
1106
|
};
|
|
1107
|
+
setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
|
|
1108
|
+
return walletDetails;
|
|
1109
|
+
}
|
|
1110
|
+
async export() {
|
|
1111
|
+
const keypair = this.getKeyPair();
|
|
1112
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
|
|
1113
|
+
const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
|
|
1114
|
+
const publicKey = keypair.getPublicKey();
|
|
1115
|
+
const accountId = keyToImplicitAddress2(publicKey.toString());
|
|
1116
|
+
return {
|
|
1117
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1118
|
+
address: accountId,
|
|
1119
|
+
privateKey: privateKey || null,
|
|
1120
|
+
mnemonic: mnemonic || null
|
|
1121
|
+
};
|
|
1052
1122
|
}
|
|
1053
|
-
generate() {
|
|
1123
|
+
async generate() {
|
|
1054
1124
|
const keyPair = KeyPair2.fromRandom("ed25519");
|
|
1055
1125
|
const publicKey = keyPair.getPublicKey();
|
|
1056
1126
|
const accountId = keyToImplicitAddress2(publicKey.toString());
|
|
@@ -1063,7 +1133,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1063
1133
|
}
|
|
1064
1134
|
getKeyPair() {
|
|
1065
1135
|
if (this.keypair) return this.keypair;
|
|
1066
|
-
const privateKey =
|
|
1136
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
|
|
1067
1137
|
if (!privateKey) throw new Error("No private key provided");
|
|
1068
1138
|
try {
|
|
1069
1139
|
return KeyPair2.fromString(privateKey);
|
|
@@ -1099,11 +1169,19 @@ var ReadOnlyWalletProvider = class {
|
|
|
1099
1169
|
const address = await this.getAddress();
|
|
1100
1170
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1101
1171
|
}
|
|
1102
|
-
|
|
1172
|
+
async importFromMnemonic(mnemonic) {
|
|
1103
1173
|
const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
|
|
1104
1174
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1105
1175
|
}
|
|
1106
|
-
|
|
1176
|
+
async importFromPrivateKey(privateKey) {
|
|
1177
|
+
const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
|
|
1178
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1179
|
+
}
|
|
1180
|
+
async export() {
|
|
1181
|
+
const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
|
|
1182
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1183
|
+
}
|
|
1184
|
+
async generate() {
|
|
1107
1185
|
const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
|
|
1108
1186
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1109
1187
|
}
|
|
@@ -1188,13 +1266,21 @@ var WarpNearWallet = class {
|
|
|
1188
1266
|
async sendTransactions(txs) {
|
|
1189
1267
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1190
1268
|
}
|
|
1191
|
-
|
|
1269
|
+
async importFromMnemonic(mnemonic) {
|
|
1270
|
+
const walletProvider = this.createProviderForOperation("mnemonic");
|
|
1271
|
+
return await walletProvider.importFromMnemonic(mnemonic);
|
|
1272
|
+
}
|
|
1273
|
+
async importFromPrivateKey(privateKey) {
|
|
1274
|
+
const walletProvider = this.createProviderForOperation("privateKey");
|
|
1275
|
+
return await walletProvider.importFromPrivateKey(privateKey);
|
|
1276
|
+
}
|
|
1277
|
+
async export(provider) {
|
|
1192
1278
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1193
|
-
return walletProvider.
|
|
1279
|
+
return await walletProvider.export();
|
|
1194
1280
|
}
|
|
1195
|
-
generate(provider) {
|
|
1281
|
+
async generate(provider) {
|
|
1196
1282
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1197
|
-
return walletProvider.generate();
|
|
1283
|
+
return await walletProvider.generate();
|
|
1198
1284
|
}
|
|
1199
1285
|
getAddress() {
|
|
1200
1286
|
return this.cachedAddress;
|
|
@@ -1250,7 +1336,7 @@ var createNearAdapter = (chainName, chainInfos) => {
|
|
|
1250
1336
|
|
|
1251
1337
|
// src/chains/near.ts
|
|
1252
1338
|
var NativeTokenNear = {
|
|
1253
|
-
chain:
|
|
1339
|
+
chain: WarpChainName2.Near,
|
|
1254
1340
|
identifier: "NEAR",
|
|
1255
1341
|
symbol: "NEAR",
|
|
1256
1342
|
name: "NEAR",
|
|
@@ -1260,9 +1346,9 @@ var NativeTokenNear = {
|
|
|
1260
1346
|
dark: "https://joai.ai/images/tokens/near-black.svg"
|
|
1261
1347
|
}
|
|
1262
1348
|
};
|
|
1263
|
-
var NearAdapter = createNearAdapter(
|
|
1349
|
+
var NearAdapter = createNearAdapter(WarpChainName2.Near, {
|
|
1264
1350
|
mainnet: {
|
|
1265
|
-
name:
|
|
1351
|
+
name: WarpChainName2.Near,
|
|
1266
1352
|
displayName: "NEAR Mainnet",
|
|
1267
1353
|
chainId: "mainnet",
|
|
1268
1354
|
blockTime: 1200,
|
|
@@ -1275,7 +1361,7 @@ var NearAdapter = createNearAdapter("near", {
|
|
|
1275
1361
|
nativeToken: NativeTokenNear
|
|
1276
1362
|
},
|
|
1277
1363
|
testnet: {
|
|
1278
|
-
name:
|
|
1364
|
+
name: WarpChainName2.Near,
|
|
1279
1365
|
displayName: "NEAR Testnet",
|
|
1280
1366
|
chainId: "testnet",
|
|
1281
1367
|
blockTime: 1200,
|
|
@@ -1288,7 +1374,7 @@ var NearAdapter = createNearAdapter("near", {
|
|
|
1288
1374
|
nativeToken: NativeTokenNear
|
|
1289
1375
|
},
|
|
1290
1376
|
devnet: {
|
|
1291
|
-
name:
|
|
1377
|
+
name: WarpChainName2.Near,
|
|
1292
1378
|
displayName: "NEAR Devnet",
|
|
1293
1379
|
chainId: "testnet",
|
|
1294
1380
|
blockTime: 1200,
|