MCPcopy Create free account
hub / github.com/B3Pay/B3Wallet / decode

Function decode

scripts/utils.ts:15–32  ·  view source on GitHub ↗
(rawKey: string)

Source from the content-addressed store, hash-verified

13 * Forum: https://forum.dfinity.org/t/using-dfinity-agent-in-node-js/6169/60?u=peterparker
14 */
15const decode = (rawKey: string) => {
16 const buf = pemfile.decode(rawKey)
17
18 if (rawKey.includes("EC PRIVATE KEY")) {
19 if (buf.length !== 118) {
20 throw Error("expecting byte length 118 but got " + buf.length)
21 }
22
23 return Secp256k1KeyIdentity.fromSecretKey(buf.slice(7, 39))
24 }
25
26 if (buf.length !== 85) {
27 throw Error("expecting byte length 85 but got " + buf.length)
28 }
29
30 const secretKey = Buffer.concat([buf.slice(16, 48)])
31 return Ed25519KeyIdentity.fromSecretKey(secretKey)
32}
33
34export const initIdentity = (mainnet: boolean) => {
35 const userHomeDir = os.homedir()

Callers 3

parse_base58_addressFunction · 0.85
parse_bip173_addressFunction · 0.85
initIdentityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected