@vleap/warps-adapter-near 0.1.0-beta.3 → 0.1.0-beta.5
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 +10 -14
- package/dist/index.d.ts +10 -14
- package/dist/index.js +225 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +226 -108
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WarpChainAsset,
|
|
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
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
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,79 +929,62 @@ var WarpNearExplorer = class {
|
|
|
929
929
|
};
|
|
930
930
|
|
|
931
931
|
// src/WarpNearWallet.ts
|
|
932
|
+
var import_warps7 = require("@vleap/warps");
|
|
933
|
+
var import_near_api_js6 = require("near-api-js");
|
|
934
|
+
|
|
935
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
936
|
+
var import_crypto = require("@near-js/crypto");
|
|
932
937
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
933
938
|
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
934
939
|
var import_warps5 = require("@vleap/warps");
|
|
935
940
|
var import_bs58 = __toESM(require("bs58"), 1);
|
|
936
941
|
var import_near_api_js4 = require("near-api-js");
|
|
937
|
-
var
|
|
942
|
+
var MnemonicWalletProvider = class {
|
|
938
943
|
constructor(config, chain) {
|
|
939
944
|
this.config = config;
|
|
940
945
|
this.chain = chain;
|
|
941
|
-
|
|
942
|
-
this.nearConfig = {
|
|
943
|
-
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
944
|
-
nodeUrl: providerConfig.url,
|
|
945
|
-
keyStore: new import_near_api_js4.keyStores.InMemoryKeyStore()
|
|
946
|
-
};
|
|
946
|
+
this.keypair = null;
|
|
947
947
|
}
|
|
948
|
-
async
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
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;
|
|
958
957
|
}
|
|
959
|
-
const signedTx = await account.signAndSendTransaction({
|
|
960
|
-
receiverId: tx.receiverId,
|
|
961
|
-
actions: tx.actions
|
|
962
|
-
});
|
|
963
|
-
return {
|
|
964
|
-
...tx,
|
|
965
|
-
signature: signedTx.transaction.hash,
|
|
966
|
-
transactionHash: signedTx.transaction.hash
|
|
967
|
-
};
|
|
968
958
|
}
|
|
969
|
-
async
|
|
970
|
-
|
|
971
|
-
|
|
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;
|
|
972
971
|
}
|
|
973
972
|
async signMessage(message) {
|
|
974
|
-
const
|
|
973
|
+
const keypair = this.getKeyPair();
|
|
975
974
|
const messageBytes = new TextEncoder().encode(message);
|
|
976
|
-
const signature =
|
|
975
|
+
const signature = keypair.sign(messageBytes);
|
|
977
976
|
return import_bs58.default.encode(signature.signature);
|
|
978
977
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
const keyPair = this.getKeyPair();
|
|
982
|
-
const accountId = this.getAddress();
|
|
983
|
-
if (!accountId) throw new Error("No account ID available");
|
|
984
|
-
await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
|
|
985
|
-
const near = await (0, import_near_api_js4.connect)(this.nearConfig);
|
|
986
|
-
const account = await near.account(accountId);
|
|
987
|
-
if (tx.transactionHash) {
|
|
988
|
-
return tx.transactionHash;
|
|
989
|
-
}
|
|
990
|
-
const result = await account.signAndSendTransaction({
|
|
991
|
-
receiverId: tx.receiverId,
|
|
992
|
-
actions: tx.actions
|
|
993
|
-
});
|
|
994
|
-
return result.transaction.hash;
|
|
995
|
-
}
|
|
996
|
-
async sendTransactions(txs) {
|
|
997
|
-
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
978
|
+
getKeyPairInstance() {
|
|
979
|
+
return this.getKeyPair();
|
|
998
980
|
}
|
|
999
981
|
create(mnemonic) {
|
|
1000
982
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1001
983
|
const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
|
|
1002
984
|
const publicKey = keyPair.getPublicKey();
|
|
1003
|
-
const accountId =
|
|
985
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
1004
986
|
return {
|
|
987
|
+
provider: "mnemonic",
|
|
1005
988
|
address: accountId,
|
|
1006
989
|
privateKey: keyPair.toString(),
|
|
1007
990
|
mnemonic
|
|
@@ -1012,77 +995,213 @@ var WarpNearWallet = class {
|
|
|
1012
995
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1013
996
|
const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
|
|
1014
997
|
const publicKey = keyPair.getPublicKey();
|
|
1015
|
-
const accountId =
|
|
998
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
1016
999
|
return {
|
|
1000
|
+
provider: "mnemonic",
|
|
1017
1001
|
address: accountId,
|
|
1018
1002
|
privateKey: keyPair.toString(),
|
|
1019
1003
|
mnemonic
|
|
1020
1004
|
};
|
|
1021
1005
|
}
|
|
1022
|
-
|
|
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;
|
|
1023
1032
|
try {
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
const keyPair = import_near_api_js4.KeyPair.fromString(privateKey);
|
|
1028
|
-
const publicKey = keyPair.getPublicKey();
|
|
1029
|
-
return publicKey.toString().split(":")[1] || publicKey.toString();
|
|
1030
|
-
} catch {
|
|
1031
|
-
return null;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
const mnemonic = (0, import_warps5.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1035
|
-
if (mnemonic) {
|
|
1036
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1037
|
-
const keyPair = import_near_api_js4.KeyPair.fromRandom("ed25519");
|
|
1038
|
-
const publicKey = keyPair.getPublicKey();
|
|
1039
|
-
return publicKey.toString().split(":")[1] || publicKey.toString();
|
|
1040
|
-
}
|
|
1041
|
-
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1042
|
-
if (wallet && typeof wallet === "object" && "address" in wallet) {
|
|
1043
|
-
return wallet.address;
|
|
1044
|
-
}
|
|
1045
|
-
if (wallet && typeof wallet === "string") {
|
|
1046
|
-
return wallet;
|
|
1047
|
-
}
|
|
1048
|
-
return null;
|
|
1033
|
+
const keypair = this.getKeyPair();
|
|
1034
|
+
const publicKey = keypair.getPublicKey();
|
|
1035
|
+
return (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1049
1036
|
} catch {
|
|
1050
1037
|
return null;
|
|
1051
1038
|
}
|
|
1052
1039
|
}
|
|
1053
|
-
getPublicKey() {
|
|
1040
|
+
async getPublicKey() {
|
|
1054
1041
|
try {
|
|
1055
|
-
const
|
|
1056
|
-
const publicKey =
|
|
1042
|
+
const keypair = this.getKeyPair();
|
|
1043
|
+
const publicKey = keypair.getPublicKey();
|
|
1057
1044
|
return publicKey.toString();
|
|
1058
1045
|
} catch {
|
|
1059
1046
|
return null;
|
|
1060
1047
|
}
|
|
1061
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
|
+
}
|
|
1062
1087
|
getKeyPair() {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
return keyPair;
|
|
1072
|
-
} catch (error) {
|
|
1073
|
-
if (error instanceof Error) {
|
|
1074
|
-
throw new Error(`Invalid private key format: ${error.message}`);
|
|
1075
|
-
}
|
|
1076
|
-
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}`);
|
|
1077
1096
|
}
|
|
1097
|
+
throw new Error("Invalid private key format");
|
|
1078
1098
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
// src/WarpNearWallet.ts
|
|
1103
|
+
var WarpNearWallet = class {
|
|
1104
|
+
constructor(config, chain) {
|
|
1105
|
+
this.config = config;
|
|
1106
|
+
this.chain = chain;
|
|
1107
|
+
this.cachedAddress = null;
|
|
1108
|
+
this.cachedPublicKey = null;
|
|
1109
|
+
const providerConfig = (0, import_warps7.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1110
|
+
this.nearConfig = {
|
|
1111
|
+
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
1112
|
+
nodeUrl: providerConfig.url,
|
|
1113
|
+
keyStore: new import_near_api_js6.keyStores.InMemoryKeyStore()
|
|
1114
|
+
};
|
|
1115
|
+
this.walletProvider = this.createProvider();
|
|
1116
|
+
this.initializeCache();
|
|
1117
|
+
}
|
|
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
|
+
async signTransaction(tx) {
|
|
1136
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1137
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1138
|
+
const accountId = this.getAddress();
|
|
1139
|
+
if (!accountId) throw new Error("No account ID available");
|
|
1140
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1141
|
+
const keyPair = this.walletProvider.getKeyPairInstance();
|
|
1142
|
+
await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
|
|
1143
|
+
const near = await (0, import_near_api_js6.connect)(this.nearConfig);
|
|
1144
|
+
const account = await near.account(accountId);
|
|
1145
|
+
if (tx.signature) {
|
|
1146
|
+
return tx;
|
|
1147
|
+
}
|
|
1148
|
+
const signedTx = await account.signAndSendTransaction({
|
|
1149
|
+
receiverId: tx.receiverId,
|
|
1150
|
+
actions: tx.actions
|
|
1151
|
+
});
|
|
1152
|
+
return {
|
|
1153
|
+
...tx,
|
|
1154
|
+
signature: signedTx.transaction.hash,
|
|
1155
|
+
transactionHash: signedTx.transaction.hash
|
|
1156
|
+
};
|
|
1084
1157
|
}
|
|
1085
|
-
throw new Error("
|
|
1158
|
+
throw new Error("Wallet provider does not support signing transactions");
|
|
1159
|
+
}
|
|
1160
|
+
async signTransactions(txs) {
|
|
1161
|
+
if (txs.length === 0) return [];
|
|
1162
|
+
return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
|
|
1163
|
+
}
|
|
1164
|
+
async signMessage(message) {
|
|
1165
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1166
|
+
return await this.walletProvider.signMessage(message);
|
|
1167
|
+
}
|
|
1168
|
+
async sendTransaction(tx) {
|
|
1169
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1170
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1171
|
+
const accountId = this.getAddress();
|
|
1172
|
+
if (!accountId) throw new Error("No account ID available");
|
|
1173
|
+
if (tx.transactionHash) {
|
|
1174
|
+
return tx.transactionHash;
|
|
1175
|
+
}
|
|
1176
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1177
|
+
const keyPair = this.walletProvider.getKeyPairInstance();
|
|
1178
|
+
await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
|
|
1179
|
+
const near = await (0, import_near_api_js6.connect)(this.nearConfig);
|
|
1180
|
+
const account = await near.account(accountId);
|
|
1181
|
+
const result = await account.signAndSendTransaction({
|
|
1182
|
+
receiverId: tx.receiverId,
|
|
1183
|
+
actions: tx.actions
|
|
1184
|
+
});
|
|
1185
|
+
return result.transaction.hash;
|
|
1186
|
+
}
|
|
1187
|
+
throw new Error("Wallet provider does not support sending transactions");
|
|
1188
|
+
}
|
|
1189
|
+
async sendTransactions(txs) {
|
|
1190
|
+
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1191
|
+
}
|
|
1192
|
+
create(mnemonic) {
|
|
1193
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1194
|
+
return this.walletProvider.create(mnemonic);
|
|
1195
|
+
}
|
|
1196
|
+
generate() {
|
|
1197
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1198
|
+
return this.walletProvider.generate();
|
|
1199
|
+
}
|
|
1200
|
+
getAddress() {
|
|
1201
|
+
return this.cachedAddress;
|
|
1202
|
+
}
|
|
1203
|
+
getPublicKey() {
|
|
1204
|
+
return this.cachedPublicKey;
|
|
1086
1205
|
}
|
|
1087
1206
|
};
|
|
1088
1207
|
|
|
@@ -1115,7 +1234,7 @@ var NativeTokenNear = {
|
|
|
1115
1234
|
decimals: 24,
|
|
1116
1235
|
logoUrl: "https://joai.ai/images/tokens/near-black.svg"
|
|
1117
1236
|
};
|
|
1118
|
-
var
|
|
1237
|
+
var NearAdapter = createNearAdapter("near", {
|
|
1119
1238
|
mainnet: {
|
|
1120
1239
|
name: "near",
|
|
1121
1240
|
displayName: "NEAR Mainnet",
|
|
@@ -1152,6 +1271,7 @@ var getNearAdapter = createNearAdapter("near", {
|
|
|
1152
1271
|
ExplorerUrls,
|
|
1153
1272
|
KnownTokens,
|
|
1154
1273
|
NativeTokenNear,
|
|
1274
|
+
NearAdapter,
|
|
1155
1275
|
NearExplorerMap,
|
|
1156
1276
|
NearExplorerNames,
|
|
1157
1277
|
NearExplorerUrls,
|
|
@@ -1165,7 +1285,6 @@ var getNearAdapter = createNearAdapter("near", {
|
|
|
1165
1285
|
WarpNearSerializer,
|
|
1166
1286
|
WarpNearWallet,
|
|
1167
1287
|
findKnownTokenById,
|
|
1168
|
-
getKnownTokensForChain
|
|
1169
|
-
getNearAdapter
|
|
1288
|
+
getKnownTokensForChain
|
|
1170
1289
|
});
|
|
1171
1290
|
//# sourceMappingURL=index.js.map
|