(rawKey: string)
| 13 | * Forum: https://forum.dfinity.org/t/using-dfinity-agent-in-node-js/6169/60?u=peterparker |
| 14 | */ |
| 15 | const 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 | |
| 34 | export const initIdentity = (mainnet: boolean) => { |
| 35 | const userHomeDir = os.homedir() |
no outgoing calls
no test coverage detected