@vleap/warps-adapter-near 0.1.0-beta.4 → 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 +222 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -107
- 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,73 +929,54 @@ 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
|
|
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
|
|
942
|
+
var MnemonicWalletProvider = class {
|
|
939
943
|
constructor(config, chain) {
|
|
940
944
|
this.config = config;
|
|
941
945
|
this.chain = chain;
|
|
942
|
-
|
|
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
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
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
|
|
971
|
-
|
|
972
|
-
|
|
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
|
|
973
|
+
const keypair = this.getKeyPair();
|
|
976
974
|
const messageBytes = new TextEncoder().encode(message);
|
|
977
|
-
const signature =
|
|
975
|
+
const signature = keypair.sign(messageBytes);
|
|
978
976
|
return import_bs58.default.encode(signature.signature);
|
|
979
977
|
}
|
|
980
|
-
|
|
981
|
-
|
|
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,211 @@ 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
|
-
|
|
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
|
|
1026
|
-
|
|
1027
|
-
|
|
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
|
|
1057
|
-
const publicKey =
|
|
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
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
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
|
+
};
|
|
1085
1157
|
}
|
|
1086
|
-
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;
|
|
1087
1205
|
}
|
|
1088
1206
|
};
|
|
1089
1207
|
|
|
@@ -1116,7 +1234,7 @@ var NativeTokenNear = {
|
|
|
1116
1234
|
decimals: 24,
|
|
1117
1235
|
logoUrl: "https://joai.ai/images/tokens/near-black.svg"
|
|
1118
1236
|
};
|
|
1119
|
-
var
|
|
1237
|
+
var NearAdapter = createNearAdapter("near", {
|
|
1120
1238
|
mainnet: {
|
|
1121
1239
|
name: "near",
|
|
1122
1240
|
displayName: "NEAR Mainnet",
|
|
@@ -1153,6 +1271,7 @@ var getNearAdapter = createNearAdapter("near", {
|
|
|
1153
1271
|
ExplorerUrls,
|
|
1154
1272
|
KnownTokens,
|
|
1155
1273
|
NativeTokenNear,
|
|
1274
|
+
NearAdapter,
|
|
1156
1275
|
NearExplorerMap,
|
|
1157
1276
|
NearExplorerNames,
|
|
1158
1277
|
NearExplorerUrls,
|
|
@@ -1166,7 +1285,6 @@ var getNearAdapter = createNearAdapter("near", {
|
|
|
1166
1285
|
WarpNearSerializer,
|
|
1167
1286
|
WarpNearWallet,
|
|
1168
1287
|
findKnownTokenById,
|
|
1169
|
-
getKnownTokensForChain
|
|
1170
|
-
getNearAdapter
|
|
1288
|
+
getKnownTokensForChain
|
|
1171
1289
|
});
|
|
1172
1290
|
//# sourceMappingURL=index.js.map
|