@seesign/kit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/qcs1.js ADDED
@@ -0,0 +1,220 @@
1
+ /**
2
+ * QCS-1: the SeeSign clear-signing sentence, version 1. Reference renderer.
3
+ *
4
+ * This is the TypeScript half of the standard written down in SPEC.md. The
5
+ * Solidity half (contracts/src/ClearSign.sol) must produce byte-identical
6
+ * output for the same inputs; the shared vectors in test-vectors/qcs1.json and
7
+ * a differential fuzz test hold both to that.
8
+ *
9
+ * Everything here is pure: no network, no clock, no randomness.
10
+ */
11
+ import { getAddress } from "viem";
12
+ // ---- constants (SPEC.md §3) --------------------------------------------------
13
+ export const VERSION_TAG = "SeeSign v1";
14
+ export const MAX_SENTENCE_BYTES = 512;
15
+ export const MAX_LABEL_BYTES = 32;
16
+ export const MAX_SYMBOL_BYTES = 11;
17
+ export const MAX_DECIMALS = 36;
18
+ export const NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
19
+ export const NATIVE_SYMBOL = "QOR";
20
+ export const NATIVE_DECIMALS = 18;
21
+ export const MAX_UINT64 = (1n << 64n) - 1n;
22
+ export const MAX_UINT256 = (1n << 256n) - 1n;
23
+ /** EVM chain id to the chain name QCS-1 prints, the same name QoreX puts in its prefix. */
24
+ export const CHAIN_NAMES = Object.freeze({ 9800: "qorechain-diana" });
25
+ /** The domain QoreX `signArbitrary` (QoreSign message-signing-v1) puts before the data. */
26
+ export const signingPrefix = (chain) => `qorechain-msg-v1|${chain}|`;
27
+ export const ACTIONS = ["TRANSFER", "ADD_PAYEE", "REMOVE_PAYEE", "CANCEL_ADD", "SET_LIMIT", "UPGRADE"];
28
+ // ---- errors (SPEC.md §6) -----------------------------------------------------
29
+ export const ERROR_CODES = [
30
+ "UnsupportedChain",
31
+ "UnknownAction",
32
+ "BadAddress",
33
+ "ZeroAddress",
34
+ "BadLabel",
35
+ "LabelTooLong",
36
+ "BadSymbol",
37
+ "BadDecimals",
38
+ "ValueOutOfRange",
39
+ "SentenceTooLong",
40
+ ];
41
+ /** A call QCS-1 cannot render. A wallet must refuse it: there is no fallback. */
42
+ export class Qcs1Error extends Error {
43
+ code;
44
+ constructor(code, detail) {
45
+ super(`${code}: ${detail}`);
46
+ this.name = "Qcs1Error";
47
+ this.code = code;
48
+ }
49
+ }
50
+ // ---- field rules (SPEC.md §4) --------------------------------------------------
51
+ const utf8 = new TextEncoder();
52
+ const byteLength = (s) => utf8.encode(s).length;
53
+ export function chainName(evmChainId) {
54
+ const name = CHAIN_NAMES[evmChainId];
55
+ if (!name)
56
+ throw new Qcs1Error("UnsupportedChain", `EVM chain id ${evmChainId} has no QCS-1 chain name`);
57
+ return name;
58
+ }
59
+ /**
60
+ * A 20-byte address as EIP-55 text. Accepts lower, upper or correctly
61
+ * checksummed mixed case; a mixed-case input with a wrong checksum is refused
62
+ * (it is most likely a typo).
63
+ */
64
+ export function canonicalAddress(input, what = "address") {
65
+ if (typeof input !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(input)) {
66
+ throw new Qcs1Error("BadAddress", `${what} is not a 0x-prefixed 20-byte hex address`);
67
+ }
68
+ const checksummed = getAddress(input.toLowerCase());
69
+ const body = input.slice(2);
70
+ if (/[a-f]/.test(body) && /[A-F]/.test(body) && checksummed !== input) {
71
+ throw new Qcs1Error("BadAddress", `${what} has an invalid EIP-55 checksum`);
72
+ }
73
+ return checksummed;
74
+ }
75
+ function nonZeroAddress(input, what) {
76
+ const a = canonicalAddress(input, what);
77
+ if (a === NATIVE_TOKEN)
78
+ throw new Qcs1Error("ZeroAddress", `${what} is the zero address`);
79
+ return a;
80
+ }
81
+ /** Labels: 1 to 32 bytes of [a-z0-9._-], starting with [a-z0-9], not starting with "0x". */
82
+ export function checkLabel(label) {
83
+ if (typeof label !== "string")
84
+ throw new Qcs1Error("BadLabel", "label is not a string");
85
+ const n = byteLength(label);
86
+ if (n === 0)
87
+ throw new Qcs1Error("BadLabel", "label is empty");
88
+ if (n > MAX_LABEL_BYTES)
89
+ throw new Qcs1Error("LabelTooLong", `label is ${n} bytes, the limit is ${MAX_LABEL_BYTES}`);
90
+ if (!/^[a-z0-9][a-z0-9._-]*$/.test(label)) {
91
+ throw new Qcs1Error("BadLabel", "label may only use a-z, 0-9, '.', '_' and '-', and must start with a letter or digit");
92
+ }
93
+ if (label.startsWith("0x"))
94
+ throw new Qcs1Error("BadLabel", "label may not start with 0x (it would read like an address)");
95
+ return label;
96
+ }
97
+ /** Token symbols: 1 to 11 bytes of [A-Za-z0-9]. */
98
+ export function checkSymbol(symbol) {
99
+ if (typeof symbol !== "string" || !/^[A-Za-z0-9]{1,11}$/.test(symbol)) {
100
+ throw new Qcs1Error("BadSymbol", "symbol must be 1 to 11 characters of A-Z, a-z, 0-9");
101
+ }
102
+ return symbol;
103
+ }
104
+ export function checkDecimals(decimals) {
105
+ if (!Number.isInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
106
+ throw new Qcs1Error("BadDecimals", `decimals must be an integer from 0 to ${MAX_DECIMALS}`);
107
+ }
108
+ return decimals;
109
+ }
110
+ function checkUint(value, max, what) {
111
+ if (typeof value !== "bigint" || value < 0n || value > max) {
112
+ throw new Qcs1Error("ValueOutOfRange", `${what} is outside 0 to ${max}`);
113
+ }
114
+ return value;
115
+ }
116
+ /**
117
+ * A token amount in base units as QCS-1 text (SPEC.md §4.4): integer part with
118
+ * "," every three digits, then "." and the fraction with trailing zeros removed
119
+ * but at least min(2, decimals) digits; no fraction when decimals is 0.
120
+ */
121
+ export function formatAmount(value, decimals) {
122
+ checkDecimals(decimals);
123
+ checkUint(value, MAX_UINT256, "amount");
124
+ let int = value.toString();
125
+ let frac = "";
126
+ if (decimals > 0) {
127
+ const digits = int.padStart(decimals + 1, "0");
128
+ int = digits.slice(0, digits.length - decimals);
129
+ frac = digits.slice(digits.length - decimals).replace(/0+$/, "").padEnd(Math.min(2, decimals), "0");
130
+ }
131
+ const grouped = int.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
132
+ return frac ? `${grouped}.${frac}` : grouped;
133
+ }
134
+ /** The token lines of a sentence, plus the symbol and decimals its amount uses. */
135
+ function tokenBlock(token) {
136
+ const address = canonicalAddress(token.address, "token");
137
+ if (address === NATIVE_TOKEN) {
138
+ return { lines: [`token ${NATIVE_SYMBOL} (native)`], symbol: NATIVE_SYMBOL, decimals: NATIVE_DECIMALS };
139
+ }
140
+ const decimals = checkDecimals(token.decimals);
141
+ const symbol = checkSymbol(token.symbol);
142
+ return { lines: ["token", address], symbol, decimals };
143
+ }
144
+ // ---- rendering (SPEC.md §5) ----------------------------------------------------
145
+ /**
146
+ * The QCS-1 sentence for an intent, as a string (printable ASCII and LF only).
147
+ * Throws Qcs1Error for anything it cannot render; never renders a fallback.
148
+ */
149
+ export function render(env, intent) {
150
+ const chain = chainName(env.evmChainId);
151
+ const wallet = nonZeroAddress(env.wallet, "wallet");
152
+ const lines = [`${VERSION_TAG} | ${chain}`, "wallet", wallet];
153
+ switch (intent.action) {
154
+ case "TRANSFER": {
155
+ const t = tokenBlock(intent.token);
156
+ const amount = formatAmount(intent.amount, t.decimals);
157
+ const label = checkLabel(intent.payee.label);
158
+ const payee = nonZeroAddress(intent.payee.address, "payee");
159
+ lines.push(`TRANSFER ${amount} ${t.symbol}`, ...t.lines, `to @${label}`, payee);
160
+ break;
161
+ }
162
+ case "ADD_PAYEE":
163
+ case "REMOVE_PAYEE":
164
+ case "CANCEL_ADD": {
165
+ const label = checkLabel(intent.payee.label);
166
+ const payee = nonZeroAddress(intent.payee.address, "payee");
167
+ lines.push(`${intent.action} @${label}`, payee);
168
+ break;
169
+ }
170
+ case "SET_LIMIT": {
171
+ const t = tokenBlock(intent.token);
172
+ const limit = formatAmount(intent.limit, t.decimals);
173
+ lines.push(`SET_LIMIT ${limit} ${t.symbol} per day`, ...t.lines);
174
+ break;
175
+ }
176
+ case "UPGRADE": {
177
+ const target = nonZeroAddress(intent.newWallet, "new wallet");
178
+ lines.push("UPGRADE move all funds to new wallet", target);
179
+ break;
180
+ }
181
+ default: {
182
+ const action = String(intent.action);
183
+ throw new Qcs1Error("UnknownAction", `"${action}" is not a QCS-1 action; unrenderable calls are refused`);
184
+ }
185
+ }
186
+ const nonce = checkUint(env.nonce, MAX_UINT64, "nonce");
187
+ const expiry = checkUint(env.expiry, MAX_UINT64, "expiry");
188
+ lines.push(`nonce ${nonce} | expires block ${expiry}`);
189
+ const sentence = lines.join("\n");
190
+ const n = byteLength(sentence);
191
+ if (n > MAX_SENTENCE_BYTES)
192
+ throw new Qcs1Error("SentenceTooLong", `sentence is ${n} bytes, the limit is ${MAX_SENTENCE_BYTES}`);
193
+ return sentence;
194
+ }
195
+ /** The sentence as bytes. */
196
+ export function renderBytes(env, intent) {
197
+ return utf8.encode(render(env, intent));
198
+ }
199
+ /** The exact bytes the ML-DSA-87 key signs: the QoreSign prefix, then the sentence. */
200
+ export function signedMessage(env, intent) {
201
+ return signingPrefix(chainName(env.evmChainId)) + render(env, intent);
202
+ }
203
+ // ---- wallet rules shared with the contract (SPEC.md §7) -------------------------
204
+ /** An intent is live while the current block is at or before its expiry block. */
205
+ export function isLive(expiry, currentBlock) {
206
+ checkUint(expiry, MAX_UINT64, "expiry");
207
+ checkUint(currentBlock, MAX_UINT64, "current block");
208
+ return currentBlock <= expiry;
209
+ }
210
+ /**
211
+ * Two different addresses whose first 4 and last 4 hex characters match,
212
+ * ignoring case. The same address twice is not a lookalike.
213
+ */
214
+ export function isLookalike(a, b) {
215
+ const x = canonicalAddress(a, "first address").slice(2).toLowerCase();
216
+ const y = canonicalAddress(b, "second address").slice(2).toLowerCase();
217
+ if (x === y)
218
+ return false;
219
+ return x.slice(0, 4) === y.slice(0, 4) && x.slice(-4) === y.slice(-4);
220
+ }
@@ -0,0 +1,68 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import { type Envelope, type Intent } from "./qcs1.ts";
3
+ export interface QorexKey {
4
+ bech32Address: string;
5
+ algo?: string;
6
+ name?: string;
7
+ }
8
+ export interface QorexArbitrarySignature {
9
+ signatureType: string;
10
+ classical?: {
11
+ keyType: string;
12
+ publicKey: string;
13
+ signature: string;
14
+ };
15
+ pq?: {
16
+ algorithmId: number;
17
+ signature: string;
18
+ };
19
+ pub_key?: {
20
+ type: string;
21
+ value: string;
22
+ };
23
+ signature?: string;
24
+ }
25
+ /** The subset of `window.qorex.native` used here. */
26
+ export interface QorexNative {
27
+ capabilities?: readonly string[] | (() => Promise<readonly string[]>);
28
+ enable(chainId: string): Promise<unknown>;
29
+ getKey(chainId: string): Promise<QorexKey>;
30
+ signArbitrary?(chainId: string, signer: string, data: string | Uint8Array): Promise<QorexArbitrarySignature>;
31
+ }
32
+ export type QorexErrorCode = "QOREX_NOT_FOUND" | "SIGN_ARBITRARY_UNAVAILABLE" | "WRONG_NETWORK" | "WRONG_ACCOUNT" | "REJECTED" | "BAD_SIGNATURE";
33
+ export declare class QorexError extends Error {
34
+ readonly code: QorexErrorCode;
35
+ constructor(code: QorexErrorCode, message: string);
36
+ }
37
+ export declare const CLI_HINT = "sign from a terminal with the SeeSign CLI instead: pnpm seesign sign \"<sentence>\" in the SeeSign Kit repository (testnet keys only, never a real recovery phrase)";
38
+ /** The QoreX native provider on this page, if there is one. */
39
+ export declare function findQorex(): QorexNative | undefined;
40
+ /** Whether this QoreX build can sign messages with ML-DSA-87. */
41
+ export declare function qorexCanSign(provider: QorexNative): Promise<boolean>;
42
+ export interface QorexSigned {
43
+ sentence: string;
44
+ /** The ML-DSA-87 signature (4,627 bytes) the wallet contract verifies. */
45
+ signature: Hex;
46
+ signer: {
47
+ qor: string;
48
+ evm: Address;
49
+ };
50
+ /** Everything QoreX returned, including the ADR-36 classical half. */
51
+ raw: QorexArbitrarySignature;
52
+ }
53
+ /**
54
+ * Asks QoreX to sign a QCS-1 sentence. Pass a sentence you already checked (for
55
+ * example `prepare(...).sentence`), or an envelope and intent to render here.
56
+ * With `expectedSigner` (the wallet's owner, 0x… or qor1…), refuses to sign with
57
+ * any other account.
58
+ */
59
+ export declare function signWithQoreX(input: {
60
+ sentence: string;
61
+ } | {
62
+ env: Envelope;
63
+ intent: Intent;
64
+ }, opts?: {
65
+ provider?: QorexNative;
66
+ expectedSigner?: string;
67
+ chainId?: string;
68
+ }): Promise<QorexSigned>;
package/dist/qorex.js ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Signing a QCS-1 sentence with QoreX (`window.qorex.native.signArbitrary`).
3
+ *
4
+ * QoreX signs "qorechain-msg-v1|<chain>|" + data with the account's ML-DSA-87 key
5
+ * (QoreSign message-signing-v1) and shows the user the whole text first. The
6
+ * ML-DSA-87 part (`pq.signature`, 4,627 bytes) is what the wallet contract checks.
7
+ *
8
+ * The published @qorechain/qorex-types 0.1.0 types `signArbitrary` as
9
+ * `Promise<never>` ("refused in current builds"), which is out of date (QoreX
10
+ * extension 0.4.5 signs), so this module defines its own minimal types.
11
+ * It never asks for, and never handles, a recovery phrase or a key.
12
+ */
13
+ import { base64 } from "@scure/base";
14
+ import { bytesToHex } from "viem";
15
+ import { qorToEvm, sameAccount } from "./address.js";
16
+ import { render } from "./qcs1.js";
17
+ export class QorexError extends Error {
18
+ code;
19
+ constructor(code, message) {
20
+ super(message);
21
+ this.code = code;
22
+ this.name = "QorexError";
23
+ }
24
+ }
25
+ export const CLI_HINT = 'sign from a terminal with the SeeSign CLI instead: pnpm seesign sign "<sentence>" in the SeeSign Kit repository (testnet keys only, never a real recovery phrase)';
26
+ /** The QoreX native provider on this page, if there is one. */
27
+ export function findQorex() {
28
+ return globalThis.qorex?.native;
29
+ }
30
+ /** Whether this QoreX build can sign messages with ML-DSA-87. */
31
+ export async function qorexCanSign(provider) {
32
+ const caps = typeof provider.capabilities === "function" ? await provider.capabilities() : provider.capabilities;
33
+ // QoreX app 1.2.0 has the method but declares no capabilities; fall back to the method itself.
34
+ if (Array.isArray(caps))
35
+ return caps.includes("signArbitrary");
36
+ return typeof provider.signArbitrary === "function";
37
+ }
38
+ /**
39
+ * Asks QoreX to sign a QCS-1 sentence. Pass a sentence you already checked (for
40
+ * example `prepare(...).sentence`), or an envelope and intent to render here.
41
+ * With `expectedSigner` (the wallet's owner, 0x… or qor1…), refuses to sign with
42
+ * any other account.
43
+ */
44
+ export async function signWithQoreX(input, opts = {}) {
45
+ const chainId = opts.chainId ?? "qorechain-diana";
46
+ const provider = opts.provider ?? findQorex();
47
+ if (!provider) {
48
+ throw new QorexError("QOREX_NOT_FOUND", `QoreX was not found on this page. Install it or enable it for this site, or ${CLI_HINT}.`);
49
+ }
50
+ if (!(await qorexCanSign(provider)) || typeof provider.signArbitrary !== "function") {
51
+ throw new QorexError("SIGN_ARBITRARY_UNAVAILABLE", `This QoreX cannot sign SeeSign sentences (signArbitrary is not available). Update QoreX (extension 0.4.0 or later, app 1.2.1 or later), or ${CLI_HINT}.`);
52
+ }
53
+ const sentence = "sentence" in input ? input.sentence : render(input.env, input.intent);
54
+ let key;
55
+ try {
56
+ await provider.enable(chainId);
57
+ key = await provider.getKey(chainId);
58
+ }
59
+ catch (err) {
60
+ throw new QorexError("WRONG_NETWORK", `QoreX did not open ${chainId}: switch QoreX to Testnet and try again (${errorText(err)}).`);
61
+ }
62
+ if (opts.expectedSigner && !sameAccount(key.bech32Address, opts.expectedSigner)) {
63
+ throw new QorexError("WRONG_ACCOUNT", `QoreX has ${key.bech32Address} selected, but this wallet belongs to ${opts.expectedSigner}. Select that account in QoreX.`);
64
+ }
65
+ let raw;
66
+ try {
67
+ raw = await provider.signArbitrary(chainId, key.bech32Address, sentence);
68
+ }
69
+ catch (err) {
70
+ throw new QorexError("REJECTED", `QoreX did not sign: ${errorText(err)}`);
71
+ }
72
+ const pq = raw?.pq;
73
+ let sig;
74
+ try {
75
+ sig = pq?.signature ? base64.decode(pq.signature) : undefined;
76
+ }
77
+ catch {
78
+ sig = undefined;
79
+ }
80
+ if (raw?.signatureType !== "ml-dsa-87-hybrid" || pq?.algorithmId !== 1 || sig?.length !== 4627) {
81
+ throw new QorexError("BAD_SIGNATURE", "QoreX returned a signature that is not a 4,627-byte ML-DSA-87 signature.");
82
+ }
83
+ return { sentence, signature: bytesToHex(sig), signer: { qor: key.bech32Address, evm: qorToEvm(key.bech32Address) }, raw };
84
+ }
85
+ function errorText(err) {
86
+ return err instanceof Error ? err.message : String(err);
87
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The shape of test-vectors/qcs1.json, and the decoder from a vector's flat
3
+ * input to an (envelope, intent) pair.
4
+ *
5
+ * Inputs are flat and every key is present in every vector (unused ones hold
6
+ * neutral values), with keys in alphabetical order, so the Solidity
7
+ * conformance test can read them with plain JSON paths.
8
+ */
9
+ import type { Envelope, Intent } from "./qcs1.ts";
10
+ export interface VectorInput {
11
+ /** One of the QCS-1 actions, or anything else to test refusal. */
12
+ action: string;
13
+ /** Base units: the TRANSFER amount, or the SET_LIMIT daily limit. Decimal string. */
14
+ amount: string;
15
+ evmChainId: number;
16
+ /** Expiry block, decimal string. */
17
+ expiry: string;
18
+ /** UPGRADE target. */
19
+ newWallet: string;
20
+ /** Wallet nonce, decimal string. */
21
+ nonce: string;
22
+ payeeAddress: string;
23
+ payeeLabel: string;
24
+ /** 0x0 for native QOR. */
25
+ tokenAddress: string;
26
+ tokenDecimals: number;
27
+ tokenSymbol: string;
28
+ wallet: string;
29
+ }
30
+ export type VectorExpect = {
31
+ ok: true;
32
+ sentence: string;
33
+ sentenceHex: string;
34
+ bytes: number;
35
+ signedHex: string;
36
+ live?: boolean;
37
+ } | {
38
+ ok: false;
39
+ error: string;
40
+ };
41
+ export interface Vector {
42
+ id: string;
43
+ description: string;
44
+ /** "ts" and/or "sol": TS-only vectors test string inputs a typed Solidity call cannot carry. */
45
+ appliesTo: Array<"ts" | "sol">;
46
+ input: VectorInput;
47
+ /** Present when the vector also tests the expiry rule. */
48
+ context?: {
49
+ currentBlock: string;
50
+ };
51
+ expect: VectorExpect;
52
+ }
53
+ export interface LookalikeVector {
54
+ id: string;
55
+ description: string;
56
+ a: string;
57
+ b: string;
58
+ lookalike: boolean;
59
+ }
60
+ export interface VectorFile {
61
+ name: string;
62
+ spec: string;
63
+ specVersion: string;
64
+ generatedBy: string;
65
+ chain: {
66
+ name: string;
67
+ evmChainId: number;
68
+ };
69
+ prefix: string;
70
+ vectors: Vector[];
71
+ lookalike: LookalikeVector[];
72
+ }
73
+ export declare function decodeVectorInput(v: VectorInput): {
74
+ env: Envelope;
75
+ intent: Intent;
76
+ };
@@ -0,0 +1,19 @@
1
+ export function decodeVectorInput(v) {
2
+ const env = { evmChainId: v.evmChainId, wallet: v.wallet, nonce: BigInt(v.nonce), expiry: BigInt(v.expiry) };
3
+ const token = { address: v.tokenAddress, symbol: v.tokenSymbol, decimals: v.tokenDecimals };
4
+ const payee = { address: v.payeeAddress, label: v.payeeLabel };
5
+ switch (v.action) {
6
+ case "TRANSFER":
7
+ return { env, intent: { action: "TRANSFER", token, payee, amount: BigInt(v.amount) } };
8
+ case "ADD_PAYEE":
9
+ case "REMOVE_PAYEE":
10
+ case "CANCEL_ADD":
11
+ return { env, intent: { action: v.action, payee } };
12
+ case "SET_LIMIT":
13
+ return { env, intent: { action: "SET_LIMIT", token, limit: BigInt(v.amount) } };
14
+ case "UPGRADE":
15
+ return { env, intent: { action: "UPGRADE", newWallet: v.newWallet } };
16
+ default:
17
+ return { env, intent: { action: v.action } };
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ import { type Hex } from "viem";
2
+ export declare const ML_DSA_87_PUBLIC_KEY_BYTES = 2592;
3
+ export declare const ML_DSA_87_SIGNATURE_BYTES = 4627;
4
+ /** Plain ML-DSA-87 verification over `message` (empty context), as pqcVerify does it. */
5
+ export declare function verifyMlDsa87(publicKey: Uint8Array | Hex, message: Uint8Array, signature: Uint8Array | Hex): boolean;
6
+ /** Verifies a signature over "qorechain-msg-v1|<chain>|" + sentence, as the wallet does. */
7
+ export declare function verifySentence(publicKey: Uint8Array | Hex, sentence: string | Uint8Array, signature: Uint8Array | Hex, chain?: string): boolean;
package/dist/verify.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Local ML-DSA-87 (FIPS 204) verification, for a relayer's pre-check or a CLI.
3
+ * The chain's pqcVerify precompile is what counts; this gives the same answer
4
+ * off chain.
5
+ */
6
+ import { ml_dsa87 } from "@noble/post-quantum/ml-dsa.js";
7
+ import { hexToBytes } from "viem";
8
+ import { messageForSentence } from "./message.js";
9
+ export const ML_DSA_87_PUBLIC_KEY_BYTES = 2592;
10
+ export const ML_DSA_87_SIGNATURE_BYTES = 4627;
11
+ const bytes = (x) => (typeof x === "string" ? hexToBytes(x) : x);
12
+ /** Plain ML-DSA-87 verification over `message` (empty context), as pqcVerify does it. */
13
+ export function verifyMlDsa87(publicKey, message, signature) {
14
+ const pk = bytes(publicKey);
15
+ const sig = bytes(signature);
16
+ if (pk.length !== ML_DSA_87_PUBLIC_KEY_BYTES || sig.length !== ML_DSA_87_SIGNATURE_BYTES)
17
+ return false;
18
+ try {
19
+ return ml_dsa87.verify(sig, message, pk);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /** Verifies a signature over "qorechain-msg-v1|<chain>|" + sentence, as the wallet does. */
26
+ export function verifySentence(publicKey, sentence, signature, chain = "qorechain-diana") {
27
+ return verifyMlDsa87(publicKey, messageForSentence(sentence, chain), signature);
28
+ }
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@seesign/kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "SeeSign Kit: QCS-1 clear signing for QoreChain. Render the sentence a SeeSign wallet checks, sign it with ML-DSA-87 in QoreX, and build the wallet calls (qorechain-diana testnet).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "keywords": [
8
+ "qorechain",
9
+ "post-quantum",
10
+ "ml-dsa",
11
+ "ml-dsa-87",
12
+ "fips-204",
13
+ "clear-signing",
14
+ "wallet",
15
+ "qorex"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Sayangenri/seesign-kit.git",
20
+ "directory": "sdk"
21
+ },
22
+ "homepage": "https://github.com/Sayangenri/seesign-kit/tree/main/sdk#readme",
23
+ "bugs": "https://github.com/Sayangenri/seesign-kit/issues",
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=20"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./vectors": {
34
+ "types": "./dist/vectors.d.ts",
35
+ "default": "./dist/vectors.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@noble/post-quantum": "^0.7.1",
48
+ "@scure/base": "^2.4.0",
49
+ "viem": "^2.58.8"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^26.6.11",
53
+ "tsx": "^4.23.15",
54
+ "typescript": "^7.0.2",
55
+ "vitest": "^5.1.2"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc -p tsconfig.build.json",
59
+ "test": "vitest run",
60
+ "vectors": "tsx scripts/gen-vectors.ts",
61
+ "typecheck": "tsc --noEmit",
62
+ "abi": "tsx scripts/gen-abi.ts",
63
+ "smoke": "tsx scripts/smoke.ts"
64
+ },
65
+ "main": "./dist/index.js",
66
+ "types": "./dist/index.d.ts"
6
67
  }