Created
October 26, 2021 18:49
-
-
Save gregsantos/2f0480662d36dd4904a53e6d6c07e619 to your computer and use it in GitHub Desktop.
account-proof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Authentication Proof Service | |
| { | |
| "f_type": "Service", | |
| "f_vsn": "1.0.0", | |
| "type": "account-proof", | |
| "method": "DATA", | |
| "uid": "fcl-dev-wallet#account-proof", | |
| "data": { | |
| "f_type": "account-proof", | |
| "f_vsn": "1.0.0", | |
| "address": "0x179b6b1cb6755e31", | |
| "timestamp": 1635272113264, | |
| "appDomainTag": "APP-V0.0-user", // default | |
| "signatures": [ | |
| { | |
| "f_type": "CompositeSignature", | |
| "f_vsn": "1.0.0", | |
| "addr": "0x179b6b1cb6755e31", // with prefix | |
| "keyId": 0, | |
| "signature": "542b9..." | |
| } | |
| ] | |
| } | |
| } | |
| // signature production | |
| signature: sign( | |
| accountPrivateKey, | |
| fcl.WalletUtils.encodeMessageForProvableAuthnSigning( | |
| address, | |
| timestamp, | |
| appDomainTag | |
| ) | |
| ) | |
| import {ec as EC} from "elliptic" | |
| import {SHA3} from "sha3" | |
| const ec = new EC("p256") | |
| const hashMsgHex = (msgHex: string) => { | |
| const sha = new SHA3(256) | |
| sha.update(Buffer.from(msgHex, "hex")) | |
| return sha.digest() | |
| } | |
| export function sign(accountPrivateKey: string, msgHex: string) { | |
| const key = ec.keyFromPrivate(Buffer.from(accountPrivateKey, "hex")) | |
| const sig = key.sign(hashMsgHex(msgHex)) | |
| const n = 32 | |
| const r = sig.r.toArrayLike(Buffer, "be", n) | |
| const s = sig.s.toArrayLike(Buffer, "be", n) | |
| return Buffer.concat([r, s]).toString("hex") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment