@hankolabs/attestation-engine
v0.1.2
Published
Ed25519 typed attestation issuer + verifier. EIP-712 domain-separator pattern ported to Ed25519 for on-chain verification via Solana's Instructions sysvar.
Maintainers
Readme
@hankolabs/attestation-engine
Ed25519 typed attestation issuer and verifier for the HANKO Solana Agent Trust Registry.
It ports the EIP-712 domain-separator pattern to Ed25519 so the resulting signature can be verified inside a Solana program via the Instructions sysvar. The same canonical byte layout is produced off-chain (this package) and hashed on-chain (the Anchor program), so a signature made here validates in post_attestation.
Install
npm install @hankolabs/attestation-engineCanonical message layout
Byte-for-byte identical to the program's util.rs::canonical_attestation_message
(125 bytes):
"hanko-attest"(12) || client(32) || agent(32) || score(i8) ||
tag_bitmap(u64 le) || uri_hash(32) || nonce(u64 le)The domain separator is the fixed 12-byte ASCII prefix hanko-attest. The client
(attester) is the Ed25519 signer.
Usage
import { PublicKey } from "@solana/web3.js";
import nacl from "tweetnacl";
import {
signAttestation,
verifyAttestation,
} from "@hankolabs/attestation-engine";
const client = nacl.sign.keyPair();
const params = {
client: new PublicKey(client.publicKey),
agent: new PublicKey("8N3v..."),
score: 90, // i8, range [-100, 100]
tagBitmap: 0b101n, // u64 tag bitmap
uriHash: new Uint8Array(32),
nonce: 1n,
};
const signature = signAttestation(params, client.secretKey);
const ok = verifyAttestation(params, signature, new PublicKey(client.publicKey));API
| Export | Description |
| ------ | ----------- |
| canonicalMessage(params) | Build the 125-byte canonical bytes that must be signed. |
| signAttestation(params, secretKey) | Ed25519 sign the canonical message (64-byte nacl secret key). |
| verifyAttestation(params, signature, clientPublicKey) | Verify a signature against its canonical message. |
| validationCommitment(expectedHash, salt) | sha256(expected_hash \|\| salt) — the Validation Registry commitment. |
| bs58Encode(bytes) / bs58Decode(text) | Base58 helpers. |
| HANKO_ATTESTATION_DOMAIN | The 12-byte domain prefix constant. |
score outside [-100, 100] or a uriHash that is not exactly 32 bytes throws.
License
MIT
