@vleap/warps-adapter-near 0.1.0-beta.4 → 0.1.0-beta.6

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 CHANGED
@@ -1,7 +1,7 @@
1
- import { WarpChainAsset, AdapterFactory, 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 } 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, WarpWalletDetails } from '@vleap/warps';
2
2
 
3
3
  declare const NativeTokenNear: WarpChainAsset;
4
- declare const getNearAdapter: AdapterFactory;
4
+ declare const NearAdapter: ChainAdapterFactory;
5
5
 
6
6
  declare const WarpNearConstants: {
7
7
  NativeToken: {
@@ -131,25 +131,21 @@ declare class WarpNearWallet implements AdapterWarpWallet {
131
131
  private config;
132
132
  private chain;
133
133
  private nearConfig;
134
+ private walletProvider;
135
+ private cachedAddress;
136
+ private cachedPublicKey;
134
137
  constructor(config: WarpClientConfig, chain: WarpChainInfo);
138
+ private createProvider;
139
+ private initializeCache;
135
140
  signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
136
141
  signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
137
142
  signMessage(message: string): Promise<string>;
138
143
  sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
139
144
  sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
140
- create(mnemonic: string): {
141
- address: string;
142
- privateKey: string;
143
- mnemonic: string;
144
- };
145
- generate(): {
146
- address: string;
147
- privateKey: string;
148
- mnemonic: string;
149
- };
145
+ create(mnemonic: string): WarpWalletDetails;
146
+ generate(): WarpWalletDetails;
150
147
  getAddress(): string | null;
151
148
  getPublicKey(): string | null;
152
- private getKeyPair;
153
149
  }
154
150
 
155
- export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenNear, NearExplorerMap, NearExplorerNames, NearExplorerUrls, NearExplorers, NearTokens, WarpNearConstants, WarpNearDataLoader, WarpNearExecutor, WarpNearExplorer, WarpNearOutput, WarpNearSerializer, WarpNearWallet, findKnownTokenById, getKnownTokensForChain, getNearAdapter };
151
+ 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,7 +1,7 @@
1
- import { WarpChainAsset, AdapterFactory, 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 } 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, WarpWalletDetails } from '@vleap/warps';
2
2
 
3
3
  declare const NativeTokenNear: WarpChainAsset;
4
- declare const getNearAdapter: AdapterFactory;
4
+ declare const NearAdapter: ChainAdapterFactory;
5
5
 
6
6
  declare const WarpNearConstants: {
7
7
  NativeToken: {
@@ -131,25 +131,21 @@ declare class WarpNearWallet implements AdapterWarpWallet {
131
131
  private config;
132
132
  private chain;
133
133
  private nearConfig;
134
+ private walletProvider;
135
+ private cachedAddress;
136
+ private cachedPublicKey;
134
137
  constructor(config: WarpClientConfig, chain: WarpChainInfo);
138
+ private createProvider;
139
+ private initializeCache;
135
140
  signTransaction(tx: WarpAdapterGenericTransaction): Promise<WarpAdapterGenericTransaction>;
136
141
  signTransactions(txs: WarpAdapterGenericTransaction[]): Promise<WarpAdapterGenericTransaction[]>;
137
142
  signMessage(message: string): Promise<string>;
138
143
  sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
139
144
  sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
140
- create(mnemonic: string): {
141
- address: string;
142
- privateKey: string;
143
- mnemonic: string;
144
- };
145
- generate(): {
146
- address: string;
147
- privateKey: string;
148
- mnemonic: string;
149
- };
145
+ create(mnemonic: string): WarpWalletDetails;
146
+ generate(): WarpWalletDetails;
150
147
  getAddress(): string | null;
151
148
  getPublicKey(): string | null;
152
- private getKeyPair;
153
149
  }
154
150
 
155
- export { type ExplorerName, ExplorerUrls, KnownTokens, NativeTokenNear, NearExplorerMap, NearExplorerNames, NearExplorerUrls, NearExplorers, NearTokens, WarpNearConstants, WarpNearDataLoader, WarpNearExecutor, WarpNearExplorer, WarpNearOutput, WarpNearSerializer, WarpNearWallet, findKnownTokenById, getKnownTokensForChain, getNearAdapter };
151
+ 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
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  ExplorerUrls: () => ExplorerUrls,
34
34
  KnownTokens: () => KnownTokens,
35
35
  NativeTokenNear: () => NativeTokenNear,
36
+ NearAdapter: () => NearAdapter,
36
37
  NearExplorerMap: () => NearExplorerMap,
37
38
  NearExplorerNames: () => NearExplorerNames,
38
39
  NearExplorerUrls: () => NearExplorerUrls,
@@ -46,8 +47,7 @@ __export(index_exports, {
46
47
  WarpNearSerializer: () => WarpNearSerializer,
47
48
  WarpNearWallet: () => WarpNearWallet,
48
49
  findKnownTokenById: () => findKnownTokenById,
49
- getKnownTokensForChain: () => getKnownTokensForChain,
50
- getNearAdapter: () => getNearAdapter
50
+ getKnownTokensForChain: () => getKnownTokensForChain
51
51
  });
52
52
  module.exports = __toCommonJS(index_exports);
53
53
 
@@ -929,73 +929,54 @@ var WarpNearExplorer = class {
929
929
  };
930
930
 
931
931
  // src/WarpNearWallet.ts
932
+ var import_warps8 = require("@vleap/warps");
933
+ var import_near_api_js6 = require("near-api-js");
934
+
935
+ // src/providers/MnemonicWalletProvider.ts
932
936
  var import_crypto = require("@near-js/crypto");
933
937
  var bip39 = __toESM(require("@scure/bip39"), 1);
934
938
  var import_english = require("@scure/bip39/wordlists/english.js");
935
939
  var import_warps5 = require("@vleap/warps");
936
940
  var import_bs58 = __toESM(require("bs58"), 1);
937
941
  var import_near_api_js4 = require("near-api-js");
938
- var WarpNearWallet = class {
942
+ var MnemonicWalletProvider = class {
939
943
  constructor(config, chain) {
940
944
  this.config = config;
941
945
  this.chain = chain;
942
- const providerConfig = (0, import_warps5.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
943
- this.nearConfig = {
944
- networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
945
- nodeUrl: providerConfig.url,
946
- keyStore: new import_near_api_js4.keyStores.InMemoryKeyStore()
947
- };
946
+ this.keypair = null;
948
947
  }
949
- async signTransaction(tx) {
950
- if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
951
- const keyPair = this.getKeyPair();
952
- const accountId = this.getAddress();
953
- if (!accountId) throw new Error("No account ID available");
954
- await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
955
- const near = await (0, import_near_api_js4.connect)(this.nearConfig);
956
- const account = await near.account(accountId);
957
- if (tx.signature) {
958
- return tx;
948
+ async getAddress() {
949
+ const address = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
950
+ if (address) return address;
951
+ try {
952
+ const keypair = this.getKeyPair();
953
+ const publicKey = keypair.getPublicKey();
954
+ return (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
955
+ } catch {
956
+ return null;
959
957
  }
960
- const signedTx = await account.signAndSendTransaction({
961
- receiverId: tx.receiverId,
962
- actions: tx.actions
963
- });
964
- return {
965
- ...tx,
966
- signature: signedTx.transaction.hash,
967
- transactionHash: signedTx.transaction.hash
968
- };
969
958
  }
970
- async signTransactions(txs) {
971
- if (txs.length === 0) return [];
972
- return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
959
+ async getPublicKey() {
960
+ try {
961
+ const keypair = this.getKeyPair();
962
+ const publicKey = keypair.getPublicKey();
963
+ return publicKey.toString();
964
+ } catch {
965
+ return null;
966
+ }
967
+ }
968
+ async signTransaction(tx) {
969
+ const keypair = this.getKeyPair();
970
+ return tx;
973
971
  }
974
972
  async signMessage(message) {
975
- const keyPair = this.getKeyPair();
973
+ const keypair = this.getKeyPair();
976
974
  const messageBytes = new TextEncoder().encode(message);
977
- const signature = keyPair.sign(messageBytes);
975
+ const signature = keypair.sign(messageBytes);
978
976
  return import_bs58.default.encode(signature.signature);
979
977
  }
980
- async sendTransaction(tx) {
981
- if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
982
- const keyPair = this.getKeyPair();
983
- const accountId = this.getAddress();
984
- if (!accountId) throw new Error("No account ID available");
985
- await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
986
- const near = await (0, import_near_api_js4.connect)(this.nearConfig);
987
- const account = await near.account(accountId);
988
- if (tx.transactionHash) {
989
- return tx.transactionHash;
990
- }
991
- const result = await account.signAndSendTransaction({
992
- receiverId: tx.receiverId,
993
- actions: tx.actions
994
- });
995
- return result.transaction.hash;
996
- }
997
- async sendTransactions(txs) {
998
- return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
978
+ getKeyPairInstance() {
979
+ return this.getKeyPair();
999
980
  }
1000
981
  create(mnemonic) {
1001
982
  const seed = bip39.mnemonicToSeedSync(mnemonic);
@@ -1003,6 +984,7 @@ var WarpNearWallet = class {
1003
984
  const publicKey = keyPair.getPublicKey();
1004
985
  const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
1005
986
  return {
987
+ provider: "mnemonic",
1006
988
  address: accountId,
1007
989
  privateKey: keyPair.toString(),
1008
990
  mnemonic
@@ -1015,75 +997,250 @@ var WarpNearWallet = class {
1015
997
  const publicKey = keyPair.getPublicKey();
1016
998
  const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
1017
999
  return {
1000
+ provider: "mnemonic",
1018
1001
  address: accountId,
1019
1002
  privateKey: keyPair.toString(),
1020
1003
  mnemonic
1021
1004
  };
1022
1005
  }
1023
- getAddress() {
1006
+ getKeyPair() {
1007
+ if (this.keypair) return this.keypair;
1008
+ const mnemonic = (0, import_warps5.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
1009
+ if (!mnemonic) throw new Error("No mnemonic provided");
1010
+ const seed = bip39.mnemonicToSeedSync(mnemonic);
1011
+ this.keypair = import_near_api_js4.KeyPair.fromRandom("ed25519");
1012
+ return this.keypair;
1013
+ }
1014
+ };
1015
+
1016
+ // src/providers/PrivateKeyWalletProvider.ts
1017
+ 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
+ var import_warps6 = require("@vleap/warps");
1021
+ var import_bs582 = __toESM(require("bs58"), 1);
1022
+ var import_near_api_js5 = require("near-api-js");
1023
+ var PrivateKeyWalletProvider = class {
1024
+ constructor(config, chain) {
1025
+ this.config = config;
1026
+ this.chain = chain;
1027
+ this.keypair = null;
1028
+ }
1029
+ async getAddress() {
1030
+ const address = (0, import_warps6.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
1031
+ if (address) return address;
1024
1032
  try {
1025
- const wallet = this.config.user?.wallets?.[this.chain.name];
1026
- if (wallet && typeof wallet === "object" && "address" in wallet) {
1027
- return wallet.address;
1028
- }
1029
- if (wallet && typeof wallet === "string") {
1030
- return wallet;
1031
- }
1032
- const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
1033
- if (privateKey) {
1034
- try {
1035
- const keyPair = import_near_api_js4.KeyPair.fromString(privateKey);
1036
- const publicKey = keyPair.getPublicKey();
1037
- return (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
1038
- } catch {
1039
- return null;
1040
- }
1041
- }
1042
- const mnemonic = (0, import_warps5.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
1043
- if (mnemonic) {
1044
- const seed = bip39.mnemonicToSeedSync(mnemonic);
1045
- const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
1046
- const publicKey = keyPair.getPublicKey();
1047
- return (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
1048
- }
1049
- return null;
1033
+ const keypair = this.getKeyPair();
1034
+ const publicKey = keypair.getPublicKey();
1035
+ return (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
1050
1036
  } catch {
1051
1037
  return null;
1052
1038
  }
1053
1039
  }
1054
- getPublicKey() {
1040
+ async getPublicKey() {
1055
1041
  try {
1056
- const keyPair = this.getKeyPair();
1057
- const publicKey = keyPair.getPublicKey();
1042
+ const keypair = this.getKeyPair();
1043
+ const publicKey = keypair.getPublicKey();
1058
1044
  return publicKey.toString();
1059
1045
  } catch {
1060
1046
  return null;
1061
1047
  }
1062
1048
  }
1049
+ async signTransaction(tx) {
1050
+ const keypair = this.getKeyPair();
1051
+ return tx;
1052
+ }
1053
+ async signMessage(message) {
1054
+ const keypair = this.getKeyPair();
1055
+ const messageBytes = new TextEncoder().encode(message);
1056
+ const signature = keypair.sign(messageBytes);
1057
+ return import_bs582.default.encode(signature.signature);
1058
+ }
1059
+ getKeyPairInstance() {
1060
+ return this.getKeyPair();
1061
+ }
1062
+ create(mnemonic) {
1063
+ const seed = bip392.mnemonicToSeedSync(mnemonic);
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
+ };
1073
+ }
1074
+ generate() {
1075
+ const mnemonic = bip392.generateMnemonic(import_english2.wordlist);
1076
+ const seed = bip392.mnemonicToSeedSync(mnemonic);
1077
+ const keyPair = import_near_api_js5.KeyPair.fromRandom("ed25519");
1078
+ const publicKey = keyPair.getPublicKey();
1079
+ const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
1080
+ return {
1081
+ provider: "privateKey",
1082
+ address: accountId,
1083
+ privateKey: keyPair.toString(),
1084
+ mnemonic
1085
+ };
1086
+ }
1063
1087
  getKeyPair() {
1064
- const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
1065
- if (privateKey) {
1066
- try {
1067
- try {
1068
- return import_near_api_js4.KeyPair.fromString(privateKey);
1069
- } catch {
1070
- }
1071
- const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
1072
- return keyPair;
1073
- } catch (error) {
1074
- if (error instanceof Error) {
1075
- throw new Error(`Invalid private key format: ${error.message}`);
1076
- }
1077
- throw new Error("Invalid private key format");
1088
+ if (this.keypair) return this.keypair;
1089
+ const privateKey = (0, import_warps6.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
1090
+ if (!privateKey) throw new Error("No private key provided");
1091
+ try {
1092
+ return import_near_api_js5.KeyPair.fromString(privateKey);
1093
+ } catch (error) {
1094
+ if (error instanceof Error) {
1095
+ throw new Error(`Invalid private key format: ${error.message}`);
1078
1096
  }
1097
+ throw new Error("Invalid private key format");
1079
1098
  }
1080
- const mnemonic = (0, import_warps5.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
1081
- if (mnemonic) {
1082
- const seed = bip39.mnemonicToSeedSync(mnemonic);
1083
- const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
1084
- return keyPair;
1099
+ }
1100
+ };
1101
+
1102
+ // src/providers/ReadOnlyWalletProvider.ts
1103
+ var import_warps7 = require("@vleap/warps");
1104
+ var ReadOnlyWalletProvider = class {
1105
+ constructor(config, chain) {
1106
+ this.config = config;
1107
+ this.chain = chain;
1108
+ }
1109
+ async getAddress() {
1110
+ return (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
1111
+ }
1112
+ async getPublicKey() {
1113
+ return null;
1114
+ }
1115
+ async signTransaction(tx) {
1116
+ const address = await this.getAddress();
1117
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1118
+ }
1119
+ async signMessage(message) {
1120
+ const address = await this.getAddress();
1121
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1122
+ }
1123
+ create(mnemonic) {
1124
+ const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
1125
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1126
+ }
1127
+ generate() {
1128
+ const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
1129
+ throw new Error(`Wallet can not be used for signing: ${address}`);
1130
+ }
1131
+ };
1132
+
1133
+ // src/WarpNearWallet.ts
1134
+ var WarpNearWallet = class {
1135
+ constructor(config, chain) {
1136
+ this.config = config;
1137
+ this.chain = chain;
1138
+ this.cachedAddress = null;
1139
+ this.cachedPublicKey = null;
1140
+ const providerConfig = (0, import_warps8.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
1141
+ this.nearConfig = {
1142
+ networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
1143
+ nodeUrl: providerConfig.url,
1144
+ keyStore: new import_near_api_js6.keyStores.InMemoryKeyStore()
1145
+ };
1146
+ this.walletProvider = this.createProvider();
1147
+ this.initializeCache();
1148
+ }
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
+ async signTransaction(tx) {
1167
+ if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1168
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1169
+ if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
1170
+ const accountId = this.getAddress();
1171
+ if (!accountId) throw new Error("No account ID available");
1172
+ if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1173
+ const keyPair = this.walletProvider.getKeyPairInstance();
1174
+ await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
1175
+ const near = await (0, import_near_api_js6.connect)(this.nearConfig);
1176
+ const account = await near.account(accountId);
1177
+ if (tx.signature) {
1178
+ return tx;
1179
+ }
1180
+ const signedTx = await account.signAndSendTransaction({
1181
+ receiverId: tx.receiverId,
1182
+ actions: tx.actions
1183
+ });
1184
+ return {
1185
+ ...tx,
1186
+ signature: signedTx.transaction.hash,
1187
+ transactionHash: signedTx.transaction.hash
1188
+ };
1189
+ }
1190
+ throw new Error("Wallet provider does not support signing transactions");
1191
+ }
1192
+ async signTransactions(txs) {
1193
+ if (txs.length === 0) return [];
1194
+ const signedTxs = [];
1195
+ for (const tx of txs) {
1196
+ signedTxs.push(await this.signTransaction(tx));
1197
+ }
1198
+ return signedTxs;
1199
+ }
1200
+ async signMessage(message) {
1201
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1202
+ if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
1203
+ return await this.walletProvider.signMessage(message);
1204
+ }
1205
+ async sendTransaction(tx) {
1206
+ if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1207
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1208
+ const accountId = this.getAddress();
1209
+ if (!accountId) throw new Error("No account ID available");
1210
+ if (tx.transactionHash) {
1211
+ return tx.transactionHash;
1212
+ }
1213
+ if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1214
+ const keyPair = this.walletProvider.getKeyPairInstance();
1215
+ await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
1216
+ const near = await (0, import_near_api_js6.connect)(this.nearConfig);
1217
+ const account = await near.account(accountId);
1218
+ const result = await account.signAndSendTransaction({
1219
+ receiverId: tx.receiverId,
1220
+ actions: tx.actions
1221
+ });
1222
+ return result.transaction.hash;
1085
1223
  }
1086
- throw new Error("No private key or mnemonic provided");
1224
+ throw new Error("Wallet provider does not support sending transactions");
1225
+ }
1226
+ async sendTransactions(txs) {
1227
+ return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
1228
+ }
1229
+ create(mnemonic) {
1230
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1231
+ if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
1232
+ return this.walletProvider.create(mnemonic);
1233
+ }
1234
+ generate() {
1235
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1236
+ if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
1237
+ return this.walletProvider.generate();
1238
+ }
1239
+ getAddress() {
1240
+ return this.cachedAddress;
1241
+ }
1242
+ getPublicKey() {
1243
+ return this.cachedPublicKey;
1087
1244
  }
1088
1245
  };
1089
1246
 
@@ -1116,7 +1273,7 @@ var NativeTokenNear = {
1116
1273
  decimals: 24,
1117
1274
  logoUrl: "https://joai.ai/images/tokens/near-black.svg"
1118
1275
  };
1119
- var getNearAdapter = createNearAdapter("near", {
1276
+ var NearAdapter = createNearAdapter("near", {
1120
1277
  mainnet: {
1121
1278
  name: "near",
1122
1279
  displayName: "NEAR Mainnet",
@@ -1153,6 +1310,7 @@ var getNearAdapter = createNearAdapter("near", {
1153
1310
  ExplorerUrls,
1154
1311
  KnownTokens,
1155
1312
  NativeTokenNear,
1313
+ NearAdapter,
1156
1314
  NearExplorerMap,
1157
1315
  NearExplorerNames,
1158
1316
  NearExplorerUrls,
@@ -1166,7 +1324,6 @@ var getNearAdapter = createNearAdapter("near", {
1166
1324
  WarpNearSerializer,
1167
1325
  WarpNearWallet,
1168
1326
  findKnownTokenById,
1169
- getKnownTokensForChain,
1170
- getNearAdapter
1327
+ getKnownTokensForChain
1171
1328
  });
1172
1329
  //# sourceMappingURL=index.js.map