@peers-app/peers-sdk 0.27.2 → 0.27.4
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/contracts/contract-proxy.d.ts +7 -0
- package/dist/contracts/contract-proxy.js +19 -2
- package/dist/contracts/create-local-consumer.js +16 -1
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/system/index.d.ts +2 -0
- package/dist/contracts/system/index.js +2 -0
- package/dist/contracts/system/invites-contract.js +2 -1
- package/dist/contracts/system/sync-check-contract.d.ts +97 -0
- package/dist/contracts/system/sync-check-contract.js +115 -0
- package/dist/contracts/tool-arguments.d.ts +15 -0
- package/dist/contracts/tool-arguments.js +41 -0
- package/dist/contracts/tool-catalog-service.js +2 -12
- package/dist/data/change-tracking.d.ts +40 -0
- package/dist/data/change-tracking.js +89 -0
- package/dist/data/orm/types.d.ts +24 -7
- package/dist/data/orm/types.js +97 -24
- package/dist/data/persistent-vars.d.ts +5 -0
- package/dist/data/persistent-vars.js +24 -6
- package/dist/define/manifest.js +6 -34
- package/dist/package-loader/package-loader.js +27 -22
- package/dist/system-ids.d.ts +5 -0
- package/dist/system-ids.js +6 -1
- package/package.json +4 -2
- package/dist/context/user-context-identity.test.d.ts +0 -1
- package/dist/context/user-context-identity.test.js +0 -220
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
- package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
- package/dist/contracts/__tests__/also-implements.test.js +0 -110
- package/dist/contracts/__tests__/builder.test.d.ts +0 -1
- package/dist/contracts/__tests__/builder.test.js +0 -669
- package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-events.test.js +0 -199
- package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-observables.test.js +0 -290
- package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
- package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
- package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
- package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
- package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/contract-transport.test.js +0 -163
- package/dist/contracts/__tests__/extract.test.d.ts +0 -1
- package/dist/contracts/__tests__/extract.test.js +0 -145
- package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
- package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
- package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
- package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
- package/dist/contracts/__tests__/integration.test.d.ts +0 -1
- package/dist/contracts/__tests__/integration.test.js +0 -348
- package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
- package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
- package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
- package/dist/contracts/__tests__/playground.test.d.ts +0 -1
- package/dist/contracts/__tests__/playground.test.js +0 -216
- package/dist/contracts/__tests__/registry.test.d.ts +0 -1
- package/dist/contracts/__tests__/registry.test.js +0 -238
- package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
- package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
- package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
- package/dist/contracts/__tests__/system-contracts.test.js +0 -247
- package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
- package/dist/contracts/__tests__/target-dispatch.js +0 -24
- package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
- package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
- package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
- package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
- package/dist/contracts/__tests__/validate.test.d.ts +0 -1
- package/dist/contracts/__tests__/validate.test.js +0 -991
- package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
- package/dist/contracts/__tests__/workflow-context.test.js +0 -50
- package/dist/data/access-level.test.d.ts +0 -1
- package/dist/data/access-level.test.js +0 -53
- package/dist/data/change-tracking.test.d.ts +0 -1
- package/dist/data/change-tracking.test.js +0 -62
- package/dist/data/files/files.test.d.ts +0 -1
- package/dist/data/files/files.test.js +0 -770
- package/dist/data/group-members.test.d.ts +0 -1
- package/dist/data/group-members.test.js +0 -336
- package/dist/data/group-share.test.d.ts +0 -1
- package/dist/data/group-share.test.js +0 -110
- package/dist/data/groups.test.d.ts +0 -1
- package/dist/data/groups.test.js +0 -153
- package/dist/data/orm/cursor.test.d.ts +0 -1
- package/dist/data/orm/cursor.test.js +0 -314
- package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
- package/dist/data/orm/data-query.mongo.test.js +0 -367
- package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
- package/dist/data/orm/data-query.sqlite.test.js +0 -365
- package/dist/data/orm/data-query.test.d.ts +0 -1
- package/dist/data/orm/data-query.test.js +0 -545
- package/dist/data/orm/dependency-injection.test.d.ts +0 -1
- package/dist/data/orm/dependency-injection.test.js +0 -171
- package/dist/data/orm/event-registry.test.d.ts +0 -1
- package/dist/data/orm/event-registry.test.js +0 -44
- package/dist/data/orm/multi-cursors.test.d.ts +0 -1
- package/dist/data/orm/multi-cursors.test.js +0 -463
- package/dist/data/orm/sql.data-source.test.d.ts +0 -1
- package/dist/data/orm/sql.data-source.test.js +0 -731
- package/dist/data/orm/table-container-events.test.d.ts +0 -1
- package/dist/data/orm/table-container-events.test.js +0 -101
- package/dist/data/orm/table-container.test.d.ts +0 -1
- package/dist/data/orm/table-container.test.js +0 -273
- package/dist/data/orm/table.event-source.test.d.ts +0 -1
- package/dist/data/orm/table.event-source.test.js +0 -331
- package/dist/data/orm/types.test.d.ts +0 -1
- package/dist/data/orm/types.test.js +0 -409
- package/dist/data/package-table-identity.test.d.ts +0 -1
- package/dist/data/package-table-identity.test.js +0 -46
- package/dist/data/package-version-permissions.test.d.ts +0 -1
- package/dist/data/package-version-permissions.test.js +0 -107
- package/dist/data/package-version-resolver.test.d.ts +0 -4
- package/dist/data/package-version-resolver.test.js +0 -543
- package/dist/data/package-versions.test.d.ts +0 -1
- package/dist/data/package-versions.test.js +0 -227
- package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
- package/dist/data/persistent-vars.conflict.test.js +0 -126
- package/dist/data/persistent-vars.migration.test.d.ts +0 -1
- package/dist/data/persistent-vars.migration.test.js +0 -133
- package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
- package/dist/data/persistent-vars.package-scope.test.js +0 -27
- package/dist/data/sync-recovery-queue.test.d.ts +0 -1
- package/dist/data/sync-recovery-queue.test.js +0 -215
- package/dist/data/table-signing.test.d.ts +0 -1
- package/dist/data/table-signing.test.js +0 -118
- package/dist/data/tool-access.test.d.ts +0 -1
- package/dist/data/tool-access.test.js +0 -166
- package/dist/data/user-permissions.test.d.ts +0 -1
- package/dist/data/user-permissions.test.js +0 -305
- package/dist/data/user-trust-levels.test.d.ts +0 -1
- package/dist/data/user-trust-levels.test.js +0 -37
- package/dist/define/also-implements.test.d.ts +0 -1
- package/dist/define/also-implements.test.js +0 -123
- package/dist/define/declare-contract.test.d.ts +0 -1
- package/dist/define/declare-contract.test.js +0 -573
- package/dist/define/define.test.d.ts +0 -1
- package/dist/define/define.test.js +0 -1010
- package/dist/define/empty-fields.test.d.ts +0 -1
- package/dist/define/empty-fields.test.js +0 -55
- package/dist/define/events-observables.test.d.ts +0 -1
- package/dist/define/events-observables.test.js +0 -1013
- package/dist/define/serve-members.test.d.ts +0 -1
- package/dist/define/serve-members.test.js +0 -630
- package/dist/define/vars.test.d.ts +0 -1
- package/dist/define/vars.test.js +0 -39
- package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
- package/dist/device/binary-peer-connection-v2.test.js +0 -730
- package/dist/device/binary-peer-connection.test.d.ts +0 -1
- package/dist/device/binary-peer-connection.test.js +0 -184
- package/dist/device/connection.test.d.ts +0 -1
- package/dist/device/connection.test.js +0 -613
- package/dist/device/device-election.test.d.ts +0 -1
- package/dist/device/device-election.test.js +0 -516
- package/dist/device/device.test.d.ts +0 -1
- package/dist/device/device.test.js +0 -243
- package/dist/device/frame-cipher.test.d.ts +0 -1
- package/dist/device/frame-cipher.test.js +0 -219
- package/dist/device/get-trust-level-fn.test.d.ts +0 -1
- package/dist/device/get-trust-level-fn.test.js +0 -685
- package/dist/device/streamed-socket.test.d.ts +0 -1
- package/dist/device/streamed-socket.test.js +0 -216
- package/dist/device/tx-encoding.test.d.ts +0 -1
- package/dist/device/tx-encoding.test.js +0 -295
- package/dist/device-pairing/cpace.test.d.ts +0 -1
- package/dist/device-pairing/cpace.test.js +0 -116
- package/dist/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/device-pairing/device-pairing.test.js +0 -211
- package/dist/hlc.test.d.ts +0 -1
- package/dist/hlc.test.js +0 -45
- package/dist/host-credentials.test.d.ts +0 -1
- package/dist/host-credentials.test.js +0 -88
- package/dist/identity/account-email.test.d.ts +0 -1
- package/dist/identity/account-email.test.js +0 -59
- package/dist/identity/anchor-document.test.d.ts +0 -1
- package/dist/identity/anchor-document.test.js +0 -16
- package/dist/identity/anchor-resolution.test.d.ts +0 -1
- package/dist/identity/anchor-resolution.test.js +0 -130
- package/dist/identity/key-change.test.d.ts +0 -1
- package/dist/identity/key-change.test.js +0 -811
- package/dist/invites/group-approval.test.d.ts +0 -1
- package/dist/invites/group-approval.test.js +0 -223
- package/dist/invites/invite-token.test.d.ts +0 -1
- package/dist/invites/invite-token.test.js +0 -123
- package/dist/keys.test.d.ts +0 -1
- package/dist/keys.test.js +0 -336
- package/dist/logging/console-logger.test.d.ts +0 -1
- package/dist/logging/console-logger.test.js +0 -300
- package/dist/logging/console-logs.table.test.d.ts +0 -1
- package/dist/logging/console-logs.table.test.js +0 -156
- package/dist/observable.test.d.ts +0 -1
- package/dist/observable.test.js +0 -309
- package/dist/package-build/build-package.test.d.ts +0 -1
- package/dist/package-build/build-package.test.js +0 -204
- package/dist/package-build/contract-add.test.d.ts +0 -1
- package/dist/package-build/contract-add.test.js +0 -467
- package/dist/package-build/freeze-contracts.test.d.ts +0 -1
- package/dist/package-build/freeze-contracts.test.js +0 -355
- package/dist/package-installer/package-author-signing.test.d.ts +0 -1
- package/dist/package-installer/package-author-signing.test.js +0 -200
- package/dist/package-installer/package-cloner.test.d.ts +0 -1
- package/dist/package-installer/package-cloner.test.js +0 -278
- package/dist/package-installer/package-creator.test.d.ts +0 -1
- package/dist/package-installer/package-creator.test.js +0 -908
- package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
- package/dist/package-installer/package-dev-tools.test.js +0 -64
- package/dist/package-installer/package-installer.test.d.ts +0 -1
- package/dist/package-installer/package-installer.test.js +0 -882
- package/dist/package-installer/package-propagation.test.d.ts +0 -1
- package/dist/package-installer/package-propagation.test.js +0 -1269
- package/dist/package-installer/package-publisher.test.d.ts +0 -1
- package/dist/package-installer/package-publisher.test.js +0 -153
- package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
- package/dist/package-installer/package-remote-checker.test.js +0 -334
- package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
- package/dist/package-installer/package-seed-installer.test.js +0 -123
- package/dist/package-installer/package-tarball.test.d.ts +0 -1
- package/dist/package-installer/package-tarball.test.js +0 -75
- package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
- package/dist/package-installer/peers-core-installer.test.js +0 -49
- package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
- package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
- package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
- package/dist/package-loader/contract-package-loader.test.js +0 -274
- package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
- package/dist/package-loader/host-authority-loading.test.js +0 -104
- package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
- package/dist/package-loader/host-dispatch-policy.test.js +0 -56
- package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
- package/dist/package-loader/isolated-artifact.test.js +0 -688
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
- package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
- package/dist/package-loader/isolated-table-gateway.test.js +0 -633
- package/dist/package-loader/package-loader.test.d.ts +0 -1
- package/dist/package-loader/package-loader.test.js +0 -1764
- package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
- package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
- package/dist/serial-json.compat.test.d.ts +0 -1
- package/dist/serial-json.compat.test.js +0 -369
- package/dist/serial-json.test.d.ts +0 -1
- package/dist/serial-json.test.js +0 -401
- package/dist/testing/mock-host-contract.test.d.ts +0 -1
- package/dist/testing/mock-host-contract.test.js +0 -782
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -232
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const device_1 = require("../device/device");
|
|
4
|
-
const keys_1 = require("../keys");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const _1 = require(".");
|
|
7
|
-
const NOW = 1_800_000_000_000;
|
|
8
|
-
const ORIGIN = "https://peers.app";
|
|
9
|
-
const FINGERPRINT = Array.from({ length: 32 }, (_, index) => index.toString(16).padStart(2, "0"))
|
|
10
|
-
.join(":")
|
|
11
|
-
.toUpperCase();
|
|
12
|
-
describe("pairing code", () => {
|
|
13
|
-
it("uses the full PGP word lists with no duplicates", () => {
|
|
14
|
-
expect(_1.PGP_EVEN_WORDS).toHaveLength(256);
|
|
15
|
-
expect(_1.PGP_ODD_WORDS).toHaveLength(256);
|
|
16
|
-
expect(new Set([..._1.PGP_EVEN_WORDS, ..._1.PGP_ODD_WORDS]).size).toBe(512);
|
|
17
|
-
});
|
|
18
|
-
it("generates even/odd/even words and round-trips through formatting and parsing", () => {
|
|
19
|
-
const words = (0, _1.generatePairingWords)();
|
|
20
|
-
expect(_1.PGP_EVEN_WORDS).toContain(words[0]);
|
|
21
|
-
expect(_1.PGP_ODD_WORDS).toContain(words[1]);
|
|
22
|
-
expect(_1.PGP_EVEN_WORDS).toContain(words[2]);
|
|
23
|
-
const text = (0, _1.formatPairingCode)(7, words);
|
|
24
|
-
expect(text).toBe(`7-${words.join("-")}`);
|
|
25
|
-
expect((0, _1.parsePairingCode)(text)).toEqual({ nameplate: 7, words });
|
|
26
|
-
expect((0, _1.parsePairingCode)(` 7 ${words.join(" ").toUpperCase()} `)).toEqual({
|
|
27
|
-
nameplate: 7,
|
|
28
|
-
words,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
it("rejects wrong slots, unknown words, bad nameplates, and wrong lengths", () => {
|
|
32
|
-
expect(() => (0, _1.parsePairingCode)("7-adroitness-aardvark-absurd")).toThrow(/word 1/);
|
|
33
|
-
expect(() => (0, _1.parsePairingCode)("7-aardvark-absurd-acme")).toThrow(/word 2/);
|
|
34
|
-
expect(() => (0, _1.parsePairingCode)("7-aardvark-adroitness-nope")).toThrow(/word 3/);
|
|
35
|
-
expect(() => (0, _1.parsePairingCode)("0-aardvark-adroitness-acme")).toThrow(/room number/);
|
|
36
|
-
expect(() => (0, _1.parsePairingCode)("10000-aardvark-adroitness-acme")).toThrow(/room number/);
|
|
37
|
-
expect(() => (0, _1.parsePairingCode)("aardvark-adroitness-acme")).toThrow(/three words/);
|
|
38
|
-
expect(() => (0, _1.parsePairingCode)("7-aardvark-adroitness")).toThrow(/three words/);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe("pairing PAKE and signaling", () => {
|
|
42
|
-
const code = (0, _1.parsePairingCode)("42-aardvark-adroitness-acme");
|
|
43
|
-
it("derives matching keys for the same code and different keys for a wrong code", () => {
|
|
44
|
-
const source = (0, _1.startPairingPake)("source", code, ORIGIN);
|
|
45
|
-
const destination = (0, _1.startPairingPake)("destination", code, ORIGIN);
|
|
46
|
-
const sourceKeys = source.finish(destination.share);
|
|
47
|
-
const destinationKeys = destination.finish(source.share);
|
|
48
|
-
expect(sourceKeys).toEqual(destinationKeys);
|
|
49
|
-
expect(sourceKeys.signalingKey).not.toBe(sourceKeys.confirmKey);
|
|
50
|
-
const token = (0, _1.derivePairingWebSocketToken)(sourceKeys.signalingKey);
|
|
51
|
-
expect(token).toBe((0, _1.derivePairingWebSocketToken)(destinationKeys.signalingKey));
|
|
52
|
-
expect(token).not.toBe(sourceKeys.signalingKey);
|
|
53
|
-
expect(token).not.toBe(sourceKeys.confirmKey);
|
|
54
|
-
const wrong = (0, _1.startPairingPake)("source", (0, _1.parsePairingCode)("42-absurd-adroitness-acme"), ORIGIN);
|
|
55
|
-
const honest = (0, _1.startPairingPake)("destination", code, ORIGIN);
|
|
56
|
-
expect(wrong.finish(honest.share)).not.toEqual(honest.finish(wrong.share));
|
|
57
|
-
const otherRoom = (0, _1.startPairingPake)("source", { ...code, nameplate: 43 }, ORIGIN);
|
|
58
|
-
const thisRoom = (0, _1.startPairingPake)("destination", code, ORIGIN);
|
|
59
|
-
expect(otherRoom.finish(thisRoom.share)).not.toEqual(thisRoom.finish(otherRoom.share));
|
|
60
|
-
});
|
|
61
|
-
it("accepts the pake share unauthenticated and everything else only with the key", () => {
|
|
62
|
-
const share = (0, _1.startPairingPake)("source", code, ORIGIN).share;
|
|
63
|
-
const pake = (0, _1.createPairingPakeSignal)({
|
|
64
|
-
nameplate: 42,
|
|
65
|
-
senderRole: "source",
|
|
66
|
-
sequence: 1,
|
|
67
|
-
share,
|
|
68
|
-
});
|
|
69
|
-
expect((0, _1.verifyPairingSignal)(pake, undefined, {
|
|
70
|
-
nameplate: 42,
|
|
71
|
-
senderRole: "source",
|
|
72
|
-
nextSequence: 1,
|
|
73
|
-
})).toEqual(pake);
|
|
74
|
-
const keys = (0, _1.startPairingPake)("destination", code, ORIGIN);
|
|
75
|
-
const signalingKey = keys.finish(share).signalingKey;
|
|
76
|
-
const options = (0, _1.signPairingSignal)({
|
|
77
|
-
version: 3,
|
|
78
|
-
nameplate: 42,
|
|
79
|
-
senderRole: "destination",
|
|
80
|
-
sequence: 2,
|
|
81
|
-
kind: "transport-options",
|
|
82
|
-
payload: {
|
|
83
|
-
endpointNonce: (0, keys_1.newToken)(32),
|
|
84
|
-
webrtc: false,
|
|
85
|
-
websocket: { urls: ["http://192.168.1.20:3341", "wss://peers.example.com"] },
|
|
86
|
-
},
|
|
87
|
-
}, signalingKey);
|
|
88
|
-
expect((0, _1.verifyPairingSignal)(options, signalingKey, {
|
|
89
|
-
nameplate: 42,
|
|
90
|
-
senderRole: "destination",
|
|
91
|
-
nextSequence: 2,
|
|
92
|
-
})).toEqual(options);
|
|
93
|
-
expect(() => (0, _1.signPairingSignal)({
|
|
94
|
-
...options,
|
|
95
|
-
payload: { ...options.payload, websocket: { urls: ["ftp://nope"] } },
|
|
96
|
-
}, signalingKey)).toThrow();
|
|
97
|
-
const choice = (0, _1.signPairingSignal)({
|
|
98
|
-
version: 3,
|
|
99
|
-
nameplate: 42,
|
|
100
|
-
senderRole: "source",
|
|
101
|
-
sequence: 2,
|
|
102
|
-
kind: "transport-choice",
|
|
103
|
-
payload: { endpointNonce: (0, keys_1.newToken)(32), selected: "ws", url: "http://192.168.1.20:3341" },
|
|
104
|
-
}, signalingKey);
|
|
105
|
-
expect((0, _1.verifyPairingSignal)(choice, signalingKey, {
|
|
106
|
-
nameplate: 42,
|
|
107
|
-
senderRole: "source",
|
|
108
|
-
nextSequence: 2,
|
|
109
|
-
})).toEqual(choice);
|
|
110
|
-
const offerSdp = `v=0\r\na=fingerprint:sha-256 ${FINGERPRINT}\r\n`;
|
|
111
|
-
const signal = (0, _1.signPairingSignal)({
|
|
112
|
-
version: 3,
|
|
113
|
-
nameplate: 42,
|
|
114
|
-
senderRole: "source",
|
|
115
|
-
sequence: 3,
|
|
116
|
-
kind: "offer",
|
|
117
|
-
payload: { type: "offer", sdp: offerSdp },
|
|
118
|
-
}, signalingKey);
|
|
119
|
-
const expected = { nameplate: 42, senderRole: "source", nextSequence: 3 };
|
|
120
|
-
expect((0, _1.verifyPairingSignal)(signal, signalingKey, expected)).toEqual(signal);
|
|
121
|
-
expect(() => (0, _1.verifyPairingSignal)(signal, undefined, expected)).toThrow(/before authentication/);
|
|
122
|
-
expect(() => (0, _1.verifyPairingSignal)({ ...signal, payload: { ...signal.payload, sdp: `${offerSdp}modified` } }, signalingKey, expected)).toThrow(/authentication failed/);
|
|
123
|
-
expect(() => (0, _1.verifyPairingSignal)(signal, signalingKey, { ...expected, senderRole: "destination" })).toThrow(/out of order/);
|
|
124
|
-
expect(() => (0, _1.verifyPairingSignal)(signal, signalingKey, { ...expected, nextSequence: 4 })).toThrow(/out of order/);
|
|
125
|
-
expect(() => (0, _1.verifyPairingSignal)(signal, signalingKey, { ...expected, nameplate: 41 })).toThrow(/out of order/);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe("pairing transcript, confirmation, and credentials", () => {
|
|
129
|
-
const source = new device_1.Device();
|
|
130
|
-
const destination = new device_1.Device();
|
|
131
|
-
const sdp = `v=0\r\na=fingerprint:sha-256 ${FINGERPRINT}\r\n`;
|
|
132
|
-
const transcript = {
|
|
133
|
-
version: 3,
|
|
134
|
-
serviceOrigin: ORIGIN,
|
|
135
|
-
nameplate: 42,
|
|
136
|
-
sourceIdentity: (0, keys_1.openSignedObject)(source.getDeviceInfo()),
|
|
137
|
-
destinationIdentity: (0, keys_1.openSignedObject)(destination.getDeviceInfo()),
|
|
138
|
-
sourceEndpointNonce: (0, keys_1.newToken)(32),
|
|
139
|
-
destinationEndpointNonce: (0, keys_1.newToken)(32),
|
|
140
|
-
transport: "wrtc",
|
|
141
|
-
transportBinding: (0, _1.webRtcPairingTransportBinding)(sdp, sdp),
|
|
142
|
-
};
|
|
143
|
-
it("hashes the transcript deterministically and changes with any input", () => {
|
|
144
|
-
const hash = (0, _1.computeDevicePairingTranscriptHash)(transcript);
|
|
145
|
-
expect((0, _1.computeDevicePairingTranscriptHash)(transcript)).toBe(hash);
|
|
146
|
-
expect((0, _1.computeDevicePairingTranscriptHash)({ ...transcript, nameplate: 43 })).not.toBe(hash);
|
|
147
|
-
expect(transcript.transportBinding).toBe(`${(0, _1.extractSha256SdpFingerprint)(sdp)}|${(0, _1.extractSha256SdpFingerprint)(sdp)}`);
|
|
148
|
-
expect((0, _1.computeDevicePairingTranscriptHash)({
|
|
149
|
-
...transcript,
|
|
150
|
-
transportBinding: transcript.transportBinding.replace("00", "FF"),
|
|
151
|
-
})).not.toBe(hash);
|
|
152
|
-
expect((0, _1.computeDevicePairingTranscriptHash)({
|
|
153
|
-
...transcript,
|
|
154
|
-
transport: "ws",
|
|
155
|
-
transportBinding: "http://192.168.1.20:3341",
|
|
156
|
-
})).not.toBe(hash);
|
|
157
|
-
});
|
|
158
|
-
it("confirms only with the same key, role, transcript, and identity", () => {
|
|
159
|
-
const code = (0, _1.parsePairingCode)("42-aardvark-adroitness-acme");
|
|
160
|
-
const sourcePake = (0, _1.startPairingPake)("source", code, ORIGIN);
|
|
161
|
-
const destinationPake = (0, _1.startPairingPake)("destination", code, ORIGIN);
|
|
162
|
-
const keys = sourcePake.finish(destinationPake.share);
|
|
163
|
-
const wrongKeys = (0, _1.startPairingPake)("destination", (0, _1.parsePairingCode)("42-absurd-adroitness-acme"), ORIGIN).finish((0, _1.startPairingPake)("source", code, ORIGIN).share);
|
|
164
|
-
const transcriptHash = (0, _1.computeDevicePairingTranscriptHash)(transcript);
|
|
165
|
-
const confirmation = (0, _1.createPairingConfirmation)({
|
|
166
|
-
role: "destination",
|
|
167
|
-
transcriptHash,
|
|
168
|
-
device: transcript.destinationIdentity,
|
|
169
|
-
presentation: { deviceName: "Phone", deviceType: "mobile" },
|
|
170
|
-
}, keys.confirmKey);
|
|
171
|
-
const expected = {
|
|
172
|
-
role: "destination",
|
|
173
|
-
transcriptHash,
|
|
174
|
-
device: transcript.destinationIdentity,
|
|
175
|
-
};
|
|
176
|
-
expect((0, _1.verifyPairingConfirmation)(confirmation, keys.confirmKey, expected)).toEqual(confirmation);
|
|
177
|
-
expect(() => (0, _1.verifyPairingConfirmation)(confirmation, wrongKeys.confirmKey, expected)).toThrow(/did not match/);
|
|
178
|
-
expect(() => (0, _1.verifyPairingConfirmation)(confirmation, keys.confirmKey, { ...expected, role: "source" })).toThrow(/does not match/);
|
|
179
|
-
expect(() => (0, _1.verifyPairingConfirmation)(confirmation, keys.confirmKey, {
|
|
180
|
-
...expected,
|
|
181
|
-
device: transcript.sourceIdentity,
|
|
182
|
-
})).toThrow(/identity mismatch/);
|
|
183
|
-
expect(() => (0, _1.verifyPairingConfirmation)({ ...confirmation, presentation: { deviceName: "Evil" } }, keys.confirmKey, expected)).toThrow(/did not match/);
|
|
184
|
-
});
|
|
185
|
-
it("requires the expected identities and transcript for credentials and receipt", () => {
|
|
186
|
-
const transcriptHash = (0, keys_1.newToken)(32);
|
|
187
|
-
const expiresAt = NOW + 60_000;
|
|
188
|
-
const credentials = { userId: (0, utils_1.newid)(), secretKey: (0, keys_1.newKeys)().secretKey };
|
|
189
|
-
const destinationInfo = (0, keys_1.openSignedObject)(destination.getDeviceInfo());
|
|
190
|
-
const envelope = (0, _1.createPairingCredentialEnvelope)(source, destinationInfo, credentials, transcriptHash, expiresAt);
|
|
191
|
-
expect((0, _1.openPairingCredentialEnvelope)(destination, envelope, {
|
|
192
|
-
sourcePublicKey: source.publicKey,
|
|
193
|
-
sourcePublicBoxKey: source.publicBoxKey,
|
|
194
|
-
transcriptHash,
|
|
195
|
-
now: NOW,
|
|
196
|
-
})).toEqual({ version: 3, transcriptHash, expiresAt, ...credentials });
|
|
197
|
-
expect(() => (0, _1.openPairingCredentialEnvelope)(new device_1.Device(), envelope, {
|
|
198
|
-
sourcePublicKey: source.publicKey,
|
|
199
|
-
sourcePublicBoxKey: source.publicBoxKey,
|
|
200
|
-
transcriptHash,
|
|
201
|
-
now: NOW,
|
|
202
|
-
})).toThrow();
|
|
203
|
-
const initialized = new device_1.Device(credentials.userId);
|
|
204
|
-
const initializedInfo = (0, keys_1.openSignedObject)(initialized.getDeviceInfo());
|
|
205
|
-
const receipt = (0, _1.createSignedPairingInstallationReceipt)(destination, transcriptHash, initializedInfo, NOW);
|
|
206
|
-
expect((0, _1.verifySignedPairingInstallationReceipt)(receipt, {
|
|
207
|
-
temporaryDestinationPublicKey: destination.publicKey,
|
|
208
|
-
transcriptHash,
|
|
209
|
-
})).toEqual(initializedInfo);
|
|
210
|
-
});
|
|
211
|
-
});
|
package/dist/hlc.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/hlc.test.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const hlc_1 = require("./hlc");
|
|
4
|
-
const peer_device_1 = require("./types/peer-device");
|
|
5
|
-
describe("HybridLogicalClock", () => {
|
|
6
|
-
it("is monotonic when now goes backward", () => {
|
|
7
|
-
let t = 1000;
|
|
8
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => t });
|
|
9
|
-
const first = clock.tick();
|
|
10
|
-
t = 100;
|
|
11
|
-
const second = clock.tick();
|
|
12
|
-
expect(second).toBe(first + 1);
|
|
13
|
-
});
|
|
14
|
-
it("advances by 1 on the same millisecond", () => {
|
|
15
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => 5000 });
|
|
16
|
-
expect(clock.tick()).toBe(5000);
|
|
17
|
-
expect(clock.tick()).toBe(5001);
|
|
18
|
-
expect(clock.tick()).toBe(5002);
|
|
19
|
-
});
|
|
20
|
-
it("observe advances last so the next tick is after the observed time", () => {
|
|
21
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => 1000 });
|
|
22
|
-
expect(clock.observe(2500)).toBe(true);
|
|
23
|
-
expect(clock.tick()).toBe(2501);
|
|
24
|
-
});
|
|
25
|
-
it("observe ignores timestamps beyond the skew bound", () => {
|
|
26
|
-
const now = 10_000;
|
|
27
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => now });
|
|
28
|
-
const future = now + peer_device_1.PeerDeviceConsts.CHANGE_TIMESTAMP_TOLERANCE_MS + 1;
|
|
29
|
-
expect(clock.observe(future)).toBe(false);
|
|
30
|
-
expect(clock.tick()).toBe(now);
|
|
31
|
-
});
|
|
32
|
-
it("seed raises last without going backward", () => {
|
|
33
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => 1000 });
|
|
34
|
-
clock.seed(2000);
|
|
35
|
-
clock.seed(1500);
|
|
36
|
-
expect(clock.tick()).toBe(2001);
|
|
37
|
-
});
|
|
38
|
-
it("now peeks physical time without advancing", () => {
|
|
39
|
-
const clock = new hlc_1.HybridLogicalClock({ now: () => 42 });
|
|
40
|
-
expect(clock.now()).toBe(42);
|
|
41
|
-
expect(clock.now()).toBe(42);
|
|
42
|
-
expect(clock.value).toBe(0);
|
|
43
|
-
expect(clock.tick()).toBe(42);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const host_credentials_1 = require("./host-credentials");
|
|
4
|
-
const keys_1 = require("./keys");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
describe("host credential record", () => {
|
|
7
|
-
const userId = (0, utils_1.newid)();
|
|
8
|
-
const k1 = (0, keys_1.newKeys)();
|
|
9
|
-
const k2 = (0, keys_1.newKeys)();
|
|
10
|
-
it("parses the legacy userId::secretKey form and derives the legacy db secret", () => {
|
|
11
|
-
const record = (0, host_credentials_1.parseCredentialRecord)(`${userId}::${k1.secretKey}`);
|
|
12
|
-
expect(record).toEqual({
|
|
13
|
-
userId,
|
|
14
|
-
secretKey: k1.secretKey,
|
|
15
|
-
dbSecret: (0, keys_1.hashValue)(k1.secretKey),
|
|
16
|
-
});
|
|
17
|
-
expect((0, host_credentials_1.legacyDbSecret)(k1.secretKey)).toBe((0, keys_1.hashValue)(k1.secretKey));
|
|
18
|
-
});
|
|
19
|
-
it("parses the JSON form, filling a missing dbSecret with the legacy value", () => {
|
|
20
|
-
expect((0, host_credentials_1.parseCredentialRecord)(JSON.stringify({ userId, secretKey: k1.secretKey }))).toEqual({
|
|
21
|
-
userId,
|
|
22
|
-
secretKey: k1.secretKey,
|
|
23
|
-
dbSecret: (0, keys_1.hashValue)(k1.secretKey),
|
|
24
|
-
});
|
|
25
|
-
const full = {
|
|
26
|
-
userId,
|
|
27
|
-
secretKey: k2.secretKey,
|
|
28
|
-
dbSecret: "db",
|
|
29
|
-
previousPublicKeys: [{ publicKey: k1.publicKey, replacedAt: "2026-10-02T00:00:00.000Z" }],
|
|
30
|
-
};
|
|
31
|
-
expect((0, host_credentials_1.parseCredentialRecord)((0, host_credentials_1.serializeCredentialRecord)(full))).toEqual(full);
|
|
32
|
-
});
|
|
33
|
-
it("returns null for garbage", () => {
|
|
34
|
-
expect((0, host_credentials_1.parseCredentialRecord)(null)).toBeNull();
|
|
35
|
-
expect((0, host_credentials_1.parseCredentialRecord)("")).toBeNull();
|
|
36
|
-
expect((0, host_credentials_1.parseCredentialRecord)("{not json")).toBeNull();
|
|
37
|
-
expect((0, host_credentials_1.parseCredentialRecord)(JSON.stringify({ userId }))).toBeNull();
|
|
38
|
-
expect((0, host_credentials_1.parseCredentialRecord)("::")).toBeNull();
|
|
39
|
-
expect((0, host_credentials_1.parseCredentialRecord)("nosep")).toBeNull();
|
|
40
|
-
});
|
|
41
|
-
it("mints a random dbSecret only when asked", () => {
|
|
42
|
-
const fresh = (0, host_credentials_1.normalizeCredentialRecord)({ userId, secretKey: k1.secretKey }, { freshDbSecret: true });
|
|
43
|
-
expect(fresh.dbSecret).not.toBe((0, keys_1.hashValue)(k1.secretKey));
|
|
44
|
-
expect(fresh.dbSecret.length).toBeGreaterThan(30);
|
|
45
|
-
const kept = (0, host_credentials_1.normalizeCredentialRecord)({ userId, secretKey: k1.secretKey, dbSecret: "keep" }, {
|
|
46
|
-
freshDbSecret: true,
|
|
47
|
-
});
|
|
48
|
-
expect(kept.dbSecret).toBe("keep");
|
|
49
|
-
});
|
|
50
|
-
it("rotates the secret while keeping dbSecret and remembering the old key", () => {
|
|
51
|
-
const current = (0, host_credentials_1.normalizeCredentialRecord)({ userId, secretKey: k1.secretKey });
|
|
52
|
-
const at = new Date("2026-10-03T00:00:00.000Z");
|
|
53
|
-
const rotated = (0, host_credentials_1.rotateCredentialRecord)(current, {
|
|
54
|
-
secretKey: k2.secretKey,
|
|
55
|
-
oldPublicKey: k1.publicKey,
|
|
56
|
-
reason: "compromised",
|
|
57
|
-
at,
|
|
58
|
-
});
|
|
59
|
-
expect(rotated).toEqual({
|
|
60
|
-
userId,
|
|
61
|
-
secretKey: k2.secretKey,
|
|
62
|
-
dbSecret: (0, keys_1.hashValue)(k1.secretKey),
|
|
63
|
-
previousPublicKeys: [
|
|
64
|
-
{ publicKey: k1.publicKey, replacedAt: at.toISOString(), reason: "compromised" },
|
|
65
|
-
],
|
|
66
|
-
rewrapFrom: { publicKey: k1.publicKey, secretKey: k1.secretKey },
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
it("keeps the retired secret through storage until the re-wrap is finished", () => {
|
|
70
|
-
// Secrets in the personal database are re-wrapped one by one after the new key is stored.
|
|
71
|
-
// A crash in between must not lose the only key that can still open the rest.
|
|
72
|
-
const rotated = (0, host_credentials_1.rotateCredentialRecord)((0, host_credentials_1.normalizeCredentialRecord)({ userId, secretKey: k1.secretKey }), { secretKey: k2.secretKey, oldPublicKey: k1.publicKey });
|
|
73
|
-
const stored = (0, host_credentials_1.parseCredentialRecord)((0, host_credentials_1.serializeCredentialRecord)(rotated));
|
|
74
|
-
expect(stored?.rewrapFrom).toEqual({ publicKey: k1.publicKey, secretKey: k1.secretKey });
|
|
75
|
-
expect(stored?.secretKey).toBe(k2.secretKey);
|
|
76
|
-
const finished = (0, host_credentials_1.completeCredentialRewrap)(rotated);
|
|
77
|
-
expect(finished.rewrapFrom).toBeUndefined();
|
|
78
|
-
expect(finished.secretKey).toBe(k2.secretKey);
|
|
79
|
-
expect(finished.previousPublicKeys).toEqual(rotated.previousPublicKeys);
|
|
80
|
-
expect((0, host_credentials_1.parseCredentialRecord)((0, host_credentials_1.serializeCredentialRecord)(finished))?.rewrapFrom).toBeUndefined();
|
|
81
|
-
// A half-written slot is not a key to re-wrap from.
|
|
82
|
-
expect((0, host_credentials_1.parseCredentialRecord)(JSON.stringify({
|
|
83
|
-
userId,
|
|
84
|
-
secretKey: k2.secretKey,
|
|
85
|
-
rewrapFrom: { publicKey: k1.publicKey },
|
|
86
|
-
}))?.rewrapFrom).toBeUndefined();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const keys_1 = require("../keys");
|
|
4
|
-
const account_email_1 = require("./account-email");
|
|
5
|
-
describe("account email statements", () => {
|
|
6
|
-
const keys = (0, keys_1.newKeys)();
|
|
7
|
-
const userId = "00maccountemailstatements";
|
|
8
|
-
const issuedAt = new Date().toISOString();
|
|
9
|
-
const bind = (0, account_email_1.signEmailBind)({ purpose: "peers-account-email-bind", userId, email: "ada@example.com", issuedAt }, keys.secretKey);
|
|
10
|
-
const status = (0, account_email_1.signEmailStatus)({ purpose: "peers-account-email-status", userId, issuedAt }, keys.secretKey);
|
|
11
|
-
const unbind = (0, account_email_1.signEmailUnbind)({ purpose: "peers-account-email-unbind", userId, issuedAt }, keys.secretKey);
|
|
12
|
-
it("accepts each statement for the purpose it was signed for", () => {
|
|
13
|
-
expect((0, account_email_1.verifyEmailBind)({
|
|
14
|
-
signed: bind,
|
|
15
|
-
userId,
|
|
16
|
-
email: "ada@example.com",
|
|
17
|
-
recordPublicKey: keys.publicKey,
|
|
18
|
-
})).toBe(true);
|
|
19
|
-
expect((0, account_email_1.verifyEmailStatus)({ signed: status, userId, recordPublicKey: keys.publicKey })).toBe(true);
|
|
20
|
-
expect((0, account_email_1.verifyEmailUnbind)({ signed: unbind, userId, recordPublicKey: keys.publicKey })).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
it("does not let a statement signed for one purpose stand in for another", () => {
|
|
23
|
-
// A captured read request must not be able to remove the mailbox or bind a new one.
|
|
24
|
-
expect((0, account_email_1.verifyEmailUnbind)({ signed: status, userId, recordPublicKey: keys.publicKey })).toBe(false);
|
|
25
|
-
expect((0, account_email_1.verifyEmailBind)({
|
|
26
|
-
signed: status,
|
|
27
|
-
userId,
|
|
28
|
-
email: "ada@example.com",
|
|
29
|
-
recordPublicKey: keys.publicKey,
|
|
30
|
-
})).toBe(false);
|
|
31
|
-
expect((0, account_email_1.verifyEmailStatus)({ signed: unbind, userId, recordPublicKey: keys.publicKey })).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
it("refuses a statement for another user, another mailbox, or from another key", () => {
|
|
34
|
-
expect((0, account_email_1.verifyEmailBind)({
|
|
35
|
-
signed: bind,
|
|
36
|
-
userId: "00maccountemailotheruser0",
|
|
37
|
-
email: "ada@example.com",
|
|
38
|
-
recordPublicKey: keys.publicKey,
|
|
39
|
-
})).toBe(false);
|
|
40
|
-
expect((0, account_email_1.verifyEmailBind)({
|
|
41
|
-
signed: bind,
|
|
42
|
-
userId,
|
|
43
|
-
email: "eve@example.com",
|
|
44
|
-
recordPublicKey: keys.publicKey,
|
|
45
|
-
})).toBe(false);
|
|
46
|
-
expect((0, account_email_1.verifyEmailUnbind)({ signed: unbind, userId, recordPublicKey: (0, keys_1.newKeys)().publicKey })).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
it("refuses a statement whose contents were changed after signing", () => {
|
|
49
|
-
const forged = {
|
|
50
|
-
...unbind,
|
|
51
|
-
contents: { ...unbind.contents, userId: "00maccountemailotheruser0" },
|
|
52
|
-
};
|
|
53
|
-
expect((0, account_email_1.verifyEmailUnbind)({
|
|
54
|
-
signed: forged,
|
|
55
|
-
userId: "00maccountemailotheruser0",
|
|
56
|
-
recordPublicKey: keys.publicKey,
|
|
57
|
-
})).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const anchor_document_1 = require("./anchor-document");
|
|
4
|
-
describe("normalizeAnchorList", () => {
|
|
5
|
-
it("allows http for peers-services and requires https for a page anchor", () => {
|
|
6
|
-
const list = (0, anchor_document_1.normalizeAnchorList)([
|
|
7
|
-
{ type: "peers-services", url: "http://127.0.0.1:4000/api/v1/keys/abc" },
|
|
8
|
-
{ type: "https", url: "https://example.com/peers.json" },
|
|
9
|
-
]);
|
|
10
|
-
expect(list.map((anchor) => anchor.url)).toEqual([
|
|
11
|
-
"https://example.com/peers.json",
|
|
12
|
-
"http://127.0.0.1:4000/api/v1/keys/abc",
|
|
13
|
-
]);
|
|
14
|
-
expect(() => (0, anchor_document_1.normalizeAnchorList)([{ type: "https", url: "http://example.com/peers.json" }])).toThrow(/https/);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("../index");
|
|
4
|
-
const anchor_document_1 = require("./anchor-document");
|
|
5
|
-
const anchor_resolution_1 = require("./anchor-resolution");
|
|
6
|
-
const userId = (0, index_1.newid)();
|
|
7
|
-
const record = (0, index_1.newKeys)();
|
|
8
|
-
const next = (0, index_1.newKeys)();
|
|
9
|
-
const anchor = {
|
|
10
|
-
type: "https",
|
|
11
|
-
url: "https://example.com/.well-known/peers-identity.json",
|
|
12
|
-
};
|
|
13
|
-
function document(keys) {
|
|
14
|
-
return {
|
|
15
|
-
version: 1,
|
|
16
|
-
userId,
|
|
17
|
-
keys,
|
|
18
|
-
anchors: [anchor],
|
|
19
|
-
updatedAt: "2026-10-03T18:00:00.000Z",
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function confirm(entry) {
|
|
23
|
-
return { outcome: "document", document: document([entry]), maxAgeSeconds: 30 };
|
|
24
|
-
}
|
|
25
|
-
describe("resolvePresentedKey", () => {
|
|
26
|
-
const issuedAt = "2026-10-03T18:00:00.000Z";
|
|
27
|
-
it("confirms a rotation when the key on record co-signed and nobody vetoes", () => {
|
|
28
|
-
const signed = (0, anchor_document_1.signSuccession)({ purpose: "peers-key-succession", userId, publicKey: next.publicKey, issuedAt }, record.secretKey);
|
|
29
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
30
|
-
userId,
|
|
31
|
-
recordPublicKey: record.publicKey,
|
|
32
|
-
presentedPublicKey: next.publicKey,
|
|
33
|
-
outcomes: [
|
|
34
|
-
confirm({
|
|
35
|
-
publicKey: next.publicKey,
|
|
36
|
-
issuedAt,
|
|
37
|
-
reason: "rotation",
|
|
38
|
-
authorizedBy: { publicKey: signed.publicKey, signature: signed.signature },
|
|
39
|
-
}),
|
|
40
|
-
{ outcome: "abstain" },
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
expect(resolution.state).toBe("confirmed-rotation");
|
|
44
|
-
expect(resolution.successionByRecordKey).toBe(true);
|
|
45
|
-
expect(resolution.cacheSeconds).toBe(30);
|
|
46
|
-
});
|
|
47
|
-
it("treats a listed key without the record key's signature as recovery", () => {
|
|
48
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
49
|
-
userId,
|
|
50
|
-
recordPublicKey: record.publicKey,
|
|
51
|
-
presentedPublicKey: next.publicKey,
|
|
52
|
-
outcomes: [confirm({ publicKey: next.publicKey, issuedAt, reason: "lost" })],
|
|
53
|
-
});
|
|
54
|
-
expect(resolution.state).toBe("confirmed-recovery");
|
|
55
|
-
});
|
|
56
|
-
it("vetoes when any anchor omits the presented key", () => {
|
|
57
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
58
|
-
userId,
|
|
59
|
-
recordPublicKey: record.publicKey,
|
|
60
|
-
presentedPublicKey: next.publicKey,
|
|
61
|
-
outcomes: [
|
|
62
|
-
confirm({ publicKey: next.publicKey, issuedAt }),
|
|
63
|
-
confirm({ publicKey: record.publicKey, issuedAt }),
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
|
-
expect(resolution.state).toBe("vetoed");
|
|
67
|
-
});
|
|
68
|
-
it("vetoes a document for another user and a 404", () => {
|
|
69
|
-
const other = document([{ publicKey: next.publicKey, issuedAt }]);
|
|
70
|
-
other.userId = (0, index_1.newid)();
|
|
71
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
72
|
-
userId,
|
|
73
|
-
recordPublicKey: record.publicKey,
|
|
74
|
-
presentedPublicKey: next.publicKey,
|
|
75
|
-
outcomes: [{ outcome: "document", document: other }, { outcome: "veto" }],
|
|
76
|
-
});
|
|
77
|
-
expect(resolution.state).toBe("vetoed");
|
|
78
|
-
});
|
|
79
|
-
it("stays pending when every anchor abstains", () => {
|
|
80
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
81
|
-
userId,
|
|
82
|
-
recordPublicKey: record.publicKey,
|
|
83
|
-
presentedPublicKey: next.publicKey,
|
|
84
|
-
outcomes: [{ outcome: "abstain" }, { outcome: "abstain" }],
|
|
85
|
-
});
|
|
86
|
-
expect(resolution.state).toBe("pending");
|
|
87
|
-
});
|
|
88
|
-
it("rejects a co-signature that is not the key on record", () => {
|
|
89
|
-
const imposter = (0, index_1.newKeys)();
|
|
90
|
-
const signed = (0, anchor_document_1.signSuccession)({ purpose: "peers-key-succession", userId, publicKey: next.publicKey, issuedAt }, imposter.secretKey);
|
|
91
|
-
const resolution = (0, anchor_resolution_1.resolvePresentedKey)({
|
|
92
|
-
userId,
|
|
93
|
-
recordPublicKey: record.publicKey,
|
|
94
|
-
presentedPublicKey: next.publicKey,
|
|
95
|
-
outcomes: [
|
|
96
|
-
confirm({
|
|
97
|
-
publicKey: next.publicKey,
|
|
98
|
-
issuedAt,
|
|
99
|
-
authorizedBy: { publicKey: signed.publicKey, signature: signed.signature },
|
|
100
|
-
}),
|
|
101
|
-
],
|
|
102
|
-
});
|
|
103
|
-
expect(resolution.state).toBe("confirmed-recovery");
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe("resolvePresentedAnchors", () => {
|
|
107
|
-
const next = [anchor, { type: "https", url: "https://example.com/other.json" }];
|
|
108
|
-
it("confirms when an anchor publishes the new list and none veto", () => {
|
|
109
|
-
const decision = (0, anchor_resolution_1.resolvePresentedAnchors)({
|
|
110
|
-
userId,
|
|
111
|
-
presented: next,
|
|
112
|
-
outcomes: [
|
|
113
|
-
{ outcome: "document", document: { ...document([]), anchors: [...next].reverse() } },
|
|
114
|
-
{ outcome: "abstain" },
|
|
115
|
-
],
|
|
116
|
-
});
|
|
117
|
-
expect(decision).toBe("confirmed");
|
|
118
|
-
});
|
|
119
|
-
it("vetoes when an anchor still publishes a different list", () => {
|
|
120
|
-
const decision = (0, anchor_resolution_1.resolvePresentedAnchors)({
|
|
121
|
-
userId,
|
|
122
|
-
presented: next,
|
|
123
|
-
outcomes: [
|
|
124
|
-
{ outcome: "document", document: document([]) },
|
|
125
|
-
{ outcome: "document", document: { ...document([]), anchors: next } },
|
|
126
|
-
],
|
|
127
|
-
});
|
|
128
|
-
expect(decision).toBe("vetoed");
|
|
129
|
-
});
|
|
130
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./user-row-change";
|