@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/LICENSE +21 -0
- package/README.md +76 -2
- package/dist/abi.d.ts +1370 -0
- package/dist/abi.js +1787 -0
- package/dist/address.d.ts +5 -0
- package/dist/address.js +23 -0
- package/dist/calls.d.ts +33 -0
- package/dist/calls.js +73 -0
- package/dist/chain.d.ts +100 -0
- package/dist/chain.js +130 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/message.d.ts +14 -0
- package/dist/message.js +21 -0
- package/dist/network.d.ts +52 -0
- package/dist/network.js +43 -0
- package/dist/qcs1.d.ts +97 -0
- package/dist/qcs1.js +220 -0
- package/dist/qorex.d.ts +68 -0
- package/dist/qorex.js +87 -0
- package/dist/vectors.d.ts +76 -0
- package/dist/vectors.js +19 -0
- package/dist/verify.d.ts +7 -0
- package/dist/verify.js +28 -0
- package/package.json +64 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
export declare function qorToEvm(qor: string): Address;
|
|
3
|
+
export declare function evmToQor(evm: string): string;
|
|
4
|
+
/** The same account, whichever encoding each side uses. */
|
|
5
|
+
export declare function sameAccount(a: string, b: string): boolean;
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QoreChain accounts have two encodings of the same 20 bytes: 0x… (EVM) and
|
|
3
|
+
* qor1… (bech32). These convert between them. Browser-safe (no Buffer).
|
|
4
|
+
*/
|
|
5
|
+
import { bech32 } from "@scure/base";
|
|
6
|
+
import { bytesToHex, getAddress, hexToBytes } from "viem";
|
|
7
|
+
export function qorToEvm(qor) {
|
|
8
|
+
const { prefix, words } = bech32.decode(qor);
|
|
9
|
+
if (prefix !== "qor")
|
|
10
|
+
throw new Error(`not a qor1 address: ${qor}`);
|
|
11
|
+
const bytes = bech32.fromWords(words);
|
|
12
|
+
if (bytes.length !== 20)
|
|
13
|
+
throw new Error(`not a 20-byte account: ${qor}`);
|
|
14
|
+
return getAddress(bytesToHex(Uint8Array.from(bytes)));
|
|
15
|
+
}
|
|
16
|
+
export function evmToQor(evm) {
|
|
17
|
+
return bech32.encode("qor", bech32.toWords(hexToBytes(getAddress(evm))));
|
|
18
|
+
}
|
|
19
|
+
/** The same account, whichever encoding each side uses. */
|
|
20
|
+
export function sameAccount(a, b) {
|
|
21
|
+
const evm = (x) => (x.startsWith("qor1") ? qorToEvm(x) : getAddress(x));
|
|
22
|
+
return evm(a) === evm(b);
|
|
23
|
+
}
|
package/dist/calls.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calldata for every SeeSign wallet and factory function.
|
|
3
|
+
*
|
|
4
|
+
* Signed actions can be sent to the wallet directly or wrapped in
|
|
5
|
+
* `encodeRelay` and sent to the factory, the single relay entry point. Classical
|
|
6
|
+
* (safety) calls must be sent by the owner's own EVM address.
|
|
7
|
+
*/
|
|
8
|
+
import { type Address, type Hex } from "viem";
|
|
9
|
+
import type { Intent } from "./qcs1.ts";
|
|
10
|
+
/** The wallet's signed entry point for an intent, with its nonce, expiry and ML-DSA-87 signature. */
|
|
11
|
+
export declare function encodeSignedCall(intent: Intent, nonce: bigint, expiry: bigint, signature: Hex): Hex;
|
|
12
|
+
/** Wraps a wallet call for the factory's relay entry point. */
|
|
13
|
+
export declare const encodeRelay: (wallet: string, data: Hex) => Hex;
|
|
14
|
+
/** Creates a wallet for `owner` (anyone may send it; the owner needs a proven ML-DSA-87 key). */
|
|
15
|
+
export declare const encodeCreateWallet: (owner: string) => Hex;
|
|
16
|
+
/** Ends a payee's timelock once it has passed (anyone may send it, directly or relayed). */
|
|
17
|
+
export declare const encodeFinalizeAdd: (payee: string) => Hex;
|
|
18
|
+
export declare const encodeRemovePayee: (payee: string) => Hex;
|
|
19
|
+
export declare const encodeCancelAdd: (payee: string) => Hex;
|
|
20
|
+
/** Lowers a limit (raising needs the signed SET_LIMIT). */
|
|
21
|
+
export declare const encodeSetLimitClassical: (token: string, newLimit: bigint) => Hex;
|
|
22
|
+
export declare const encodePause: () => Hex;
|
|
23
|
+
export declare const encodeUnpause: () => Hex;
|
|
24
|
+
/** The wallet view that returns the contract's own sentence for each action. */
|
|
25
|
+
export declare const PREVIEW_FUNCTION: {
|
|
26
|
+
readonly TRANSFER: "previewTransfer";
|
|
27
|
+
readonly ADD_PAYEE: "previewAddPayee";
|
|
28
|
+
readonly REMOVE_PAYEE: "previewRemovePayee";
|
|
29
|
+
readonly CANCEL_ADD: "previewCancelAdd";
|
|
30
|
+
readonly SET_LIMIT: "previewSetLimit";
|
|
31
|
+
readonly UPGRADE: "previewUpgrade";
|
|
32
|
+
};
|
|
33
|
+
export type { Address };
|
package/dist/calls.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calldata for every SeeSign wallet and factory function.
|
|
3
|
+
*
|
|
4
|
+
* Signed actions can be sent to the wallet directly or wrapped in
|
|
5
|
+
* `encodeRelay` and sent to the factory, the single relay entry point. Classical
|
|
6
|
+
* (safety) calls must be sent by the owner's own EVM address.
|
|
7
|
+
*/
|
|
8
|
+
import { encodeFunctionData, getAddress } from "viem";
|
|
9
|
+
import { seeSignFactoryAbi, seeSignWalletAbi } from "./abi.js";
|
|
10
|
+
const a = (x) => getAddress(x);
|
|
11
|
+
/** The wallet's signed entry point for an intent, with its nonce, expiry and ML-DSA-87 signature. */
|
|
12
|
+
export function encodeSignedCall(intent, nonce, expiry, signature) {
|
|
13
|
+
switch (intent.action) {
|
|
14
|
+
case "TRANSFER":
|
|
15
|
+
return encodeFunctionData({
|
|
16
|
+
abi: seeSignWalletAbi,
|
|
17
|
+
functionName: "transfer",
|
|
18
|
+
args: [a(intent.token.address), a(intent.payee.address), intent.amount, nonce, expiry, signature],
|
|
19
|
+
});
|
|
20
|
+
case "ADD_PAYEE":
|
|
21
|
+
return encodeFunctionData({
|
|
22
|
+
abi: seeSignWalletAbi,
|
|
23
|
+
functionName: "addPayee",
|
|
24
|
+
args: [a(intent.payee.address), intent.payee.label, nonce, expiry, signature],
|
|
25
|
+
});
|
|
26
|
+
case "REMOVE_PAYEE":
|
|
27
|
+
return encodeFunctionData({
|
|
28
|
+
abi: seeSignWalletAbi,
|
|
29
|
+
functionName: "removePayeeSigned",
|
|
30
|
+
args: [a(intent.payee.address), nonce, expiry, signature],
|
|
31
|
+
});
|
|
32
|
+
case "CANCEL_ADD":
|
|
33
|
+
return encodeFunctionData({
|
|
34
|
+
abi: seeSignWalletAbi,
|
|
35
|
+
functionName: "cancelAddSigned",
|
|
36
|
+
args: [a(intent.payee.address), nonce, expiry, signature],
|
|
37
|
+
});
|
|
38
|
+
case "SET_LIMIT":
|
|
39
|
+
return encodeFunctionData({
|
|
40
|
+
abi: seeSignWalletAbi,
|
|
41
|
+
functionName: "setLimit",
|
|
42
|
+
args: [a(intent.token.address), intent.limit, nonce, expiry, signature],
|
|
43
|
+
});
|
|
44
|
+
case "UPGRADE":
|
|
45
|
+
return encodeFunctionData({
|
|
46
|
+
abi: seeSignWalletAbi,
|
|
47
|
+
functionName: "upgrade",
|
|
48
|
+
args: [a(intent.newWallet), nonce, expiry, signature],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Wraps a wallet call for the factory's relay entry point. */
|
|
53
|
+
export const encodeRelay = (wallet, data) => encodeFunctionData({ abi: seeSignFactoryAbi, functionName: "relay", args: [a(wallet), data] });
|
|
54
|
+
/** Creates a wallet for `owner` (anyone may send it; the owner needs a proven ML-DSA-87 key). */
|
|
55
|
+
export const encodeCreateWallet = (owner) => encodeFunctionData({ abi: seeSignFactoryAbi, functionName: "createWallet", args: [a(owner)] });
|
|
56
|
+
/** Ends a payee's timelock once it has passed (anyone may send it, directly or relayed). */
|
|
57
|
+
export const encodeFinalizeAdd = (payee) => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "finalizeAdd", args: [a(payee)] });
|
|
58
|
+
// ---- classical safety calls: sent by the owner's EVM address, never move funds ----
|
|
59
|
+
export const encodeRemovePayee = (payee) => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "removePayee", args: [a(payee)] });
|
|
60
|
+
export const encodeCancelAdd = (payee) => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "cancelAdd", args: [a(payee)] });
|
|
61
|
+
/** Lowers a limit (raising needs the signed SET_LIMIT). */
|
|
62
|
+
export const encodeSetLimitClassical = (token, newLimit) => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "setLimitClassical", args: [a(token), newLimit] });
|
|
63
|
+
export const encodePause = () => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "pause" });
|
|
64
|
+
export const encodeUnpause = () => encodeFunctionData({ abi: seeSignWalletAbi, functionName: "unpause" });
|
|
65
|
+
/** The wallet view that returns the contract's own sentence for each action. */
|
|
66
|
+
export const PREVIEW_FUNCTION = {
|
|
67
|
+
TRANSFER: "previewTransfer",
|
|
68
|
+
ADD_PAYEE: "previewAddPayee",
|
|
69
|
+
REMOVE_PAYEE: "previewRemovePayee",
|
|
70
|
+
CANCEL_ADD: "previewCancelAdd",
|
|
71
|
+
SET_LIMIT: "previewSetLimit",
|
|
72
|
+
UPGRADE: "previewUpgrade",
|
|
73
|
+
};
|
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading what a signed action needs from the chain, and `prepare`: build the
|
|
3
|
+
* intent from on-chain state, render it with the TypeScript renderer, read the
|
|
4
|
+
* contract's own sentence, and refuse to go on unless the two are identical.
|
|
5
|
+
*/
|
|
6
|
+
import { type Address, type Hex, type PublicClient } from "viem";
|
|
7
|
+
import { type Envelope, type Intent, type Token } from "./qcs1.ts";
|
|
8
|
+
/** The parts of a viem PublicClient the readers use (easy to fake in tests). */
|
|
9
|
+
export type ChainReader = Pick<PublicClient, "readContract" | "getBlockNumber">;
|
|
10
|
+
/** pqcKeyStatus with the live four-output shape (the published @qorechain/evm ABI lists three). */
|
|
11
|
+
export declare const pqcKeyStatusAbi: readonly [{
|
|
12
|
+
readonly type: "function";
|
|
13
|
+
readonly name: "pqcKeyStatus";
|
|
14
|
+
readonly stateMutability: "view";
|
|
15
|
+
readonly inputs: readonly [{
|
|
16
|
+
readonly name: "account";
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}];
|
|
19
|
+
readonly outputs: readonly [{
|
|
20
|
+
readonly name: "registered";
|
|
21
|
+
readonly type: "bool";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "algorithmId";
|
|
24
|
+
readonly type: "uint8";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "pubkey";
|
|
27
|
+
readonly type: "bytes";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "possessionProven";
|
|
30
|
+
readonly type: "bool";
|
|
31
|
+
}];
|
|
32
|
+
}];
|
|
33
|
+
export interface KeyStatus {
|
|
34
|
+
registered: boolean;
|
|
35
|
+
algorithmId: number;
|
|
36
|
+
pubkey: Hex;
|
|
37
|
+
possessionProven: boolean;
|
|
38
|
+
/** Registered, ML-DSA-87 (algorithm 1) and possession-proven: usable by SeeSign. */
|
|
39
|
+
ready: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** The owner's key as the wallet will see it (the background key check). */
|
|
42
|
+
export declare function readKeyStatus(client: Pick<PublicClient, "readContract">, account: Address): Promise<KeyStatus>;
|
|
43
|
+
/** Symbol and decimals as ClearSign.tokenInfo reads them; native QOR for 0x0. */
|
|
44
|
+
export declare function readToken(client: Pick<PublicClient, "readContract">, token: Address): Promise<Token>;
|
|
45
|
+
/** What the user asks for; `prepare` fills in labels, token metadata, nonce and expiry. */
|
|
46
|
+
export type Draft = {
|
|
47
|
+
action: "TRANSFER";
|
|
48
|
+
token: Address;
|
|
49
|
+
payee: Address;
|
|
50
|
+
amount: bigint;
|
|
51
|
+
} | {
|
|
52
|
+
action: "ADD_PAYEE";
|
|
53
|
+
payee: Address;
|
|
54
|
+
label: string;
|
|
55
|
+
} | {
|
|
56
|
+
action: "REMOVE_PAYEE";
|
|
57
|
+
payee: Address;
|
|
58
|
+
} | {
|
|
59
|
+
action: "CANCEL_ADD";
|
|
60
|
+
payee: Address;
|
|
61
|
+
} | {
|
|
62
|
+
action: "SET_LIMIT";
|
|
63
|
+
token: Address;
|
|
64
|
+
limit: bigint;
|
|
65
|
+
} | {
|
|
66
|
+
action: "UPGRADE";
|
|
67
|
+
newWallet: Address;
|
|
68
|
+
};
|
|
69
|
+
export interface Prepared {
|
|
70
|
+
wallet: Address;
|
|
71
|
+
env: Envelope;
|
|
72
|
+
intent: Intent;
|
|
73
|
+
/** The QCS-1 sentence, identical from the TypeScript renderer and the contract. */
|
|
74
|
+
sentence: string;
|
|
75
|
+
/** What the ML-DSA-87 key signs: prefix + sentence. */
|
|
76
|
+
message: Uint8Array;
|
|
77
|
+
/** Calldata for the wallet, once signed. */
|
|
78
|
+
signedCall(signature: Hex): Hex;
|
|
79
|
+
/** The same call wrapped for the factory's relay entry point. */
|
|
80
|
+
relayCall(signature: Hex): Hex;
|
|
81
|
+
}
|
|
82
|
+
export declare class SentenceMismatchError extends Error {
|
|
83
|
+
readonly local: string;
|
|
84
|
+
readonly contract: string;
|
|
85
|
+
constructor(local: string, contract: string);
|
|
86
|
+
}
|
|
87
|
+
export declare class NotInBookError extends Error {
|
|
88
|
+
readonly payee: Address;
|
|
89
|
+
constructor(payee: Address, which: "payee" | "pending payee");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Builds the intent from on-chain state, renders it locally, reads the wallet's own
|
|
93
|
+
* sentence (`preview*`) and throws SentenceMismatchError unless they are byte-identical.
|
|
94
|
+
* `expiryBlocks` defaults to 300 (about 6 to 7 minutes on diana).
|
|
95
|
+
*/
|
|
96
|
+
export declare function prepare(client: ChainReader, wallet: Address, draft: Draft, opts?: {
|
|
97
|
+
expiryBlocks?: bigint;
|
|
98
|
+
nonce?: bigint;
|
|
99
|
+
evmChainId?: number;
|
|
100
|
+
}): Promise<Prepared>;
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading what a signed action needs from the chain, and `prepare`: build the
|
|
3
|
+
* intent from on-chain state, render it with the TypeScript renderer, read the
|
|
4
|
+
* contract's own sentence, and refuse to go on unless the two are identical.
|
|
5
|
+
*/
|
|
6
|
+
import { bytesToHex, erc20Abi, getAddress, hexToString, stringToBytes } from "viem";
|
|
7
|
+
import { seeSignWalletAbi } from "./abi.js";
|
|
8
|
+
import { encodeRelay, encodeSignedCall } from "./calls.js";
|
|
9
|
+
import { messageForSentence } from "./message.js";
|
|
10
|
+
import { NATIVE_DECIMALS, NATIVE_SYMBOL, NATIVE_TOKEN, render } from "./qcs1.js";
|
|
11
|
+
/** pqcKeyStatus with the live four-output shape (the published @qorechain/evm ABI lists three). */
|
|
12
|
+
export const pqcKeyStatusAbi = [
|
|
13
|
+
{
|
|
14
|
+
type: "function",
|
|
15
|
+
name: "pqcKeyStatus",
|
|
16
|
+
stateMutability: "view",
|
|
17
|
+
inputs: [{ name: "account", type: "address" }],
|
|
18
|
+
outputs: [
|
|
19
|
+
{ name: "registered", type: "bool" },
|
|
20
|
+
{ name: "algorithmId", type: "uint8" },
|
|
21
|
+
{ name: "pubkey", type: "bytes" },
|
|
22
|
+
{ name: "possessionProven", type: "bool" },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
/** The owner's key as the wallet will see it (the background key check). */
|
|
27
|
+
export async function readKeyStatus(client, account) {
|
|
28
|
+
const [registered, algorithmId, pubkey, possessionProven] = await client.readContract({
|
|
29
|
+
address: "0x0000000000000000000000000000000000000a02",
|
|
30
|
+
abi: pqcKeyStatusAbi,
|
|
31
|
+
functionName: "pqcKeyStatus",
|
|
32
|
+
args: [account],
|
|
33
|
+
});
|
|
34
|
+
return { registered, algorithmId, pubkey, possessionProven, ready: registered && algorithmId === 1 && possessionProven };
|
|
35
|
+
}
|
|
36
|
+
/** Symbol and decimals as ClearSign.tokenInfo reads them; native QOR for 0x0. */
|
|
37
|
+
export async function readToken(client, token) {
|
|
38
|
+
if (getAddress(token) === NATIVE_TOKEN)
|
|
39
|
+
return { address: NATIVE_TOKEN, symbol: NATIVE_SYMBOL, decimals: NATIVE_DECIMALS };
|
|
40
|
+
const [symbol, decimals] = await Promise.all([
|
|
41
|
+
client.readContract({ address: token, abi: erc20Abi, functionName: "symbol" }),
|
|
42
|
+
client.readContract({ address: token, abi: erc20Abi, functionName: "decimals" }),
|
|
43
|
+
]);
|
|
44
|
+
return { address: getAddress(token), symbol, decimals };
|
|
45
|
+
}
|
|
46
|
+
export class SentenceMismatchError extends Error {
|
|
47
|
+
local;
|
|
48
|
+
contract;
|
|
49
|
+
constructor(local, contract) {
|
|
50
|
+
super("The sentence from the TypeScript renderer differs from the wallet contract's own sentence. Do not sign.");
|
|
51
|
+
this.local = local;
|
|
52
|
+
this.contract = contract;
|
|
53
|
+
this.name = "SentenceMismatchError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class NotInBookError extends Error {
|
|
57
|
+
payee;
|
|
58
|
+
constructor(payee, which) {
|
|
59
|
+
super(`${payee} is not a ${which} of this wallet`);
|
|
60
|
+
this.payee = payee;
|
|
61
|
+
this.name = "NotInBookError";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds the intent from on-chain state, renders it locally, reads the wallet's own
|
|
66
|
+
* sentence (`preview*`) and throws SentenceMismatchError unless they are byte-identical.
|
|
67
|
+
* `expiryBlocks` defaults to 300 (about 6 to 7 minutes on diana).
|
|
68
|
+
*/
|
|
69
|
+
export async function prepare(client, wallet, draft, opts = {}) {
|
|
70
|
+
const w = getAddress(wallet);
|
|
71
|
+
const read = (functionName, args = []) => client.readContract({ address: w, abi: seeSignWalletAbi, functionName, args });
|
|
72
|
+
const nonce = opts.nonce ?? (await read("nonce"));
|
|
73
|
+
const expiry = (await client.getBlockNumber()) + (opts.expiryBlocks ?? 300n);
|
|
74
|
+
const env = { evmChainId: opts.evmChainId ?? 9800, wallet: w, nonce, expiry };
|
|
75
|
+
let intent;
|
|
76
|
+
let preview;
|
|
77
|
+
switch (draft.action) {
|
|
78
|
+
case "TRANSFER": {
|
|
79
|
+
const label = await read("labelOf", [draft.payee]);
|
|
80
|
+
if (!label)
|
|
81
|
+
throw new NotInBookError(draft.payee, "payee");
|
|
82
|
+
intent = { action: "TRANSFER", token: await readToken(client, draft.token), payee: { address: draft.payee, label }, amount: draft.amount };
|
|
83
|
+
preview = { fn: "previewTransfer", args: [draft.token, draft.payee, draft.amount] };
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case "ADD_PAYEE":
|
|
87
|
+
intent = { action: "ADD_PAYEE", payee: { address: draft.payee, label: draft.label } };
|
|
88
|
+
preview = { fn: "previewAddPayee", args: [draft.payee, draft.label] };
|
|
89
|
+
break;
|
|
90
|
+
case "REMOVE_PAYEE": {
|
|
91
|
+
const label = await read("labelOf", [draft.payee]);
|
|
92
|
+
if (!label)
|
|
93
|
+
throw new NotInBookError(draft.payee, "payee");
|
|
94
|
+
intent = { action: "REMOVE_PAYEE", payee: { address: draft.payee, label } };
|
|
95
|
+
preview = { fn: "previewRemovePayee", args: [draft.payee] };
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "CANCEL_ADD": {
|
|
99
|
+
const [addrs, labels] = await read("pendingPayees");
|
|
100
|
+
const i = addrs.findIndex((x) => getAddress(x) === getAddress(draft.payee));
|
|
101
|
+
if (i < 0)
|
|
102
|
+
throw new NotInBookError(draft.payee, "pending payee");
|
|
103
|
+
intent = { action: "CANCEL_ADD", payee: { address: draft.payee, label: labels[i] } };
|
|
104
|
+
preview = { fn: "previewCancelAdd", args: [draft.payee] };
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "SET_LIMIT":
|
|
108
|
+
intent = { action: "SET_LIMIT", token: await readToken(client, draft.token), limit: draft.limit };
|
|
109
|
+
preview = { fn: "previewSetLimit", args: [draft.token, draft.limit] };
|
|
110
|
+
break;
|
|
111
|
+
case "UPGRADE":
|
|
112
|
+
intent = { action: "UPGRADE", newWallet: draft.newWallet };
|
|
113
|
+
preview = { fn: "previewUpgrade", args: [draft.newWallet] };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const sentence = render(env, intent);
|
|
117
|
+
const contractHex = await read(preview.fn, [...preview.args, nonce, expiry]);
|
|
118
|
+
if (bytesToHex(stringToBytes(sentence)) !== contractHex.toLowerCase()) {
|
|
119
|
+
throw new SentenceMismatchError(sentence, hexToString(contractHex));
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
wallet: w,
|
|
123
|
+
env,
|
|
124
|
+
intent,
|
|
125
|
+
sentence,
|
|
126
|
+
message: messageForSentence(sentence),
|
|
127
|
+
signedCall: (signature) => encodeSignedCall(intent, nonce, expiry, signature),
|
|
128
|
+
relayCall: (signature) => encodeRelay(w, encodeSignedCall(intent, nonce, expiry, signature)),
|
|
129
|
+
};
|
|
130
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./qcs1.ts";
|
|
2
|
+
export * from "./message.ts";
|
|
3
|
+
export * from "./address.ts";
|
|
4
|
+
export * from "./abi.ts";
|
|
5
|
+
export * from "./calls.ts";
|
|
6
|
+
export * from "./chain.ts";
|
|
7
|
+
export * from "./network.ts";
|
|
8
|
+
export * from "./qorex.ts";
|
|
9
|
+
export * from "./verify.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @seesign/kit: QCS-1 clear signing for QoreChain (qorechain-diana testnet).
|
|
2
|
+
export * from "./qcs1.js";
|
|
3
|
+
export * from "./message.js";
|
|
4
|
+
export * from "./address.js";
|
|
5
|
+
export * from "./abi.js";
|
|
6
|
+
export * from "./calls.js";
|
|
7
|
+
export * from "./chain.js";
|
|
8
|
+
export * from "./network.js";
|
|
9
|
+
export * from "./qorex.js";
|
|
10
|
+
export * from "./verify.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes SeeSign works with: the QCS-1 sentence the contract rebuilds, and the
|
|
3
|
+
* message the owner's ML-DSA-87 key signs (QoreSign message-signing-v1, exactly
|
|
4
|
+
* what QoreX signArbitrary signs).
|
|
5
|
+
*/
|
|
6
|
+
import { type Hex } from "viem";
|
|
7
|
+
import { type Envelope, type Intent } from "./qcs1.ts";
|
|
8
|
+
/** The exact QCS-1 sentence bytes for an intent: byte-identical to ClearSign.sol. */
|
|
9
|
+
export declare function renderIntent(env: Envelope, intent: Intent): Uint8Array;
|
|
10
|
+
/** "qorechain-msg-v1|qorechain-diana|" + sentence: the bytes the ML-DSA-87 key signs. */
|
|
11
|
+
export declare function messageToSign(env: Envelope, intent: Intent): Uint8Array;
|
|
12
|
+
/** The same, for a sentence you already have (for example the contract's preview). */
|
|
13
|
+
export declare function messageForSentence(sentence: string | Uint8Array, chain?: string): Uint8Array;
|
|
14
|
+
export declare const toHex: (bytes: Uint8Array) => Hex;
|
package/dist/message.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bytes SeeSign works with: the QCS-1 sentence the contract rebuilds, and the
|
|
3
|
+
* message the owner's ML-DSA-87 key signs (QoreSign message-signing-v1, exactly
|
|
4
|
+
* what QoreX signArbitrary signs).
|
|
5
|
+
*/
|
|
6
|
+
import { bytesToHex, stringToBytes } from "viem";
|
|
7
|
+
import { chainName, render, signingPrefix } from "./qcs1.js";
|
|
8
|
+
/** The exact QCS-1 sentence bytes for an intent: byte-identical to ClearSign.sol. */
|
|
9
|
+
export function renderIntent(env, intent) {
|
|
10
|
+
return stringToBytes(render(env, intent));
|
|
11
|
+
}
|
|
12
|
+
/** "qorechain-msg-v1|qorechain-diana|" + sentence: the bytes the ML-DSA-87 key signs. */
|
|
13
|
+
export function messageToSign(env, intent) {
|
|
14
|
+
return stringToBytes(signingPrefix(chainName(env.evmChainId)) + render(env, intent));
|
|
15
|
+
}
|
|
16
|
+
/** The same, for a sentence you already have (for example the contract's preview). */
|
|
17
|
+
export function messageForSentence(sentence, chain = "qorechain-diana") {
|
|
18
|
+
const body = typeof sentence === "string" ? stringToBytes(sentence) : sentence;
|
|
19
|
+
return new Uint8Array([...stringToBytes(signingPrefix(chain)), ...body]);
|
|
20
|
+
}
|
|
21
|
+
export const toHex = (bytes) => bytesToHex(bytes);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qorechain-diana: endpoints, precompiles, the SeeSign deployment and the fest
|
|
3
|
+
* tokens. Testnet only. `test/network.test.ts` checks the contract addresses
|
|
4
|
+
* against deployments/diana.json.
|
|
5
|
+
*/
|
|
6
|
+
import { type Chain } from "viem";
|
|
7
|
+
export declare const DIANA: {
|
|
8
|
+
readonly chainId: "qorechain-diana";
|
|
9
|
+
readonly evmChainId: 9800;
|
|
10
|
+
readonly endpoints: {
|
|
11
|
+
readonly evmRpc: "https://evm-testnet.qore.host";
|
|
12
|
+
readonly rest: "https://api-testnet.qore.host";
|
|
13
|
+
readonly rpc: "https://rpc-testnet.qore.host";
|
|
14
|
+
};
|
|
15
|
+
readonly explorer: "https://explore.qore.network";
|
|
16
|
+
readonly precompiles: {
|
|
17
|
+
readonly pqcVerify: "0x0000000000000000000000000000000000000a01";
|
|
18
|
+
readonly pqcKeyStatus: "0x0000000000000000000000000000000000000a02";
|
|
19
|
+
};
|
|
20
|
+
readonly contracts: {
|
|
21
|
+
readonly factory: "0x61931F3E9Cac31687Cc53DfC52A833C681d60DbC";
|
|
22
|
+
readonly escrow: "0xD546C87995705DE1fb9426e11f6A9394C0650550";
|
|
23
|
+
};
|
|
24
|
+
/** The demo deployment's ADD_PAYEE timelock (24 hours is recommended for real use). */
|
|
25
|
+
readonly timelockSeconds: 300;
|
|
26
|
+
readonly tokens: {
|
|
27
|
+
readonly QOR: {
|
|
28
|
+
readonly address: "0x0000000000000000000000000000000000000000";
|
|
29
|
+
readonly symbol: "QOR";
|
|
30
|
+
readonly decimals: 18;
|
|
31
|
+
};
|
|
32
|
+
readonly fUSD: {
|
|
33
|
+
readonly address: "0x97143B771D34ddb9130b807b135Ae675A5a963CA";
|
|
34
|
+
readonly symbol: "fUSD";
|
|
35
|
+
readonly decimals: 6;
|
|
36
|
+
};
|
|
37
|
+
readonly fETH: {
|
|
38
|
+
readonly address: "0x02292293c13880a26242690eb70a0e42B8E91c28";
|
|
39
|
+
readonly symbol: "fETH";
|
|
40
|
+
readonly decimals: 18;
|
|
41
|
+
};
|
|
42
|
+
readonly fBTC: {
|
|
43
|
+
readonly address: "0x4604e7E45b2ecdbfbDc157103f5B2b62cb16451A";
|
|
44
|
+
readonly symbol: "fBTC";
|
|
45
|
+
readonly decimals: 8;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** viem chain definition for qorechain-diana. */
|
|
50
|
+
export declare const dianaChain: Chain;
|
|
51
|
+
export declare const txUrl: (hash: string) => string;
|
|
52
|
+
export declare const addressUrl: (address: string) => string;
|
package/dist/network.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qorechain-diana: endpoints, precompiles, the SeeSign deployment and the fest
|
|
3
|
+
* tokens. Testnet only. `test/network.test.ts` checks the contract addresses
|
|
4
|
+
* against deployments/diana.json.
|
|
5
|
+
*/
|
|
6
|
+
import { defineChain } from "viem";
|
|
7
|
+
export const DIANA = {
|
|
8
|
+
chainId: "qorechain-diana",
|
|
9
|
+
evmChainId: 9800,
|
|
10
|
+
endpoints: {
|
|
11
|
+
evmRpc: "https://evm-testnet.qore.host",
|
|
12
|
+
rest: "https://api-testnet.qore.host",
|
|
13
|
+
rpc: "https://rpc-testnet.qore.host",
|
|
14
|
+
},
|
|
15
|
+
explorer: "https://explore.qore.network",
|
|
16
|
+
precompiles: {
|
|
17
|
+
pqcVerify: "0x0000000000000000000000000000000000000a01",
|
|
18
|
+
pqcKeyStatus: "0x0000000000000000000000000000000000000a02",
|
|
19
|
+
},
|
|
20
|
+
contracts: {
|
|
21
|
+
factory: "0x61931F3E9Cac31687Cc53DfC52A833C681d60DbC",
|
|
22
|
+
escrow: "0xD546C87995705DE1fb9426e11f6A9394C0650550",
|
|
23
|
+
},
|
|
24
|
+
/** The demo deployment's ADD_PAYEE timelock (24 hours is recommended for real use). */
|
|
25
|
+
timelockSeconds: 300,
|
|
26
|
+
tokens: {
|
|
27
|
+
QOR: { address: "0x0000000000000000000000000000000000000000", symbol: "QOR", decimals: 18 },
|
|
28
|
+
fUSD: { address: "0x97143B771D34ddb9130b807b135Ae675A5a963CA", symbol: "fUSD", decimals: 6 },
|
|
29
|
+
fETH: { address: "0x02292293c13880a26242690eb70a0e42B8E91c28", symbol: "fETH", decimals: 18 },
|
|
30
|
+
fBTC: { address: "0x4604e7E45b2ecdbfbDc157103f5B2b62cb16451A", symbol: "fBTC", decimals: 8 },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
/** viem chain definition for qorechain-diana. */
|
|
34
|
+
export const dianaChain = defineChain({
|
|
35
|
+
id: DIANA.evmChainId,
|
|
36
|
+
name: "QoreChain Testnet (qorechain-diana)",
|
|
37
|
+
nativeCurrency: { name: "QOR", symbol: "QOR", decimals: 18 },
|
|
38
|
+
rpcUrls: { default: { http: [DIANA.endpoints.evmRpc] } },
|
|
39
|
+
blockExplorers: { default: { name: "QoreChain Explorer", url: DIANA.explorer } },
|
|
40
|
+
testnet: true,
|
|
41
|
+
});
|
|
42
|
+
export const txUrl = (hash) => `${DIANA.explorer}/tx/${hash}`;
|
|
43
|
+
export const addressUrl = (address) => `${DIANA.explorer}/address/${address}`;
|
package/dist/qcs1.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export declare const VERSION_TAG = "SeeSign v1";
|
|
2
|
+
export declare const MAX_SENTENCE_BYTES = 512;
|
|
3
|
+
export declare const MAX_LABEL_BYTES = 32;
|
|
4
|
+
export declare const MAX_SYMBOL_BYTES = 11;
|
|
5
|
+
export declare const MAX_DECIMALS = 36;
|
|
6
|
+
export declare const NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
|
|
7
|
+
export declare const NATIVE_SYMBOL = "QOR";
|
|
8
|
+
export declare const NATIVE_DECIMALS = 18;
|
|
9
|
+
export declare const MAX_UINT64: bigint;
|
|
10
|
+
export declare const MAX_UINT256: bigint;
|
|
11
|
+
/** EVM chain id to the chain name QCS-1 prints, the same name QoreX puts in its prefix. */
|
|
12
|
+
export declare const CHAIN_NAMES: Readonly<Record<number, string>>;
|
|
13
|
+
/** The domain QoreX `signArbitrary` (QoreSign message-signing-v1) puts before the data. */
|
|
14
|
+
export declare const signingPrefix: (chain: string) => string;
|
|
15
|
+
export declare const ACTIONS: readonly ["TRANSFER", "ADD_PAYEE", "REMOVE_PAYEE", "CANCEL_ADD", "SET_LIMIT", "UPGRADE"];
|
|
16
|
+
export type Action = (typeof ACTIONS)[number];
|
|
17
|
+
export declare const ERROR_CODES: readonly ["UnsupportedChain", "UnknownAction", "BadAddress", "ZeroAddress", "BadLabel", "LabelTooLong", "BadSymbol", "BadDecimals", "ValueOutOfRange", "SentenceTooLong"];
|
|
18
|
+
export type Qcs1ErrorCode = (typeof ERROR_CODES)[number];
|
|
19
|
+
/** A call QCS-1 cannot render. A wallet must refuse it: there is no fallback. */
|
|
20
|
+
export declare class Qcs1Error extends Error {
|
|
21
|
+
readonly code: Qcs1ErrorCode;
|
|
22
|
+
constructor(code: Qcs1ErrorCode, detail: string);
|
|
23
|
+
}
|
|
24
|
+
/** A token as the wallet sees it. `address` 0x0 means native QOR (symbol and decimals are then fixed). */
|
|
25
|
+
export interface Token {
|
|
26
|
+
address: string;
|
|
27
|
+
symbol: string;
|
|
28
|
+
decimals: number;
|
|
29
|
+
}
|
|
30
|
+
/** A payee: its address and the label the wallet stores for it. */
|
|
31
|
+
export interface Payee {
|
|
32
|
+
address: string;
|
|
33
|
+
label: string;
|
|
34
|
+
}
|
|
35
|
+
export type Intent = {
|
|
36
|
+
action: "TRANSFER";
|
|
37
|
+
token: Token;
|
|
38
|
+
payee: Payee;
|
|
39
|
+
amount: bigint;
|
|
40
|
+
} | {
|
|
41
|
+
action: "ADD_PAYEE";
|
|
42
|
+
payee: Payee;
|
|
43
|
+
} | {
|
|
44
|
+
action: "REMOVE_PAYEE";
|
|
45
|
+
payee: Payee;
|
|
46
|
+
} | {
|
|
47
|
+
action: "CANCEL_ADD";
|
|
48
|
+
payee: Payee;
|
|
49
|
+
} | {
|
|
50
|
+
action: "SET_LIMIT";
|
|
51
|
+
token: Token;
|
|
52
|
+
limit: bigint;
|
|
53
|
+
} | {
|
|
54
|
+
action: "UPGRADE";
|
|
55
|
+
newWallet: string;
|
|
56
|
+
};
|
|
57
|
+
/** Fields every sentence carries besides the action. */
|
|
58
|
+
export interface Envelope {
|
|
59
|
+
evmChainId: number;
|
|
60
|
+
wallet: string;
|
|
61
|
+
nonce: bigint;
|
|
62
|
+
expiry: bigint;
|
|
63
|
+
}
|
|
64
|
+
export declare function chainName(evmChainId: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* A 20-byte address as EIP-55 text. Accepts lower, upper or correctly
|
|
67
|
+
* checksummed mixed case; a mixed-case input with a wrong checksum is refused
|
|
68
|
+
* (it is most likely a typo).
|
|
69
|
+
*/
|
|
70
|
+
export declare function canonicalAddress(input: string, what?: string): string;
|
|
71
|
+
/** Labels: 1 to 32 bytes of [a-z0-9._-], starting with [a-z0-9], not starting with "0x". */
|
|
72
|
+
export declare function checkLabel(label: string): string;
|
|
73
|
+
/** Token symbols: 1 to 11 bytes of [A-Za-z0-9]. */
|
|
74
|
+
export declare function checkSymbol(symbol: string): string;
|
|
75
|
+
export declare function checkDecimals(decimals: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* A token amount in base units as QCS-1 text (SPEC.md §4.4): integer part with
|
|
78
|
+
* "," every three digits, then "." and the fraction with trailing zeros removed
|
|
79
|
+
* but at least min(2, decimals) digits; no fraction when decimals is 0.
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatAmount(value: bigint, decimals: number): string;
|
|
82
|
+
/**
|
|
83
|
+
* The QCS-1 sentence for an intent, as a string (printable ASCII and LF only).
|
|
84
|
+
* Throws Qcs1Error for anything it cannot render; never renders a fallback.
|
|
85
|
+
*/
|
|
86
|
+
export declare function render(env: Envelope, intent: Intent): string;
|
|
87
|
+
/** The sentence as bytes. */
|
|
88
|
+
export declare function renderBytes(env: Envelope, intent: Intent): Uint8Array;
|
|
89
|
+
/** The exact bytes the ML-DSA-87 key signs: the QoreSign prefix, then the sentence. */
|
|
90
|
+
export declare function signedMessage(env: Envelope, intent: Intent): string;
|
|
91
|
+
/** An intent is live while the current block is at or before its expiry block. */
|
|
92
|
+
export declare function isLive(expiry: bigint, currentBlock: bigint): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Two different addresses whose first 4 and last 4 hex characters match,
|
|
95
|
+
* ignoring case. The same address twice is not a lookalike.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isLookalike(a: string, b: string): boolean;
|