clients/js: fixes hardcoded Near deployer implicit account id. (#3248)
* clients/js: fixes hardcoded Near deployer implicit account id. * clients/js: remove near deployerAccount --------- Co-authored-by: Evan Gray <battledingo@gmail.com>
This commit is contained in:
parent
b175dd43c8
commit
9634d59035
|
@ -25,6 +25,7 @@ test: build
|
||||||
# This first invocation will set up the initial config, so that the warning
|
# This first invocation will set up the initial config, so that the warning
|
||||||
# doesn't show up in the tests
|
# doesn't show up in the tests
|
||||||
npm run check
|
npm run check
|
||||||
|
npm test
|
||||||
node build/main.js --version > /dev/null
|
node build/main.js --version > /dev/null
|
||||||
./run_parse_tests
|
./run_parse_tests
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^@certusone/(.*)/lib/esm/(.*)$": "@certusone/$1/lib/cjs/$2"
|
||||||
|
},
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)sx?$": "ts-jest"
|
||||||
|
},
|
||||||
|
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||||
|
"testPathIgnorePatterns": ["__tests__/utils"],
|
||||||
|
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
||||||
|
"testTimeout": 60000
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,7 @@
|
||||||
"check": "tsc --noEmit",
|
"check": "tsc --noEmit",
|
||||||
"docs": "npx tsx src/doc.ts",
|
"docs": "npx tsx src/doc.ts",
|
||||||
"prepublishOnly": "npm run check",
|
"prepublishOnly": "npm run check",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"author": "Wormhole Contributors",
|
"author": "Wormhole Contributors",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
@ -64,9 +64,12 @@
|
||||||
"@truffle/hdwallet-provider": "^2.0.15",
|
"@truffle/hdwallet-provider": "^2.0.15",
|
||||||
"@types/bn.js": "^5.1.0",
|
"@types/bn.js": "^5.1.0",
|
||||||
"@types/bs58": "^4.0.1",
|
"@types/bs58": "^4.0.1",
|
||||||
|
"@types/jest": "^29.5.12",
|
||||||
"@types/node-fetch": "^2.6.3",
|
"@types/node-fetch": "^2.6.3",
|
||||||
"@types/yargs": "^17.0.24",
|
"@types/yargs": "^17.0.24",
|
||||||
"copy-dir": "^1.3.0",
|
"copy-dir": "^1.3.0",
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"ts-jest": "^29.1.2",
|
||||||
"typescript": "^4.6"
|
"typescript": "^4.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,8 +92,6 @@ const MAINNET = {
|
||||||
rpc: "https://rpc.mainnet.near.org",
|
rpc: "https://rpc.mainnet.near.org",
|
||||||
key: getEnvVar("NEAR_KEY"),
|
key: getEnvVar("NEAR_KEY"),
|
||||||
networkId: "mainnet",
|
networkId: "mainnet",
|
||||||
deployerAccount:
|
|
||||||
"85957f38de1768d6db9eab29bee9dd2a01462aff9c8d83daefb9bcd2506c32d2",
|
|
||||||
},
|
},
|
||||||
injective: {
|
injective: {
|
||||||
rpc: "http://sentry0.injective.network:26657",
|
rpc: "http://sentry0.injective.network:26657",
|
||||||
|
@ -332,7 +330,6 @@ const TESTNET = {
|
||||||
rpc: "https://rpc.testnet.near.org",
|
rpc: "https://rpc.testnet.near.org",
|
||||||
key: getEnvVar("NEAR_KEY_TESTNET"),
|
key: getEnvVar("NEAR_KEY_TESTNET"),
|
||||||
networkId: "testnet",
|
networkId: "testnet",
|
||||||
deployerAccount: "wormhole.testnet",
|
|
||||||
},
|
},
|
||||||
injective: {
|
injective: {
|
||||||
rpc: "https://k8s.testnet.tm.injective.network:443",
|
rpc: "https://k8s.testnet.tm.injective.network:443",
|
||||||
|
@ -561,7 +558,6 @@ const DEVNET = {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
key: undefined,
|
key: undefined,
|
||||||
networkId: "sandbox",
|
networkId: "sandbox",
|
||||||
deployerAccount: "test.near",
|
|
||||||
},
|
},
|
||||||
injective: {
|
injective: {
|
||||||
rpc: undefined,
|
rpc: undefined,
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { parseSeedPhrase } from "near-seed-phrase";
|
||||||
|
import { test } from "@jest/globals";
|
||||||
|
import { KeyPair } from "near-api-js";
|
||||||
|
import { keyPairToImplicitAccount } from "./near";
|
||||||
|
import base58 from "bs58";
|
||||||
|
|
||||||
|
test("keyPairToImplicitAccount", () => {
|
||||||
|
// seed phrase from /near/devnet_deploy.ts
|
||||||
|
const parsed = parseSeedPhrase(
|
||||||
|
"weather opinion slam purpose access artefact word orbit matter rice poem badge"
|
||||||
|
);
|
||||||
|
const expectedImplicitAccount = base58
|
||||||
|
.decode(parsed.publicKey.split(":")[1])
|
||||||
|
.toString("hex");
|
||||||
|
|
||||||
|
const keyPair = KeyPair.fromString(parsed.secretKey);
|
||||||
|
const implicitAccount = keyPairToImplicitAccount(keyPair);
|
||||||
|
expect(implicitAccount.length).toEqual(64);
|
||||||
|
expect(implicitAccount).toEqual(expectedImplicitAccount);
|
||||||
|
});
|
|
@ -14,12 +14,16 @@ import {
|
||||||
} from "@certusone/wormhole-sdk/lib/esm/token_bridge/transfer";
|
} from "@certusone/wormhole-sdk/lib/esm/token_bridge/transfer";
|
||||||
import { tryNativeToUint8Array } from "@certusone/wormhole-sdk/lib/esm/utils";
|
import { tryNativeToUint8Array } from "@certusone/wormhole-sdk/lib/esm/utils";
|
||||||
|
|
||||||
|
export function keyPairToImplicitAccount(keyPair: KeyPair): string {
|
||||||
|
return Buffer.from(keyPair.getPublicKey().data).toString("hex");
|
||||||
|
}
|
||||||
|
|
||||||
export const execute_near = async (
|
export const execute_near = async (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
vaa: string,
|
vaa: string,
|
||||||
network: Network
|
network: Network
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { rpc, key, networkId, deployerAccount } = NETWORKS[network].near;
|
const { rpc, key, networkId } = NETWORKS[network].near;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
throw Error(`No ${network} key defined for NEAR`);
|
throw Error(`No ${network} key defined for NEAR`);
|
||||||
}
|
}
|
||||||
|
@ -113,8 +117,10 @@ export const execute_near = async (
|
||||||
impossible(payload);
|
impossible(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keyPair = KeyPair.fromString(key);
|
||||||
|
const deployerAccount = keyPairToImplicitAccount(keyPair);
|
||||||
const keyStore = new InMemoryKeyStore();
|
const keyStore = new InMemoryKeyStore();
|
||||||
keyStore.setKey(networkId, deployerAccount, KeyPair.fromString(key));
|
keyStore.setKey(networkId, deployerAccount, keyPair);
|
||||||
const near = await connect({
|
const near = await connect({
|
||||||
keyStore,
|
keyStore,
|
||||||
networkId,
|
networkId,
|
||||||
|
@ -159,7 +165,7 @@ export async function transferNear(
|
||||||
network: Network,
|
network: Network,
|
||||||
rpc: string
|
rpc: string
|
||||||
) {
|
) {
|
||||||
const { key, networkId, deployerAccount } = NETWORKS[network].near;
|
const { key, networkId } = NETWORKS[network].near;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
throw Error(`No ${network} key defined for NEAR`);
|
throw Error(`No ${network} key defined for NEAR`);
|
||||||
}
|
}
|
||||||
|
@ -170,8 +176,10 @@ export async function transferNear(
|
||||||
if (token_bridge === undefined) {
|
if (token_bridge === undefined) {
|
||||||
throw Error(`Unknown token bridge contract on ${network} for NEAR`);
|
throw Error(`Unknown token bridge contract on ${network} for NEAR`);
|
||||||
}
|
}
|
||||||
|
const keyPair = KeyPair.fromString(key);
|
||||||
|
const deployerAccount = keyPairToImplicitAccount(keyPair);
|
||||||
const keyStore = new InMemoryKeyStore();
|
const keyStore = new InMemoryKeyStore();
|
||||||
keyStore.setKey(networkId, deployerAccount, KeyPair.fromString(key));
|
keyStore.setKey(networkId, deployerAccount, keyPair);
|
||||||
const near = await connect({
|
const near = await connect({
|
||||||
keyStore,
|
keyStore,
|
||||||
networkId,
|
networkId,
|
||||||
|
|
Loading…
Reference in New Issue