@stasho/vf-records 0.1.1 → 0.2.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.
@@ -8,6 +8,10 @@ export type ExpectedRecord = {
8
8
  kind: "transfer";
9
9
  domain: string;
10
10
  newVault: string;
11
+ } | {
12
+ kind: "accept";
13
+ domain: string;
14
+ transfer: string;
11
15
  };
12
16
  export type CheckResult = {
13
17
  ok: true;
@@ -53,6 +53,9 @@ export function checkPreparedMessage(args) {
53
53
  if (record.kind === "transfer" && args.expected.kind === "transfer" && record.newVault !== args.expected.newVault) {
54
54
  return refuse(`transfer target ${record.newVault} differs from ${args.expected.newVault}`);
55
55
  }
56
+ if (record.kind === "accept" && args.expected.kind === "accept" && record.transfer !== args.expected.transfer) {
57
+ return refuse(`accept names transfer ${record.transfer}, you asked for ${args.expected.transfer}`);
58
+ }
56
59
  const t = Date.parse(record.ts);
57
60
  if (!Number.isFinite(t) || Math.abs(t - args.now) > CLIENT_CHECK_SKEW_MS)
58
61
  return refuse("record timestamp is more than 10 minutes from this clock");
package/dist/records.d.ts CHANGED
@@ -51,6 +51,18 @@ export type VfRecord = {
51
51
  vault: string;
52
52
  op: "bind" | "unbind";
53
53
  ts: string;
54
+ }
55
+ /**
56
+ * Signed by the INCOMING authority of a pending transfer, naming the
57
+ * transfer transaction it accepts. Bound to that signature so it is
58
+ * single-use by construction: a rejected transfer's acceptance cannot be
59
+ * replayed on a later request to the same key (spec § 2, Decision #446).
60
+ */
61
+ | {
62
+ kind: "accept";
63
+ domain: string;
64
+ transfer: string;
65
+ ts: string;
54
66
  };
55
67
  export declare function parsePayload(payload: string): VfRecord | null;
56
68
  /**
package/dist/records.js CHANGED
@@ -103,9 +103,13 @@ export function parsePayload(payload) {
103
103
  return null;
104
104
  return { kind: "bind", domain, vault, op, ts };
105
105
  }
106
+ if (kind === "accept") {
107
+ const transfer = str("transfer");
108
+ return transfer ? { kind: "accept", domain, transfer, ts } : null;
109
+ }
106
110
  return null;
107
111
  }
108
- const RECORD_KINDS = new Set(["pub", "transfer", "bind"]);
112
+ const RECORD_KINDS = new Set(["pub", "transfer", "bind", "accept"]);
109
113
  /**
110
114
  * Parses a record the way the backend index STORES it: the decoded
111
115
  * `VfRecord` as JSON (`{"kind":"pub","domain":…}`), not the raw memo text.
@@ -141,6 +145,11 @@ export function encodeRecord(record) {
141
145
  d: record.domain, newVault: record.newVault, t: record.ts,
142
146
  })}`;
143
147
  }
148
+ if (record.kind === "accept") {
149
+ return `${VF_PREFIX}accept:${JSON.stringify({
150
+ d: record.domain, transfer: record.transfer, t: record.ts,
151
+ })}`;
152
+ }
144
153
  return `${VF_PREFIX}bind:${JSON.stringify({
145
154
  d: record.domain, vault: record.vault, op: record.op, t: record.ts,
146
155
  })}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stasho/vf-records",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Stasho Verified Frontends record codec + the client-side check of a prepared publish message. Zero dependencies, browser-safe.",
5
5
  "license": "MIT",
6
6
  "type": "module",