浏览代码

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

Kevin Peters 2 年之前
父节点
当前提交
7bc96a1ebc
共有 2 个文件被更改,包括 13 次插入4 次删除
  1. 2 2
      clients/js/src/networks.ts
  2. 11 2
      clients/js/src/sui/utils.ts

+ 2 - 2
clients/js/src/networks.ts

@@ -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/",

+ 11 - 2
clients/js/src/sui/utils.ts

@@ -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);
 };