SPB Git

Repository Public

generate.ts 6.4 KB 91 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Vault8 * File             : packages/crypto-test-vectors/generate.ts9 * Module           : crypto-test-vectors10 * Repository       : https://git.spboucher.ai/sp-vault11 * Project Website  : https://vault.spboucher.ai12 * Created          : 2026-11-1913 * Last Modified    : 2026-11-1914 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Generates spv1.json: deterministic values are recomputed by every implementation; randomized ones (HPKE, ECDSA)44// are verified/opened by every implementation. Test keys below are throwaway values created for the vectors only.45import { writeFileSync } from "node:fs";46import * as P from "../protocol/src/index.ts";4748const b = (n: number, seed: number) => Uint8Array.from({ length: n }, (_, i) => (i * 7 + seed) & 0xff);49const accountId = "11111111-1111-4111-8111-111111111111", deviceId = "22222222-2222-4222-8222-222222222222";50const vaultId = "33333333-3333-4333-8333-333333333333", recordId = "44444444-4444-4444-8444-444444444444";51const ark = b(32, 1), rk = b(32, 2), vk = b(32, 3);5253const account = await P.generateAccountKeys();54const devEnc = await P.generateKemKey(true), devSig = await P.generateSigKey(true);55const dev = { deviceId, encPub: P.b64u(devEnc.pub), sigPub: P.b64u(devSig.pub), createdAt: "2026-11-19T00:00:00.000Z" };56const keysetPt = P.utf8(JSON.stringify({ sig: P.b64u(await P.exportPrivateX963(account.sig.privateKey)), enc: P.b64u(await P.exportPrivateX963(account.enc.privateKey)) }));57const item = { type: "login", title: "Exemple — été", fields: { username: "alice", password: "not-a-real-password" }, urls: [{ url: "https://example.com", match: "domain" }] };58const ref = { vaultId, recordId, type: "item" as const, rev: 3 };59const grant = await P.grantVaultKey(account, accountId, vk, vaultId, 1, accountId, account.enc.pub, "owner");60const att = await P.sealChunk(b(32, 9), b(8, 10), "55555555-5555-4555-8555-555555555555", 0, 1, P.utf8("attachment body"));61const pairSecret = b(16, 11), pairingId = "66666666-6666-4666-8666-666666666666";62const relay = await P.sealRelay(account, "77777777-7777-4777-8777-777777777777", accountId, accountId, account.enc.pub, { hello: "relay" });6364const out = {65  spec: "SPV1", suite: 1, generatedBy: "typescript",66  ctx: [{ label: "record", fields: [vaultId, recordId, "item", "3", "1"], hex: P.hex(P.ctx("record", vaultId, recordId, "item", 3, 1)) },67        { label: "é", fields: ["", "ü"], hex: P.hex(P.ctx("é", "", "ü")) }],68  hkdf: { ikm: P.b64u(ark), salt: "", info: P.b64u(P.ctx("keyset-key", accountId)), out: P.b64u(await P.hkdf(ark, new Uint8Array(0), P.ctx("keyset-key", accountId))) },69  ids: { accountId, deviceId, vaultId, recordId },70  secrets: { ark: P.b64u(ark), rk: P.b64u(rk), vk: P.b64u(vk) },71  account: { sigPriv: P.b64u(await P.exportPrivateX963(account.sig.privateKey)), encPriv: P.b64u(await P.exportPrivateX963(account.enc.privateKey)), sigPub: P.b64u(account.sig.pub), encPub: P.b64u(account.enc.pub),72             fingerprint: await P.accountFingerprint(account.sig.pub, account.enc.pub) },73  keyset: await P.sealKeysetRaw(ark, accountId, keysetPt, b(12, 4)),74  device: { ...dev, encPriv: P.b64u(await P.exportPrivateX963(devEnc.privateKey)), sigPriv: P.b64u(await P.exportPrivateX963(devSig.privateKey)),75            cert: await P.signDeviceCert(account, accountId, dev), arkEnvelope: await P.wrapArkForDevice(ark, accountId, deviceId, devEnc.pub) },76  recovery: { text: await P.encodeRecoveryKey(rk), epoch: 1, authHash: await P.recoveryAuthHash(rk, accountId), envelope: await P.sealRecoveryEnvelope(rk, accountId, 1, ark, b(12, 5)) },77  record: { ref, kid: 1, plaintext: item, envelope: await P.sealRecord(vk, 1, ref, item, { salt: b(32, 6), nonce: b(12, 7) }) },78  grant,79  chunk: { key: P.b64u(b(32, 9)), prefix: P.b64u(b(8, 10)), id: "55555555-5555-4555-8555-555555555555", index: 0, total: 1, plaintext: P.b64u(P.utf8("attachment body")), sealed: P.b64u(att) },80  pairing: { pairingId, secret: P.b64u(pairSecret), tag: await P.pairingTag(pairSecret, pairingId, dev.encPub, dev.sigPub), sas: await P.pairingSas(pairingId, dev.encPub, dev.sigPub), code: P.encodePairingCode(pairingId, pairSecret) },81  relay: { shareId: "77777777-7777-4777-8777-777777777777", box: relay, plaintext: { hello: "relay" } },82  link: await (async () => { const s = b(32, 12), id = "88888888-8888-4888-8888-888888888888"; const k = await P.linkKeys(s, id); return { secret: P.b64u(s), shareId: id, authHash: k.authHash, box: await P.sealLink(s, id, { hello: "link" }, b(12, 13)), plaintext: { hello: "link" } }; })(),83  totp: [ // RFC 6238 appendix B84    { secret: P.b64u(P.utf8("12345678901234567890")), algorithm: "SHA-1", digits: 8, period: 30, atMs: 59000, code: "94287082" },85    { secret: P.b64u(P.utf8("12345678901234567890123456789012")), algorithm: "SHA-256", digits: 8, period: 30, atMs: 1111111109000, code: "68084774" },86    { secret: P.b64u(P.utf8("1234567890123456789012345678901234567890123456789012345678901234")), algorithm: "SHA-512", digits: 8, period: 30, atMs: 20000000000000, code: "47863826" },87  ],88};89writeFileSync(new URL("./spv1.json", import.meta.url), JSON.stringify(out, null, 1) + "\n");90console.log("spv1.json written");91
Files main
Menu

Theme