@bolyra/receipts 0.11.0 → 0.12.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 +201 -0
- package/NOTICE +121 -0
- package/README.md +115 -0
- package/dist/approval.d.ts +251 -0
- package/dist/approval.js +1173 -0
- package/dist/chain.d.ts +3 -0
- package/dist/chain.js +0 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -1
- package/dist/sign.d.ts +7 -0
- package/dist/sign.js +3 -0
- package/dist/types.d.ts +7 -2
- package/package.json +2 -2
- package/src/approval.ts +1410 -0
- package/src/chain.ts +10 -1
- package/src/index.ts +39 -0
- package/src/sign.ts +41 -2
- package/src/types.ts +7 -2
package/src/chain.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { bytesToHex } from '@noble/hashes/utils';
|
|
|
41
41
|
import { canonicalize } from './canonical';
|
|
42
42
|
import { signReceipt, verifyReceipt } from './sign';
|
|
43
43
|
import type { ReceiptPayload, ReceiptSignerConfig, SignedReceipt } from './types';
|
|
44
|
+
import type { ApprovalReceiptPayload, ExecutionReceiptPayload } from './approval';
|
|
44
45
|
|
|
45
46
|
/** Sentinel prevReceiptHash for the first receipt in a log: 32 zero bytes. */
|
|
46
47
|
export const GENESIS_PREV_RECEIPT_HASH = '0x' + '0'.repeat(64);
|
|
@@ -50,7 +51,15 @@ export const GENESIS_PREV_RECEIPT_HASH = '0x' + '0'.repeat(64);
|
|
|
50
51
|
* canonicalize({ payload, signature }). Excludes `id` (derivable from
|
|
51
52
|
* signature.payloadHash) and `receiptHash` itself (to avoid self-reference).
|
|
52
53
|
*/
|
|
53
|
-
export function computeReceiptHash(receipt: SignedReceipt): string
|
|
54
|
+
export function computeReceiptHash(receipt: SignedReceipt): string;
|
|
55
|
+
export function computeReceiptHash(
|
|
56
|
+
receipt: SignedReceipt<ApprovalReceiptPayload | ExecutionReceiptPayload>,
|
|
57
|
+
): string;
|
|
58
|
+
// Legacy signature repeated last: ReturnType/Parameters read the last overload.
|
|
59
|
+
export function computeReceiptHash(receipt: SignedReceipt): string;
|
|
60
|
+
export function computeReceiptHash(
|
|
61
|
+
receipt: SignedReceipt<ReceiptPayload | ApprovalReceiptPayload | ExecutionReceiptPayload>,
|
|
62
|
+
): string {
|
|
54
63
|
const canonical = canonicalize({ payload: receipt.payload, signature: receipt.signature });
|
|
55
64
|
return '0x' + bytesToHex(keccak_256(new TextEncoder().encode(canonical)));
|
|
56
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -43,3 +43,42 @@ export {
|
|
|
43
43
|
type SignerDiscoveryDocument,
|
|
44
44
|
type DiscoveredSigner,
|
|
45
45
|
} from './signer-discovery';
|
|
46
|
+
export {
|
|
47
|
+
ARGUMENTS_DIGEST_DST,
|
|
48
|
+
ARGUMENTS_MAX_BYTES,
|
|
49
|
+
ARGUMENTS_MAX_DEPTH,
|
|
50
|
+
LINK_VERIFICATION_STATEMENT,
|
|
51
|
+
ApprovedExecutionError,
|
|
52
|
+
computeArgumentsDigest,
|
|
53
|
+
createApprovalReceipt,
|
|
54
|
+
executeApproved,
|
|
55
|
+
validateArgumentsJson,
|
|
56
|
+
verifyApprovalExecutionLink,
|
|
57
|
+
} from './approval';
|
|
58
|
+
export type {
|
|
59
|
+
ApprovalAssertion,
|
|
60
|
+
ApprovalBinding,
|
|
61
|
+
ApprovalContext,
|
|
62
|
+
ApprovalDecision,
|
|
63
|
+
ApprovalReceiptInput,
|
|
64
|
+
ApprovalReceiptPayload,
|
|
65
|
+
ApprovalValidity,
|
|
66
|
+
ApprovedExecution,
|
|
67
|
+
ArgumentsValidation,
|
|
68
|
+
BlockedExecution,
|
|
69
|
+
BlockedExecutionCode,
|
|
70
|
+
ConsumeClaim,
|
|
71
|
+
ConsumeFn,
|
|
72
|
+
DispatchFn,
|
|
73
|
+
ExecuteApprovedParams,
|
|
74
|
+
ExecutionFields,
|
|
75
|
+
ExecutionReceiptPayload,
|
|
76
|
+
JsonObject,
|
|
77
|
+
JsonPrimitive,
|
|
78
|
+
JsonValue,
|
|
79
|
+
LinkCheck,
|
|
80
|
+
LinkCheckId,
|
|
81
|
+
LinkVerificationResult,
|
|
82
|
+
ReturnedExecution,
|
|
83
|
+
VerifyLinkParams,
|
|
84
|
+
} from './approval';
|
package/src/sign.ts
CHANGED
|
@@ -5,6 +5,18 @@ import { keccak_256 } from '@noble/hashes/sha3';
|
|
|
5
5
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
6
6
|
import { canonicalize } from './canonical';
|
|
7
7
|
import type { ReceiptPayload, ReceiptSignerConfig, SignedReceipt } from './types';
|
|
8
|
+
import type { ApprovalReceiptPayload, ExecutionReceiptPayload } from './approval';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Payload kinds this module signs. Legacy-first overloads below keep every
|
|
12
|
+
* existing ReceiptPayload call site typed exactly as before; the second
|
|
13
|
+
* overload admits the approval-binding kinds. Runtime behavior, hashes and
|
|
14
|
+
* signature bytes are identical for all of them.
|
|
15
|
+
*/
|
|
16
|
+
type AnyReceiptPayload = ReceiptPayload | ApprovalReceiptPayload | ExecutionReceiptPayload;
|
|
17
|
+
// Each legacy signature appears FIRST (call resolution) and again LAST:
|
|
18
|
+
// conditional types such as ReturnType<typeof signReceipt> read the last
|
|
19
|
+
// overload, and existing code relies on that resolving to the legacy shape.
|
|
8
20
|
|
|
9
21
|
// @noble/secp256k1 v2 requires hmacSha256Sync to be set for synchronous signing.
|
|
10
22
|
secp256k1.etc.hmacSha256Sync = (k: Uint8Array, ...m: Uint8Array[]) => {
|
|
@@ -36,7 +48,10 @@ function deriveAddress(publicKeyBytes: Uint8Array): string {
|
|
|
36
48
|
return '0x' + bytesToHex(hash.slice(hash.length - 20));
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
export function hashPayload(payload: ReceiptPayload): string
|
|
51
|
+
export function hashPayload(payload: ReceiptPayload): string;
|
|
52
|
+
export function hashPayload(payload: ApprovalReceiptPayload | ExecutionReceiptPayload): string;
|
|
53
|
+
export function hashPayload(payload: ReceiptPayload): string;
|
|
54
|
+
export function hashPayload(payload: AnyReceiptPayload): string {
|
|
40
55
|
const canonical = canonicalize(payload);
|
|
41
56
|
const hash = keccak_256(utf8ToBytes(canonical));
|
|
42
57
|
return '0x' + bytesToHex(hash);
|
|
@@ -45,7 +60,19 @@ export function hashPayload(payload: ReceiptPayload): string {
|
|
|
45
60
|
export function signReceipt(
|
|
46
61
|
payload: ReceiptPayload,
|
|
47
62
|
config: ReceiptSignerConfig,
|
|
48
|
-
): SignedReceipt
|
|
63
|
+
): SignedReceipt;
|
|
64
|
+
export function signReceipt<T extends ApprovalReceiptPayload | ExecutionReceiptPayload>(
|
|
65
|
+
payload: T,
|
|
66
|
+
config: ReceiptSignerConfig,
|
|
67
|
+
): SignedReceipt<T>;
|
|
68
|
+
export function signReceipt(
|
|
69
|
+
payload: ReceiptPayload,
|
|
70
|
+
config: ReceiptSignerConfig,
|
|
71
|
+
): SignedReceipt;
|
|
72
|
+
export function signReceipt(
|
|
73
|
+
payload: AnyReceiptPayload,
|
|
74
|
+
config: ReceiptSignerConfig,
|
|
75
|
+
): SignedReceipt<AnyReceiptPayload> {
|
|
49
76
|
const canonical = canonicalize(payload);
|
|
50
77
|
const hash = keccak_256(utf8ToBytes(canonical));
|
|
51
78
|
const privateKeyBytes = hexToBytes(config.privateKey);
|
|
@@ -78,6 +105,18 @@ export function signReceipt(
|
|
|
78
105
|
export function verifyReceipt(
|
|
79
106
|
receipt: SignedReceipt,
|
|
80
107
|
expectedSigner?: string,
|
|
108
|
+
): boolean;
|
|
109
|
+
export function verifyReceipt(
|
|
110
|
+
receipt: SignedReceipt<ApprovalReceiptPayload | ExecutionReceiptPayload>,
|
|
111
|
+
expectedSigner?: string,
|
|
112
|
+
): boolean;
|
|
113
|
+
export function verifyReceipt(
|
|
114
|
+
receipt: SignedReceipt,
|
|
115
|
+
expectedSigner?: string,
|
|
116
|
+
): boolean;
|
|
117
|
+
export function verifyReceipt(
|
|
118
|
+
receipt: SignedReceipt<AnyReceiptPayload>,
|
|
119
|
+
expectedSigner?: string,
|
|
81
120
|
): boolean {
|
|
82
121
|
try {
|
|
83
122
|
// Recompute hash from payload
|
package/src/types.ts
CHANGED
|
@@ -75,10 +75,15 @@ export interface ReceiptPayload {
|
|
|
75
75
|
chain?: ReceiptChainFields;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Signed envelope. Generic over the payload so the approval-binding module can
|
|
80
|
+
* sign its own payload kinds; the default keeps every legacy call site typed
|
|
81
|
+
* exactly as before (`SignedReceipt` === `SignedReceipt<ReceiptPayload>`).
|
|
82
|
+
*/
|
|
83
|
+
export interface SignedReceipt<T = ReceiptPayload> {
|
|
79
84
|
/** First 16 hex chars of payloadHash. */
|
|
80
85
|
id: string;
|
|
81
|
-
payload:
|
|
86
|
+
payload: T;
|
|
82
87
|
signature: {
|
|
83
88
|
alg: 'ES256K';
|
|
84
89
|
keyId: string;
|