@avow-finance/verifier 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 +201 -0
- package/README.md +112 -2
- package/dist/accept.d.ts +170 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +268 -0
- package/dist/accept.js.map +1 -0
- package/dist/authorization.d.ts +65 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/authorization.js +192 -0
- package/dist/authorization.js.map +1 -0
- package/dist/chain.d.ts +160 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +72 -0
- package/dist/chain.js.map +1 -0
- package/dist/consent.d.ts +69 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +98 -0
- package/dist/consent.js.map +1 -0
- package/dist/dependency.d.ts +252 -0
- package/dist/dependency.d.ts.map +1 -0
- package/dist/dependency.js +353 -0
- package/dist/dependency.js.map +1 -0
- package/dist/disclosure.d.ts +88 -0
- package/dist/disclosure.d.ts.map +1 -0
- package/dist/disclosure.js +210 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/issued.d.ts +5 -0
- package/dist/issued.d.ts.map +1 -0
- package/dist/issued.js +24 -0
- package/dist/issued.js.map +1 -0
- package/dist/lock-abi.d.ts +471 -0
- package/dist/lock-abi.d.ts.map +1 -0
- package/dist/lock-abi.js +452 -0
- package/dist/lock-abi.js.map +1 -0
- package/dist/nonce.d.ts +3 -0
- package/dist/nonce.d.ts.map +1 -0
- package/dist/nonce.js +4 -0
- package/dist/nonce.js.map +1 -0
- package/dist/references.d.ts +38 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +93 -0
- package/dist/references.js.map +1 -0
- package/dist/report.d.ts +128 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +155 -0
- package/dist/report.js.map +1 -0
- package/dist/signing.d.ts +47 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +51 -0
- package/dist/signing.js.map +1 -0
- package/dist/tempo.d.ts +70 -0
- package/dist/tempo.d.ts.map +1 -0
- package/dist/tempo.js +341 -0
- package/dist/tempo.js.map +1 -0
- package/dist/verify.d.ts +65 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +36 -0
- package/dist/verify.js.map +1 -0
- package/package.json +34 -3
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type AvowDomain, type ChargeKind, type ChargeReport, type HashSigner, type RailToken, type ReasonCode, type Signed } from '@avow-finance/spec';
|
|
2
|
+
import { type Address, type Hex } from 'viem';
|
|
3
|
+
import { type ChainReader } from './chain.js';
|
|
4
|
+
import { type Disclosure } from './disclosure.js';
|
|
5
|
+
/** A report stays valid for ten minutes at most, and never past the charge deadline. */
|
|
6
|
+
export declare const REPORT_VALIDITY = 600n;
|
|
7
|
+
export interface ReportConfig {
|
|
8
|
+
chainId: number;
|
|
9
|
+
/** The supplier's signing key, which signs the report and which the lock has to hold. */
|
|
10
|
+
signingKey: Address;
|
|
11
|
+
/** Tokens the supplier accepts, used to show the amount a report charges. */
|
|
12
|
+
acceptedTokens: readonly RailToken[];
|
|
13
|
+
}
|
|
14
|
+
export interface ReportDeps {
|
|
15
|
+
config: ReportConfig;
|
|
16
|
+
chain: ChainReader;
|
|
17
|
+
}
|
|
18
|
+
/** What a supplier hands the verifier to get a report of a charge to sign. */
|
|
19
|
+
export interface ReportRequest {
|
|
20
|
+
lock: Address;
|
|
21
|
+
commitmentId: Hex;
|
|
22
|
+
kind: ChargeKind;
|
|
23
|
+
/** Base units of the lock's token. The most the terms let this kind of charge take when left out. */
|
|
24
|
+
amount?: bigint;
|
|
25
|
+
/** The keccak256 of the supplier's evidence for the charge. */
|
|
26
|
+
evidenceHash: Hex;
|
|
27
|
+
/** The chain's time, which the lock judges a report's timing by. */
|
|
28
|
+
now: bigint;
|
|
29
|
+
/** The report's nonce, a fresh random one when left out. */
|
|
30
|
+
nonce?: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface ReadyReport {
|
|
33
|
+
ok: true;
|
|
34
|
+
report: ChargeReport;
|
|
35
|
+
domain: AvowDomain;
|
|
36
|
+
/** The digest the supplier's signing key signs. */
|
|
37
|
+
digest: Hex;
|
|
38
|
+
/** The key that has to sign, the signing key the lock holds for the commitment. */
|
|
39
|
+
signingKey: Address;
|
|
40
|
+
/**
|
|
41
|
+
* Which of the commitment's reports this one is, 1 or 2. The lock's `reportCount` reaches it once
|
|
42
|
+
* the report lands, and passes it once a later report replaces a withdrawn one.
|
|
43
|
+
*/
|
|
44
|
+
reportNumber: number;
|
|
45
|
+
/** What to show the person who approves the signature, before signing. */
|
|
46
|
+
disclosure: Disclosure;
|
|
47
|
+
}
|
|
48
|
+
export type PreparedReport = ReadyReport | {
|
|
49
|
+
ok: false;
|
|
50
|
+
reason: ReasonCode;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The supported way for a supplier to get a report of a charge to sign. A report asks the lock to
|
|
54
|
+
* charge the business's reserve, so this builds one only when the lock would take it, and refuses
|
|
55
|
+
* with the first reason that applies.
|
|
56
|
+
*
|
|
57
|
+
* 1. The lock comes from Avow's factory and holds the commitment with this supplier's signing key.
|
|
58
|
+
* 2. The commitment is accepted with no report open, and it has fewer than two reports.
|
|
59
|
+
* 3. Its terms carry a charge of the reported kind, and the amount, that charge's most when left
|
|
60
|
+
* out, is above zero and within it.
|
|
61
|
+
* 4. The time is at or after that charge's earliest and before the charge deadline.
|
|
62
|
+
*
|
|
63
|
+
* What it returns is frozen, and `signReport` signs nothing else. The lock checks the signature
|
|
64
|
+
* and the same rules when the report lands, so it takes a correctly signed report however it was
|
|
65
|
+
* built.
|
|
66
|
+
*
|
|
67
|
+
* Throws when the chain reader is for another chain or the chain can't be read.
|
|
68
|
+
*/
|
|
69
|
+
export declare function prepareReport(request: ReportRequest, deps: ReportDeps): Promise<PreparedReport>;
|
|
70
|
+
/**
|
|
71
|
+
* Signs a report with the supplier's signing key, once the person has seen its disclosure. It
|
|
72
|
+
* signs only the object `prepareReport` returned, which is frozen, so a copy or an edit of it
|
|
73
|
+
* throws. It also throws when the confirmation names another disclosure, or when the key isn't
|
|
74
|
+
* the signing key the lock holds for the commitment.
|
|
75
|
+
*/
|
|
76
|
+
export declare function signReport(prepared: ReadyReport, key: HashSigner, confirmation: {
|
|
77
|
+
disclosureId: Hex;
|
|
78
|
+
}): Promise<Signed<ChargeReport>>;
|
|
79
|
+
/**
|
|
80
|
+
* The lock's `report`, as the testnet lock declares it. The report's fields come from the spec's
|
|
81
|
+
* `REPORT_TYPES`, so the call carries the fields the signature covers, in the same order. Anyone
|
|
82
|
+
* can send it, since the lock checks the supplier's signing key signed the report, so a supplier
|
|
83
|
+
* can send it from any account that pays the fee.
|
|
84
|
+
*/
|
|
85
|
+
export declare const REPORT_ABI: readonly [{
|
|
86
|
+
readonly type: 'function';
|
|
87
|
+
readonly name: 'report';
|
|
88
|
+
readonly inputs: readonly [{
|
|
89
|
+
readonly name: 'm';
|
|
90
|
+
readonly type: 'tuple';
|
|
91
|
+
readonly components: readonly [{
|
|
92
|
+
readonly name: 'commitmentId';
|
|
93
|
+
readonly type: 'bytes32';
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: 'side';
|
|
96
|
+
readonly type: 'uint8';
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: 'kind';
|
|
99
|
+
readonly type: 'uint8';
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: 'amount';
|
|
102
|
+
readonly type: 'uint256';
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: 'evidenceHash';
|
|
105
|
+
readonly type: 'bytes32';
|
|
106
|
+
}, {
|
|
107
|
+
readonly name: 'nonce';
|
|
108
|
+
readonly type: 'uint256';
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: 'expiry';
|
|
111
|
+
readonly type: 'uint64';
|
|
112
|
+
}];
|
|
113
|
+
}, {
|
|
114
|
+
readonly name: 'signature';
|
|
115
|
+
readonly type: 'bytes';
|
|
116
|
+
}];
|
|
117
|
+
readonly outputs: readonly [];
|
|
118
|
+
readonly stateMutability: 'nonpayable';
|
|
119
|
+
}];
|
|
120
|
+
/**
|
|
121
|
+
* The call that hands a signed report to its lock, with the fields exactly as they were signed, so
|
|
122
|
+
* the lock checks the same digest the supplier's key signed.
|
|
123
|
+
*/
|
|
124
|
+
export declare function reportCall(report: Signed<ChargeReport>): {
|
|
125
|
+
to: Address;
|
|
126
|
+
data: Hex;
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,YAAY,EAEjB,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,KAAK,UAAU,EAEf,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAsB,KAAK,GAAG,EAA+B,MAAM,MAAM,CAAA;AAC9F,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,KAAK,UAAU,EAAiC,MAAM,iBAAiB,CAAA;AAKhF,wFAAwF;AACxF,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,yFAAyF;IACzF,UAAU,EAAE,OAAO,CAAA;IACnB,6EAA6E;IAC7E,cAAc,EAAE,SAAS,SAAS,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,WAAW,CAAA;CACnB;AAED,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,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BAAE,IAAI,EAAE,OAAO;;aAEpC,OAAO;aACP,eAAe,EAAE,YAAY;EAEvB,CAAA;AAEV;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAUnF"}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { CHARGE_KINDS, digestOf, REPORT_TYPES, reportTypedData, } from '@avow-finance/spec';
|
|
2
|
+
import { encodeFunctionData, isAddressEqual, isHex, size } from 'viem';
|
|
3
|
+
import { MAX_REPORTS } from './chain.js';
|
|
4
|
+
import { listedToken, reportDisclosure } from './disclosure.js';
|
|
5
|
+
import { issue } from './issued.js';
|
|
6
|
+
import { randomNonce } from './nonce.js';
|
|
7
|
+
import { signWithKey } from './signing.js';
|
|
8
|
+
/** A report stays valid for ten minutes at most, and never past the charge deadline. */
|
|
9
|
+
export const REPORT_VALIDITY = 600n;
|
|
10
|
+
const isBytes32 = (value) => isHex(value) && size(value) === 32;
|
|
11
|
+
/**
|
|
12
|
+
* The supported way for a supplier to get a report of a charge to sign. A report asks the lock to
|
|
13
|
+
* charge the business's reserve, so this builds one only when the lock would take it, and refuses
|
|
14
|
+
* with the first reason that applies.
|
|
15
|
+
*
|
|
16
|
+
* 1. The lock comes from Avow's factory and holds the commitment with this supplier's signing key.
|
|
17
|
+
* 2. The commitment is accepted with no report open, and it has fewer than two reports.
|
|
18
|
+
* 3. Its terms carry a charge of the reported kind, and the amount, that charge's most when left
|
|
19
|
+
* out, is above zero and within it.
|
|
20
|
+
* 4. The time is at or after that charge's earliest and before the charge deadline.
|
|
21
|
+
*
|
|
22
|
+
* What it returns is frozen, and `signReport` signs nothing else. The lock checks the signature
|
|
23
|
+
* and the same rules when the report lands, so it takes a correctly signed report however it was
|
|
24
|
+
* built.
|
|
25
|
+
*
|
|
26
|
+
* Throws when the chain reader is for another chain or the chain can't be read.
|
|
27
|
+
*/
|
|
28
|
+
export async function prepareReport(request, deps) {
|
|
29
|
+
const { config, chain } = deps;
|
|
30
|
+
if (chain.chainId !== config.chainId) {
|
|
31
|
+
throw new Error(`The chain reader is for chain ${chain.chainId}, not ${config.chainId}`);
|
|
32
|
+
}
|
|
33
|
+
const refuse = (reason) => ({ ok: false, reason });
|
|
34
|
+
if (!Object.hasOwn(CHARGE_KINDS, request.kind) ||
|
|
35
|
+
!isBytes32(request.commitmentId) ||
|
|
36
|
+
!isBytes32(request.evidenceHash) ||
|
|
37
|
+
(request.amount !== undefined && typeof request.amount !== 'bigint')) {
|
|
38
|
+
return refuse('message.invalid');
|
|
39
|
+
}
|
|
40
|
+
// The commitment on the lock, and the supplier's own signing key on it.
|
|
41
|
+
const lockInfo = await chain.lock(request.lock);
|
|
42
|
+
if (!lockInfo?.fromFactory)
|
|
43
|
+
return refuse('chain.lock_unknown');
|
|
44
|
+
const b = await chain.backing(request.lock, request.commitmentId, 'buyer');
|
|
45
|
+
if (!b || b.state === 'none')
|
|
46
|
+
return refuse('chain.reserve_missing');
|
|
47
|
+
if (!isAddressEqual(b.supplierSigner, config.signingKey))
|
|
48
|
+
return refuse('chain.supplier_mismatch');
|
|
49
|
+
// The lock takes a report only on an accepted commitment, one report at a time and two at most.
|
|
50
|
+
if (b.state !== 'accepted')
|
|
51
|
+
return refuse('report.not_reportable');
|
|
52
|
+
if (b.hasReport)
|
|
53
|
+
return refuse('report.open');
|
|
54
|
+
if (b.reportCount >= MAX_REPORTS)
|
|
55
|
+
return refuse('report.limit_reached');
|
|
56
|
+
// The charge the terms set for this kind, its most and its window.
|
|
57
|
+
const charge = b.charges.find((c) => c.kind === request.kind);
|
|
58
|
+
if (!charge)
|
|
59
|
+
return refuse('report.kind_not_allowed');
|
|
60
|
+
const amount = request.amount ?? charge.most;
|
|
61
|
+
if (amount <= 0n || amount > charge.most)
|
|
62
|
+
return refuse('report.amount_invalid');
|
|
63
|
+
if (request.now < charge.earliest)
|
|
64
|
+
return refuse('report.too_early');
|
|
65
|
+
if (request.now >= b.chargeDeadline)
|
|
66
|
+
return refuse('commitment.ended');
|
|
67
|
+
const latest = request.now + REPORT_VALIDITY;
|
|
68
|
+
const report = {
|
|
69
|
+
commitmentId: request.commitmentId,
|
|
70
|
+
side: 'buyer',
|
|
71
|
+
kind: request.kind,
|
|
72
|
+
amount,
|
|
73
|
+
evidenceHash: request.evidenceHash,
|
|
74
|
+
nonce: request.nonce ?? randomNonce(),
|
|
75
|
+
expiry: latest < b.chargeDeadline ? latest : b.chargeDeadline,
|
|
76
|
+
};
|
|
77
|
+
const d = { chainId: config.chainId, verifyingContract: request.lock };
|
|
78
|
+
const digest = digestOf(reportTypedData(report, d));
|
|
79
|
+
return issue({
|
|
80
|
+
ok: true,
|
|
81
|
+
report,
|
|
82
|
+
domain: d,
|
|
83
|
+
digest,
|
|
84
|
+
signingKey: config.signingKey,
|
|
85
|
+
reportNumber: b.reportCount + 1,
|
|
86
|
+
disclosure: reportDisclosure({
|
|
87
|
+
digest,
|
|
88
|
+
report,
|
|
89
|
+
lock: request.lock,
|
|
90
|
+
chainId: config.chainId,
|
|
91
|
+
account: lockInfo.account,
|
|
92
|
+
payee: b.payee,
|
|
93
|
+
token: listedToken(config.acceptedTokens, config.chainId, lockInfo.token),
|
|
94
|
+
chargeDeadline: b.chargeDeadline,
|
|
95
|
+
contestWindow: b.contestWindow,
|
|
96
|
+
day90SupplierShareBps: b.day90SupplierShareBps,
|
|
97
|
+
timing: lockInfo.timing,
|
|
98
|
+
reportCount: b.reportCount,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Signs a report with the supplier's signing key, once the person has seen its disclosure. It
|
|
104
|
+
* signs only the object `prepareReport` returned, which is frozen, so a copy or an edit of it
|
|
105
|
+
* throws. It also throws when the confirmation names another disclosure, or when the key isn't
|
|
106
|
+
* the signing key the lock holds for the commitment.
|
|
107
|
+
*/
|
|
108
|
+
export function signReport(prepared, key, confirmation) {
|
|
109
|
+
return signWithKey({
|
|
110
|
+
prepared,
|
|
111
|
+
typedData: reportTypedData(prepared.report, prepared.domain),
|
|
112
|
+
message: prepared.report,
|
|
113
|
+
key,
|
|
114
|
+
confirmation,
|
|
115
|
+
names: {
|
|
116
|
+
message: 'report',
|
|
117
|
+
prepare: 'prepareReport',
|
|
118
|
+
signingKey: 'the signing key the lock holds for the commitment',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The lock's `report`, as the testnet lock declares it. The report's fields come from the spec's
|
|
124
|
+
* `REPORT_TYPES`, so the call carries the fields the signature covers, in the same order. Anyone
|
|
125
|
+
* can send it, since the lock checks the supplier's signing key signed the report, so a supplier
|
|
126
|
+
* can send it from any account that pays the fee.
|
|
127
|
+
*/
|
|
128
|
+
export const REPORT_ABI = [
|
|
129
|
+
{
|
|
130
|
+
type: 'function',
|
|
131
|
+
name: 'report',
|
|
132
|
+
inputs: [
|
|
133
|
+
{ name: 'm', type: 'tuple', components: REPORT_TYPES.Report },
|
|
134
|
+
{ name: 'signature', type: 'bytes' },
|
|
135
|
+
],
|
|
136
|
+
outputs: [],
|
|
137
|
+
stateMutability: 'nonpayable',
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
/**
|
|
141
|
+
* The call that hands a signed report to its lock, with the fields exactly as they were signed, so
|
|
142
|
+
* the lock checks the same digest the supplier's key signed.
|
|
143
|
+
*/
|
|
144
|
+
export function reportCall(report) {
|
|
145
|
+
const d = { chainId: report.chainId, verifyingContract: report.lock };
|
|
146
|
+
return {
|
|
147
|
+
to: report.lock,
|
|
148
|
+
data: encodeFunctionData({
|
|
149
|
+
abi: REPORT_ABI,
|
|
150
|
+
functionName: 'report',
|
|
151
|
+
args: [reportTypedData(report.message, d).message, report.signature],
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sour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E,EAAE;QACX,eAAe,EAAE,YAAY;KAC9B;CACO,CAAA;AAEV;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAA4B;IACrD,MAAM,CAAC,GAAe,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;IACjF,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,IAAI;QACf,IAAI,EAAE,kBAAkB,CAAC;YACvB,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,QAAQ;YACtB,IAAI,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC;SACrE,CAAC;KACH,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type AvowDomain, type AvowTypedData, type HashSigner, type Signed } from '@avow-finance/spec';
|
|
2
|
+
import type { Address, Hex } from 'viem';
|
|
3
|
+
import { type Disclosure } from './disclosure.js';
|
|
4
|
+
/** What a prepare call returns for a message, which only that message's signing call signs. */
|
|
5
|
+
export interface Prepared {
|
|
6
|
+
domain: AvowDomain;
|
|
7
|
+
/** The digest the message's signer signs. */
|
|
8
|
+
digest: Hex;
|
|
9
|
+
disclosure: Disclosure;
|
|
10
|
+
}
|
|
11
|
+
/** How a signing call's errors name its message and the prepare call that built it. */
|
|
12
|
+
export interface SigningNames {
|
|
13
|
+
message: string;
|
|
14
|
+
prepare: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Checks a prepared message before anything signs it, and returns the digest to sign. It has to be
|
|
18
|
+
* the frozen object its prepare call returned, its digest and disclosure have to match its message,
|
|
19
|
+
* and the confirmation has to name that disclosure, so nothing is signed before a person has seen
|
|
20
|
+
* what it binds the signer to.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkPrepared(prepared: Prepared, typedData: AvowTypedData, confirmation: {
|
|
23
|
+
disclosureId: Hex;
|
|
24
|
+
}, names: SigningNames): Hex;
|
|
25
|
+
/** A signed message as it travels, under the domain its prepare call built it for. */
|
|
26
|
+
export declare function signedMessage<T>(typedData: AvowTypedData, domain: AvowDomain, message: T, signature: Hex): Signed<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Signs a prepared message with one key's own signature, as the supplier's signing key signs an
|
|
29
|
+
* acceptance or a report. It signs only once `checkPrepared` passes, and throws when the signature
|
|
30
|
+
* isn't the one key the message has to come from.
|
|
31
|
+
*/
|
|
32
|
+
export declare function signWithKey<T>(args: {
|
|
33
|
+
prepared: Prepared & {
|
|
34
|
+
signingKey: Address;
|
|
35
|
+
};
|
|
36
|
+
typedData: AvowTypedData;
|
|
37
|
+
message: T;
|
|
38
|
+
key: HashSigner;
|
|
39
|
+
confirmation: {
|
|
40
|
+
disclosureId: Hex;
|
|
41
|
+
};
|
|
42
|
+
/** `signingKey` describes the key the message has to come from, for the error. */
|
|
43
|
+
names: SigningNames & {
|
|
44
|
+
signingKey: string;
|
|
45
|
+
};
|
|
46
|
+
}): Promise<Signed<T>>;
|
|
47
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAElB,KAAK,UAAU,EAGf,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,iBAAiB,CAAA;AAG/D,+FAA+F;AAC/F,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,UAAU,CAAA;IAClB,6CAA6C;IAC7C,MAAM,EAAE,GAAG,CAAA;IACX,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,uFAAuF;AACvF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,aAAa,EACxB,YAAY,EAAE;IAAE,YAAY,EAAE,GAAG,CAAA;CAAE,EACnC,KAAK,EAAE,YAAY,GAClB,GAAG,CAqBL;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,CAAC,EAC7B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,CAAC,EACV,SAAS,EAAE,GAAG,GACb,MAAM,CAAC,CAAC,CAAC,CASX;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,QAAQ,GAAG;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,CAAA;IAC5C,SAAS,EAAE,aAAa,CAAA;IACxB,OAAO,EAAE,CAAC,CAAA;IACV,GAAG,EAAE,UAAU,CAAA;IACf,YAAY,EAAE;QAAE,YAAY,EAAE,GAAG,CAAA;KAAE,CAAA;IACnC,kFAAkF;IAClF,KAAK,EAAE,YAAY,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAOrB"}
|
package/dist/signing.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { digestOf, isKeySignature, MESSAGE_VERSIONS, } from '@avow-finance/spec';
|
|
2
|
+
import { same } from './authorization.js';
|
|
3
|
+
import { disclosureId } from './disclosure.js';
|
|
4
|
+
import { wasIssued } from './issued.js';
|
|
5
|
+
/**
|
|
6
|
+
* Checks a prepared message before anything signs it, and returns the digest to sign. It has to be
|
|
7
|
+
* the frozen object its prepare call returned, its digest and disclosure have to match its message,
|
|
8
|
+
* and the confirmation has to name that disclosure, so nothing is signed before a person has seen
|
|
9
|
+
* what it binds the signer to.
|
|
10
|
+
*/
|
|
11
|
+
export function checkPrepared(prepared, typedData, confirmation, names) {
|
|
12
|
+
if (!wasIssued(prepared)) {
|
|
13
|
+
throw new Error(`Sign only the ${names.message} ${names.prepare} returned, as it returned it`);
|
|
14
|
+
}
|
|
15
|
+
const digest = digestOf(typedData);
|
|
16
|
+
const { disclosure } = prepared;
|
|
17
|
+
if (!same(digest, prepared.digest) ||
|
|
18
|
+
!same(disclosure.digest, digest) ||
|
|
19
|
+
!same(disclosureId(disclosure), disclosure.id)) {
|
|
20
|
+
throw new Error(`The ${names.message} or its disclosure changed after ${names.prepare} built them`);
|
|
21
|
+
}
|
|
22
|
+
if (!same(confirmation?.disclosureId, disclosure.id)) {
|
|
23
|
+
throw new Error(`Show the person this ${names.message}'s disclosure, and pass its id back once they confirm it`);
|
|
24
|
+
}
|
|
25
|
+
return digest;
|
|
26
|
+
}
|
|
27
|
+
/** A signed message as it travels, under the domain its prepare call built it for. */
|
|
28
|
+
export function signedMessage(typedData, domain, message, signature) {
|
|
29
|
+
return {
|
|
30
|
+
type: typedData.primaryType,
|
|
31
|
+
schemaVersion: MESSAGE_VERSIONS[typedData.primaryType],
|
|
32
|
+
chainId: domain.chainId,
|
|
33
|
+
lock: domain.verifyingContract,
|
|
34
|
+
message,
|
|
35
|
+
signature,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Signs a prepared message with one key's own signature, as the supplier's signing key signs an
|
|
40
|
+
* acceptance or a report. It signs only once `checkPrepared` passes, and throws when the signature
|
|
41
|
+
* isn't the one key the message has to come from.
|
|
42
|
+
*/
|
|
43
|
+
export async function signWithKey(args) {
|
|
44
|
+
const digest = checkPrepared(args.prepared, args.typedData, args.confirmation, args.names);
|
|
45
|
+
const signature = await args.key.sign({ hash: digest });
|
|
46
|
+
if (!isKeySignature(digest, signature, args.prepared.signingKey)) {
|
|
47
|
+
throw new Error(`The key that signed isn't ${args.names.signingKey}`);
|
|
48
|
+
}
|
|
49
|
+
return signedMessage(args.typedData, args.prepared.domain, args.message, signature);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.js","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EAER,cAAc,EACd,gBAAgB,GAEjB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAmB,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAgBvC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAkB,EAClB,SAAwB,EACxB,YAAmC,EACnC,KAAmB;IAEnB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;IAChG,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAA;IAClC,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAA;IAC/B,IACE,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;QAC9B,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;QAChC,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,EAC9C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,OAAO,KAAK,CAAC,OAAO,oCAAoC,KAAK,CAAC,OAAO,aAAa,CACnF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,wBAAwB,KAAK,CAAC,OAAO,0DAA0D,CAChG,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAC3B,SAAwB,EACxB,MAAkB,EAClB,OAAU,EACV,SAAc;IAEd,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,WAAW;QAC3B,aAAa,EAAE,gBAAgB,CAAC,SAAS,CAAC,WAAW,CAAC;QACtD,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,iBAAiB;QAC9B,OAAO;QACP,SAAS;KACV,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,IAQpC;IACC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IAC1F,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IACvD,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;IACvE,CAAC;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AACrF,CAAC"}
|
package/dist/tempo.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ObservedTransfer, type Side } from '@avow-finance/spec';
|
|
2
|
+
import { type Address, type Client, type Hex, type Log } from 'viem';
|
|
3
|
+
import type { AgentKeyInfo, ChainReader, ContestOnChain, LockedBacking, ObservedContest } from './chain.js';
|
|
4
|
+
import type { PinnedLockReader } from './dependency.js';
|
|
5
|
+
/**
|
|
6
|
+
* Reads an agent key from Tempo's keychain: whether it's revoked, when it expires, and the
|
|
7
|
+
* mandate hash bound into it. The keychain logs that hash as a witness in the transaction that
|
|
8
|
+
* authorized the key, and Moderato's public RPC searches logs only over short block ranges, so the
|
|
9
|
+
* caller names that transaction. Its receipt comes from the chain, so naming it proves nothing on
|
|
10
|
+
* its own: the key and the witness must both appear in it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readAgentKey(client: Client, account: Address, key: Address, authorizedIn: Hex): Promise<AgentKeyInfo | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Reads the log at one index of one transaction. The log counts as a payment only when a TIP-20
|
|
15
|
+
* token emitted it and it decodes as that token's `TransferWithMemo` event, and the caller checks
|
|
16
|
+
* that the token is the one the reference names and one it accepts. The receipt is final only
|
|
17
|
+
* when its block is at or below the chain's finalized block and is the chain's block at that
|
|
18
|
+
* height, so a receipt from a block that lost a reorg never reads as final.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readTransfer(client: Client, chainId: number, transactionHash: Hex, logIndex: number): Promise<ObservedTransfer | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Reads what a lock holds for one side of a commitment, or null when it holds nothing. It reads
|
|
23
|
+
* only the lock, so it needs no factory, and the caller decides whether the lock is Avow's. Given
|
|
24
|
+
* a block number it reads the lock as of that block, and a node that doesn't have the block yet
|
|
25
|
+
* refuses the read.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readBacking(client: Client, lock: Address, commitmentId: Hex, side: 'buyer' | 'supplier', options?: {
|
|
28
|
+
blockNumber?: bigint;
|
|
29
|
+
}): Promise<LockedBacking | null>;
|
|
30
|
+
/**
|
|
31
|
+
* The contest of one side of a commitment among one transaction's logs, from the `Paused` event the
|
|
32
|
+
* lock logged with a contest as its cause, or null when there's none. Only a log the lock itself
|
|
33
|
+
* wrote counts, since any contract can write one shaped like it. A transaction can carry calls to
|
|
34
|
+
* several commitments, so the event has to name this commitment and side.
|
|
35
|
+
*/
|
|
36
|
+
export declare function contestInLogs(logs: readonly Log[], lock: Address, commitmentId: Hex, side: Side): ObservedContest | null;
|
|
37
|
+
/**
|
|
38
|
+
* Reads the contest of one side of a commitment that one transaction carried to a lock, from the
|
|
39
|
+
* transaction's receipt, with whether its block is final as `readTransfer` judges it, and the
|
|
40
|
+
* report it named as the lock held it at that block. It returns null when the chain has no such
|
|
41
|
+
* transaction, when the transaction failed, or when it holds no contest of that side from that
|
|
42
|
+
* lock, and throws when the node can't answer, so an outage never reads as a missing contest.
|
|
43
|
+
*
|
|
44
|
+
* The lock's record is read as of the end of the contest's block, so a withdrawal and a new report
|
|
45
|
+
* later in that same block would show the new report. The lock takes a contest only when it names
|
|
46
|
+
* the latest report, so the record shows the contested report unless both happened in that block.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readContest(client: Client, lock: Address, commitmentId: Hex, side: Side, transactionHash: Hex): Promise<ContestOnChain | null>;
|
|
49
|
+
export interface TempoReaderOptions {
|
|
50
|
+
/** The factory the supplier trusts. Only a lock it created counts as Avow's. */
|
|
51
|
+
factory: Address;
|
|
52
|
+
/** The chain's id, the client's own chain when left out. */
|
|
53
|
+
chainId?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reads the locks one factory created on Tempo, every read as of a block named by number, for the
|
|
57
|
+
* check of a booking another booking relies on. The latest finalized block is the one pinned, so
|
|
58
|
+
* no later block can change what it shows, and a node that doesn't have a block refuses the read.
|
|
59
|
+
* The pinned block carries its timestamp, so the check can refuse a node that has fallen behind.
|
|
60
|
+
* The caller trusts the node the client talks to, so it uses one it chose.
|
|
61
|
+
*/
|
|
62
|
+
export declare function tempoLockReader(client: Client, options: TempoReaderOptions): PinnedLockReader;
|
|
63
|
+
/**
|
|
64
|
+
* Reads Tempo directly: the lock's settings and its record of a commitment, the agent key in the
|
|
65
|
+
* keychain, and account signatures through Tempo's own signature verifier. A lock counts as
|
|
66
|
+
* Avow's only when the factory the supplier pinned says it created it, since any contract can name
|
|
67
|
+
* a factory. The supplier trusts the node the client talks to, so it uses one it chose.
|
|
68
|
+
*/
|
|
69
|
+
export declare function tempoChainReader(client: Client, options: TempoReaderOptions): ChainReader;
|
|
70
|
+
//# sourceMappingURL=tempo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tempo.d.ts","sourceRoot":"","sources":["../src/tempo.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,gBAAgB,EAGrB,KAAK,IAAI,EAEV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,MAAM,EACX,KAAK,GAAG,EAER,KAAK,GAAG,EAIT,MAAM,MAAM,CAAA;AAGb,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,aAAa,EAEb,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAMvD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,EACZ,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAiC9B;AA8CD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,GAAG,EACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAyBlC;AAaD;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,GAAG,EACjB,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,OAAO,GAAE;IAAE,WA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