@vleap/warps-adapter-near 0.1.0-beta.11 → 0.1.0-beta.12

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.mjs CHANGED
@@ -910,7 +910,12 @@ import { connect as connect4, keyStores as keyStores4 } from "near-api-js";
910
910
  import { keyToImplicitAddress } from "@near-js/crypto";
911
911
  import * as bip39 from "@scure/bip39";
912
912
  import { wordlist } from "@scure/bip39/wordlists/english.js";
913
- import { getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3, getWarpWalletMnemonicFromConfig } from "@vleap/warps";
913
+ import {
914
+ getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig3,
915
+ getWarpWalletMnemonicFromConfig,
916
+ getWarpWalletPrivateKeyFromConfig,
917
+ setWarpWalletInConfig
918
+ } from "@vleap/warps";
914
919
  import bs58 from "bs58";
915
920
  import { KeyPair } from "near-api-js";
916
921
  var _MnemonicWalletProvider = class _MnemonicWalletProvider {
@@ -952,20 +957,48 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
952
957
  getKeyPairInstance() {
953
958
  return this.getKeyPair();
954
959
  }
955
- create(mnemonic) {
960
+ async importFromMnemonic(mnemonic) {
956
961
  const seed = bip39.mnemonicToSeedSync(mnemonic);
957
962
  const secretKey = seed.slice(0, 32);
958
963
  const keyPair = KeyPair.fromString(bs58.encode(secretKey));
959
964
  const publicKey = keyPair.getPublicKey();
960
965
  const accountId = keyToImplicitAddress(publicKey.toString());
961
- return {
966
+ const walletDetails = {
962
967
  provider: _MnemonicWalletProvider.PROVIDER_NAME,
963
968
  address: accountId,
964
- privateKey: null,
969
+ privateKey: keyPair.toString(),
965
970
  mnemonic
966
971
  };
972
+ setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
973
+ return walletDetails;
974
+ }
975
+ async importFromPrivateKey(privateKey) {
976
+ const keyPair = KeyPair.fromString(privateKey);
977
+ const publicKey = keyPair.getPublicKey();
978
+ const accountId = keyToImplicitAddress(publicKey.toString());
979
+ const walletDetails = {
980
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
981
+ address: accountId,
982
+ privateKey: keyPair.toString(),
983
+ mnemonic: null
984
+ };
985
+ setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
986
+ return walletDetails;
967
987
  }
968
- generate() {
988
+ async export() {
989
+ const keypair = this.getKeyPair();
990
+ const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
991
+ const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
992
+ const publicKey = keypair.getPublicKey();
993
+ const accountId = keyToImplicitAddress(publicKey.toString());
994
+ return {
995
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
996
+ address: accountId,
997
+ privateKey: privateKey || null,
998
+ mnemonic: mnemonic || null
999
+ };
1000
+ }
1001
+ async generate() {
969
1002
  const mnemonic = bip39.generateMnemonic(wordlist);
970
1003
  const seed = bip39.mnemonicToSeedSync(mnemonic);
971
1004
  const secretKey = seed.slice(0, 32);
@@ -995,7 +1028,12 @@ var MnemonicWalletProvider = _MnemonicWalletProvider;
995
1028
  // src/providers/PrivateKeyWalletProvider.ts
996
1029
  import { keyToImplicitAddress as keyToImplicitAddress2 } from "@near-js/crypto";
997
1030
  import * as bip392 from "@scure/bip39";
998
- import { getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig4, getWarpWalletPrivateKeyFromConfig } from "@vleap/warps";
1031
+ import {
1032
+ getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig4,
1033
+ getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
1034
+ getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
1035
+ setWarpWalletInConfig as setWarpWalletInConfig2
1036
+ } from "@vleap/warps";
999
1037
  import bs582 from "bs58";
1000
1038
  import { KeyPair as KeyPair2 } from "near-api-js";
1001
1039
  var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
@@ -1037,20 +1075,48 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
1037
1075
  getKeyPairInstance() {
1038
1076
  return this.getKeyPair();
1039
1077
  }
1040
- create(mnemonic) {
1078
+ async importFromMnemonic(mnemonic) {
1041
1079
  const seed = bip392.mnemonicToSeedSync(mnemonic);
1042
1080
  const secretKey = seed.slice(0, 32);
1043
1081
  const keyPair = KeyPair2.fromString(bs582.encode(secretKey));
1044
1082
  const publicKey = keyPair.getPublicKey();
1045
1083
  const accountId = keyToImplicitAddress2(publicKey.toString());
1046
- return {
1084
+ const walletDetails = {
1085
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
1086
+ address: accountId,
1087
+ privateKey: keyPair.toString(),
1088
+ mnemonic
1089
+ };
1090
+ setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
1091
+ return walletDetails;
1092
+ }
1093
+ async importFromPrivateKey(privateKey) {
1094
+ const keyPair = KeyPair2.fromString(privateKey);
1095
+ const publicKey = keyPair.getPublicKey();
1096
+ const accountId = keyToImplicitAddress2(publicKey.toString());
1097
+ const walletDetails = {
1047
1098
  provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
1048
1099
  address: accountId,
1049
1100
  privateKey: keyPair.toString(),
1050
1101
  mnemonic: null
1051
1102
  };
1103
+ setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
1104
+ return walletDetails;
1052
1105
  }
1053
- generate() {
1106
+ async export() {
1107
+ const keypair = this.getKeyPair();
1108
+ const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
1109
+ const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
1110
+ const publicKey = keypair.getPublicKey();
1111
+ const accountId = keyToImplicitAddress2(publicKey.toString());
1112
+ return {
1113
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
1114
+ address: accountId,
1115
+ privateKey: privateKey || null,
1116
+ mnemonic: mnemonic || null
1117
+ };
1118
+ }
1119
+ async generate() {
1054
1120
  const keyPair = KeyPair2.fromRandom("ed25519");
1055
1121
  const publicKey = keyPair.getPublicKey();
1056
1122
  const accountId = keyToImplicitAddress2(publicKey.toString());
@@ -1063,7 +1129,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
1063
1129
  }
1064
1130
  getKeyPair() {
1065
1131
  if (this.keypair) return this.keypair;
1066
- const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
1132
+ const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
1067
1133
  if (!privateKey) throw new Error("No private key provided");
1068
1134
  try {
1069
1135
  return KeyPair2.fromString(privateKey);
@@ -1099,11 +1165,19 @@ var ReadOnlyWalletProvider = class {
1099
1165
  const address = await this.getAddress();
1100
1166
  throw new Error(`Wallet can not be used for signing: ${address}`);
1101
1167
  }
1102
- create(mnemonic) {
1168
+ async importFromMnemonic(mnemonic) {
1169
+ const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
1170
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1171
+ }
1172
+ async importFromPrivateKey(privateKey) {
1173
+ const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
1174
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1175
+ }
1176
+ async export() {
1103
1177
  const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
1104
1178
  throw new Error(`Wallet can not be used for signing: ${address}`);
1105
1179
  }
1106
- generate() {
1180
+ async generate() {
1107
1181
  const address = getWarpWalletAddressFromConfig5(this.config, this.chain.name);
1108
1182
  throw new Error(`Wallet can not be used for signing: ${address}`);
1109
1183
  }
@@ -1188,13 +1262,21 @@ var WarpNearWallet = class {
1188
1262
  async sendTransactions(txs) {
1189
1263
  return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
1190
1264
  }
1191
- create(provider, mnemonic) {
1265
+ async importFromMnemonic(provider, mnemonic) {
1266
+ const walletProvider = this.createProviderForOperation(provider);
1267
+ return await walletProvider.importFromMnemonic(mnemonic);
1268
+ }
1269
+ async importFromPrivateKey(provider, privateKey) {
1270
+ const walletProvider = this.createProviderForOperation(provider);
1271
+ return await walletProvider.importFromPrivateKey(privateKey);
1272
+ }
1273
+ async export(provider) {
1192
1274
  const walletProvider = this.createProviderForOperation(provider);
1193
- return walletProvider.create(mnemonic);
1275
+ return await walletProvider.export();
1194
1276
  }
1195
- generate(provider) {
1277
+ async generate(provider) {
1196
1278
  const walletProvider = this.createProviderForOperation(provider);
1197
- return walletProvider.generate();
1279
+ return await walletProvider.generate();
1198
1280
  }
1199
1281
  getAddress() {
1200
1282
  return this.cachedAddress;