clients/js: added sui mainnet rpc, allow key to be hex or base64

This commit is contained in:
Kevin Peters 2023-05-31 02:59:04 +00:00 committed by kev1n-peters
parent c5523d39fc
commit 7bc96a1ebc
2 changed files with 13 additions and 4 deletions

View File

@ -101,8 +101,8 @@ const MAINNET = {
key: get_env_var("APTOS_KEY"),
},
sui: {
rpc: undefined,
key: undefined,
rpc: "https://fullnode.mainnet.sui.io:443",
key: get_env_var("SUI_KEY"),
},
pythnet: {
rpc: "http://api.pythnet.pyth.network:8899/",

View File

@ -240,8 +240,17 @@ export const getSigner = (
throw new Error(`No private key found for Sui ${network}`);
}
const bytes = fromB64(privateKey);
const keypair = Ed25519Keypair.fromSecretKey(bytes.slice(1));
let bytes = privateKey.startsWith("0x")
? Buffer.from(privateKey.slice(2), "hex")
: fromB64(privateKey);
if (bytes.length === 33) {
// remove the first flag byte after checking it is indeed the Ed25519 scheme flag 0x00
if (bytes[0] !== 0) {
throw new Error("Only the Ed25519 scheme flag is supported");
}
bytes = bytes.subarray(1);
}
const keypair = Ed25519Keypair.fromSecretKey(bytes);
return new RawSigner(keypair, provider);
};