@serve.zone/witness 0.0.0-stage → 1.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.
- package/.smartconfig.json +72 -0
- package/changelog.md +13 -0
- package/cli.js +4 -0
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/classes.models.d.ts +60 -0
- package/dist_ts/classes.models.js +158 -0
- package/dist_ts/classes.refusal.d.ts +16 -0
- package/dist_ts/classes.refusal.js +21 -0
- package/dist_ts/classes.register.d.ts +70 -0
- package/dist_ts/classes.register.js +306 -0
- package/dist_ts/classes.server.d.ts +38 -0
- package/dist_ts/classes.server.js +86 -0
- package/dist_ts/classes.storage.d.ts +45 -0
- package/dist_ts/classes.storage.js +110 -0
- package/dist_ts/classes.witness.d.ts +29 -0
- package/dist_ts/classes.witness.js +82 -0
- package/dist_ts/index.d.ts +7 -0
- package/dist_ts/index.js +8 -0
- package/dist_ts/plugins.d.ts +13 -0
- package/dist_ts/plugins.js +19 -0
- package/dist_ts/witness.cli.d.ts +16 -0
- package/dist_ts/witness.cli.js +145 -0
- package/dist_ts/witness.config.d.ts +41 -0
- package/dist_ts/witness.config.js +71 -0
- package/dist_ts/witness.enroll.d.ts +26 -0
- package/dist_ts/witness.enroll.js +74 -0
- package/dist_ts/witness.log.d.ts +28 -0
- package/dist_ts/witness.log.js +34 -0
- package/license.md +21 -0
- package/package.json +45 -3
- package/readme.md +96 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/classes.models.ts +100 -0
- package/ts/classes.refusal.ts +28 -0
- package/ts/classes.register.ts +389 -0
- package/ts/classes.server.ts +129 -0
- package/ts/classes.storage.ts +123 -0
- package/ts/classes.witness.ts +99 -0
- package/ts/index.ts +23 -0
- package/ts/plugins.ts +38 -0
- package/ts/witness.cli.ts +168 -0
- package/ts/witness.config.ts +107 -0
- package/ts/witness.enroll.ts +113 -0
- package/ts/witness.log.ts +58 -0
- package/README.md +0 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@git.zone/tsrepo": {
|
|
3
|
+
"bundle": {
|
|
4
|
+
"bundles": [
|
|
5
|
+
{
|
|
6
|
+
"from": "./binary/witness.ts",
|
|
7
|
+
"to": "./dist/sea/witness.mjs",
|
|
8
|
+
"bundler": "esbuild",
|
|
9
|
+
"platform": "node",
|
|
10
|
+
"sea": true,
|
|
11
|
+
"production": true
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"sea": {
|
|
16
|
+
"nodeVersion": "26.11.1",
|
|
17
|
+
"bundle": "./dist/sea/witness.mjs",
|
|
18
|
+
"outDir": "./dist/binaries",
|
|
19
|
+
"targets": [
|
|
20
|
+
{
|
|
21
|
+
"target": "linux-x64",
|
|
22
|
+
"name": "witness-linux-x64"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"target": "linux-arm64",
|
|
26
|
+
"name": "witness-linux-arm64"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"smoke": {
|
|
30
|
+
"args": ["--version"],
|
|
31
|
+
"expectExitCode": 0,
|
|
32
|
+
"expectStdoutPattern": "(?:^|\\n)\\d+\\.\\d+\\.\\d+(?:\\n|$)",
|
|
33
|
+
"timeoutMs": 30000,
|
|
34
|
+
"cleanEnv": true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"@git.zone/cli": {
|
|
39
|
+
"schemaVersion": 2,
|
|
40
|
+
"projectType": "npm",
|
|
41
|
+
"module": {
|
|
42
|
+
"githost": "code.foss.global",
|
|
43
|
+
"gitscope": "serve.zone",
|
|
44
|
+
"gitrepo": "witness",
|
|
45
|
+
"description": "the serve.zone witness: a compare-and-set register that decides which site's controller is active",
|
|
46
|
+
"npmPackagename": "@serve.zone/witness",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"projectDomain": "serve.zone"
|
|
49
|
+
},
|
|
50
|
+
"release": {
|
|
51
|
+
"preflight": {
|
|
52
|
+
"build": true,
|
|
53
|
+
"test": true
|
|
54
|
+
},
|
|
55
|
+
"targets": {
|
|
56
|
+
"git": {
|
|
57
|
+
"enabled": true,
|
|
58
|
+
"remote": "origin"
|
|
59
|
+
},
|
|
60
|
+
"npm": {
|
|
61
|
+
"enabled": true,
|
|
62
|
+
"registries": [
|
|
63
|
+
"https://verdaccio.lossless.digital",
|
|
64
|
+
"https://registry.npmjs.org"
|
|
65
|
+
],
|
|
66
|
+
"accessLevel": "public",
|
|
67
|
+
"alreadyPublished": "success"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/changelog.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 2026-11-27 - 1.2.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Add single-use managed host enrollment (`witness enroll`, `ts/witness.enroll.ts`) redeeming Cloudly's `claimManagedHostEnrollment` grant with `0600` TLS key persistence, `--version` CLI flag, and Node.js SEA packaging targets (`witness-linux-x64`, `witness-linux-arm64`).
|
|
8
|
+
|
|
9
|
+
## 2026-11-12 - 1.1.0
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- The witness service (AGL-1195, Linus rulings 69 Q5, Q6 and 73): one compare-and-set record per controller, serving the `@serve.zone/interfaces` 32.81.0 witness contract (`pairWitnessController`, `enrollWitnessMember`, `getWitnessRecord`, `compareAndSetWitnessRecord`, `getWitnessHealth`) with TypedRequest over HTTPS through `@api.global/typedserver` 16, in the contract's gate order. Storage is a `LocalNoSqlDb` (`@lossless.org/nosqldb` 11) embedded in the process with `@lossless.org/client/nosqldb` models: every change is an `atomicFindOneAndUpdate` on `{controllerId, revision}` answered after the durable acknowledgement, and pairing consumes the code and creates the record in one transaction. Members are known by `bearerSha256` only, compared in constant time; an unknown controller, a non-member and a bad bearer answer one `credential-invalid`, and the log keeps which. The `witness` CLI runs `serve` and makes one-time pairing codes (`pairing-code --controller <id>`), stored as hashes and living minutes.
|
package/cli.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
3
|
+
*/
|
|
4
|
+
export const commitinfo = {
|
|
5
|
+
name: '@serve.zone/witness',
|
|
6
|
+
version: '1.2.0',
|
|
7
|
+
description: 'the serve.zone witness: a compare-and-set register that decides which site\'s controller is active'
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxxQkFBcUI7SUFDM0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLG9HQUFvRztDQUNsSCxDQUFBIn0=
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
/**
|
|
3
|
+
* How a member authenticates: the SHA-256 of the bearer that site created for itself, as 64
|
|
4
|
+
* lowercase hex characters. The witness never holds the bearer.
|
|
5
|
+
*/
|
|
6
|
+
export interface IWitnessMemberHash {
|
|
7
|
+
/** The member's site origin. */
|
|
8
|
+
origin: string;
|
|
9
|
+
bearerSha256: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The stored witness record of one controller: the contract's `IWitnessRecord` without
|
|
13
|
+
* `memberOrigins`, which is derived from `members`, so the members and their hashes cannot disagree.
|
|
14
|
+
*/
|
|
15
|
+
export interface IWitnessRecordDocument {
|
|
16
|
+
controllerId: string;
|
|
17
|
+
epoch: number;
|
|
18
|
+
activeOrigin: string;
|
|
19
|
+
inSyncStandbyOrigin: string | null;
|
|
20
|
+
revision: number;
|
|
21
|
+
/** Every member, ordered by origin as `IWitnessRecord.memberOrigins` is. */
|
|
22
|
+
members: IWitnessMemberHash[];
|
|
23
|
+
}
|
|
24
|
+
/** A one-time pairing code, stored as its hash only. */
|
|
25
|
+
export interface IWitnessPairingCodeDocument {
|
|
26
|
+
/** SHA-256 of the code's UTF-8, 64 lowercase hex characters. */
|
|
27
|
+
codeSha256: string;
|
|
28
|
+
/** The one controller id the code pairs. */
|
|
29
|
+
controllerId: string;
|
|
30
|
+
/** Witness clock, milliseconds since the epoch. */
|
|
31
|
+
issuedAt: number;
|
|
32
|
+
/** The code is refused `pairing-code-expired` from this witness-clock time on. */
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
/** When the code was redeemed, or `null` while it is unused. */
|
|
35
|
+
consumedAt: number | null;
|
|
36
|
+
}
|
|
37
|
+
export declare class WitnessRecordDoc extends plugins.smartdata.SmartDataDbDoc<WitnessRecordDoc, IWitnessRecordDocument> implements IWitnessRecordDocument {
|
|
38
|
+
controllerId: string;
|
|
39
|
+
epoch: number;
|
|
40
|
+
activeOrigin: string;
|
|
41
|
+
inSyncStandbyOrigin: string | null;
|
|
42
|
+
revision: number;
|
|
43
|
+
members: IWitnessMemberHash[];
|
|
44
|
+
}
|
|
45
|
+
export declare class WitnessPairingCodeDoc extends plugins.smartdata.SmartDataDbDoc<WitnessPairingCodeDoc, IWitnessPairingCodeDocument> implements IWitnessPairingCodeDocument {
|
|
46
|
+
codeSha256: string;
|
|
47
|
+
controllerId: string;
|
|
48
|
+
issuedAt: number;
|
|
49
|
+
expiresAt: number;
|
|
50
|
+
consumedAt: number | null;
|
|
51
|
+
}
|
|
52
|
+
/** The witness models, bound to one database. */
|
|
53
|
+
export interface IWitnessModels {
|
|
54
|
+
Record: typeof WitnessRecordDoc;
|
|
55
|
+
PairingCode: typeof WitnessPairingCodeDoc;
|
|
56
|
+
}
|
|
57
|
+
/** Binds the models to `dbArg`, so several witnesses (a restart in a test) use their own database. */
|
|
58
|
+
export declare const bindWitnessModels: (dbArg: plugins.smartdata.SmartdataDb) => IWitnessModels;
|
|
59
|
+
/** Every witness model, for preparation at start. */
|
|
60
|
+
export declare const listWitnessModels: (modelsArg: IWitnessModels) => readonly [typeof WitnessRecordDoc, typeof WitnessPairingCodeDoc];
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import * as plugins from './plugins.js';
|
|
36
|
+
let WitnessRecordDoc = (() => {
|
|
37
|
+
let _classDecorators = [plugins.smartdata.managed({ collectionName: 'witnessrecords' })];
|
|
38
|
+
let _classDescriptor;
|
|
39
|
+
let _classExtraInitializers = [];
|
|
40
|
+
let _classThis;
|
|
41
|
+
let _classSuper = plugins.smartdata.SmartDataDbDoc;
|
|
42
|
+
let _controllerId_decorators;
|
|
43
|
+
let _controllerId_initializers = [];
|
|
44
|
+
let _controllerId_extraInitializers = [];
|
|
45
|
+
let _epoch_decorators;
|
|
46
|
+
let _epoch_initializers = [];
|
|
47
|
+
let _epoch_extraInitializers = [];
|
|
48
|
+
let _activeOrigin_decorators;
|
|
49
|
+
let _activeOrigin_initializers = [];
|
|
50
|
+
let _activeOrigin_extraInitializers = [];
|
|
51
|
+
let _inSyncStandbyOrigin_decorators;
|
|
52
|
+
let _inSyncStandbyOrigin_initializers = [];
|
|
53
|
+
let _inSyncStandbyOrigin_extraInitializers = [];
|
|
54
|
+
let _revision_decorators;
|
|
55
|
+
let _revision_initializers = [];
|
|
56
|
+
let _revision_extraInitializers = [];
|
|
57
|
+
let _members_decorators;
|
|
58
|
+
let _members_initializers = [];
|
|
59
|
+
let _members_extraInitializers = [];
|
|
60
|
+
var WitnessRecordDoc = class extends _classSuper {
|
|
61
|
+
static { _classThis = this; }
|
|
62
|
+
static {
|
|
63
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
64
|
+
_controllerId_decorators = [plugins.smartdata.unI()];
|
|
65
|
+
_epoch_decorators = [plugins.smartdata.svDb()];
|
|
66
|
+
_activeOrigin_decorators = [plugins.smartdata.svDb()];
|
|
67
|
+
_inSyncStandbyOrigin_decorators = [plugins.smartdata.svDb()];
|
|
68
|
+
_revision_decorators = [plugins.smartdata.svDb()];
|
|
69
|
+
_members_decorators = [plugins.smartdata.svDb()];
|
|
70
|
+
__esDecorate(null, null, _controllerId_decorators, { kind: "field", name: "controllerId", static: false, private: false, access: { has: obj => "controllerId" in obj, get: obj => obj.controllerId, set: (obj, value) => { obj.controllerId = value; } }, metadata: _metadata }, _controllerId_initializers, _controllerId_extraInitializers);
|
|
71
|
+
__esDecorate(null, null, _epoch_decorators, { kind: "field", name: "epoch", static: false, private: false, access: { has: obj => "epoch" in obj, get: obj => obj.epoch, set: (obj, value) => { obj.epoch = value; } }, metadata: _metadata }, _epoch_initializers, _epoch_extraInitializers);
|
|
72
|
+
__esDecorate(null, null, _activeOrigin_decorators, { kind: "field", name: "activeOrigin", static: false, private: false, access: { has: obj => "activeOrigin" in obj, get: obj => obj.activeOrigin, set: (obj, value) => { obj.activeOrigin = value; } }, metadata: _metadata }, _activeOrigin_initializers, _activeOrigin_extraInitializers);
|
|
73
|
+
__esDecorate(null, null, _inSyncStandbyOrigin_decorators, { kind: "field", name: "inSyncStandbyOrigin", static: false, private: false, access: { has: obj => "inSyncStandbyOrigin" in obj, get: obj => obj.inSyncStandbyOrigin, set: (obj, value) => { obj.inSyncStandbyOrigin = value; } }, metadata: _metadata }, _inSyncStandbyOrigin_initializers, _inSyncStandbyOrigin_extraInitializers);
|
|
74
|
+
__esDecorate(null, null, _revision_decorators, { kind: "field", name: "revision", static: false, private: false, access: { has: obj => "revision" in obj, get: obj => obj.revision, set: (obj, value) => { obj.revision = value; } }, metadata: _metadata }, _revision_initializers, _revision_extraInitializers);
|
|
75
|
+
__esDecorate(null, null, _members_decorators, { kind: "field", name: "members", static: false, private: false, access: { has: obj => "members" in obj, get: obj => obj.members, set: (obj, value) => { obj.members = value; } }, metadata: _metadata }, _members_initializers, _members_extraInitializers);
|
|
76
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
77
|
+
WitnessRecordDoc = _classThis = _classDescriptor.value;
|
|
78
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
79
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
80
|
+
}
|
|
81
|
+
controllerId = __runInitializers(this, _controllerId_initializers, void 0);
|
|
82
|
+
epoch = (__runInitializers(this, _controllerId_extraInitializers), __runInitializers(this, _epoch_initializers, void 0));
|
|
83
|
+
activeOrigin = (__runInitializers(this, _epoch_extraInitializers), __runInitializers(this, _activeOrigin_initializers, void 0));
|
|
84
|
+
inSyncStandbyOrigin = (__runInitializers(this, _activeOrigin_extraInitializers), __runInitializers(this, _inSyncStandbyOrigin_initializers, void 0));
|
|
85
|
+
revision = (__runInitializers(this, _inSyncStandbyOrigin_extraInitializers), __runInitializers(this, _revision_initializers, void 0));
|
|
86
|
+
members = (__runInitializers(this, _revision_extraInitializers), __runInitializers(this, _members_initializers, void 0));
|
|
87
|
+
constructor() {
|
|
88
|
+
super(...arguments);
|
|
89
|
+
__runInitializers(this, _members_extraInitializers);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return WitnessRecordDoc = _classThis;
|
|
93
|
+
})();
|
|
94
|
+
export { WitnessRecordDoc };
|
|
95
|
+
let WitnessPairingCodeDoc = (() => {
|
|
96
|
+
let _classDecorators = [plugins.smartdata.managed({ collectionName: 'witnesspairingcodes' })];
|
|
97
|
+
let _classDescriptor;
|
|
98
|
+
let _classExtraInitializers = [];
|
|
99
|
+
let _classThis;
|
|
100
|
+
let _classSuper = plugins.smartdata.SmartDataDbDoc;
|
|
101
|
+
let _codeSha256_decorators;
|
|
102
|
+
let _codeSha256_initializers = [];
|
|
103
|
+
let _codeSha256_extraInitializers = [];
|
|
104
|
+
let _controllerId_decorators;
|
|
105
|
+
let _controllerId_initializers = [];
|
|
106
|
+
let _controllerId_extraInitializers = [];
|
|
107
|
+
let _issuedAt_decorators;
|
|
108
|
+
let _issuedAt_initializers = [];
|
|
109
|
+
let _issuedAt_extraInitializers = [];
|
|
110
|
+
let _expiresAt_decorators;
|
|
111
|
+
let _expiresAt_initializers = [];
|
|
112
|
+
let _expiresAt_extraInitializers = [];
|
|
113
|
+
let _consumedAt_decorators;
|
|
114
|
+
let _consumedAt_initializers = [];
|
|
115
|
+
let _consumedAt_extraInitializers = [];
|
|
116
|
+
var WitnessPairingCodeDoc = class extends _classSuper {
|
|
117
|
+
static { _classThis = this; }
|
|
118
|
+
static {
|
|
119
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
120
|
+
_codeSha256_decorators = [plugins.smartdata.unI()];
|
|
121
|
+
_controllerId_decorators = [plugins.smartdata.svDb()];
|
|
122
|
+
_issuedAt_decorators = [plugins.smartdata.svDb()];
|
|
123
|
+
_expiresAt_decorators = [plugins.smartdata.svDb()];
|
|
124
|
+
_consumedAt_decorators = [plugins.smartdata.svDb()];
|
|
125
|
+
__esDecorate(null, null, _codeSha256_decorators, { kind: "field", name: "codeSha256", static: false, private: false, access: { has: obj => "codeSha256" in obj, get: obj => obj.codeSha256, set: (obj, value) => { obj.codeSha256 = value; } }, metadata: _metadata }, _codeSha256_initializers, _codeSha256_extraInitializers);
|
|
126
|
+
__esDecorate(null, null, _controllerId_decorators, { kind: "field", name: "controllerId", static: false, private: false, access: { has: obj => "controllerId" in obj, get: obj => obj.controllerId, set: (obj, value) => { obj.controllerId = value; } }, metadata: _metadata }, _controllerId_initializers, _controllerId_extraInitializers);
|
|
127
|
+
__esDecorate(null, null, _issuedAt_decorators, { kind: "field", name: "issuedAt", static: false, private: false, access: { has: obj => "issuedAt" in obj, get: obj => obj.issuedAt, set: (obj, value) => { obj.issuedAt = value; } }, metadata: _metadata }, _issuedAt_initializers, _issuedAt_extraInitializers);
|
|
128
|
+
__esDecorate(null, null, _expiresAt_decorators, { kind: "field", name: "expiresAt", static: false, private: false, access: { has: obj => "expiresAt" in obj, get: obj => obj.expiresAt, set: (obj, value) => { obj.expiresAt = value; } }, metadata: _metadata }, _expiresAt_initializers, _expiresAt_extraInitializers);
|
|
129
|
+
__esDecorate(null, null, _consumedAt_decorators, { kind: "field", name: "consumedAt", static: false, private: false, access: { has: obj => "consumedAt" in obj, get: obj => obj.consumedAt, set: (obj, value) => { obj.consumedAt = value; } }, metadata: _metadata }, _consumedAt_initializers, _consumedAt_extraInitializers);
|
|
130
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
131
|
+
WitnessPairingCodeDoc = _classThis = _classDescriptor.value;
|
|
132
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
133
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
134
|
+
}
|
|
135
|
+
codeSha256 = __runInitializers(this, _codeSha256_initializers, void 0);
|
|
136
|
+
controllerId = (__runInitializers(this, _codeSha256_extraInitializers), __runInitializers(this, _controllerId_initializers, void 0));
|
|
137
|
+
issuedAt = (__runInitializers(this, _controllerId_extraInitializers), __runInitializers(this, _issuedAt_initializers, void 0));
|
|
138
|
+
expiresAt = (__runInitializers(this, _issuedAt_extraInitializers), __runInitializers(this, _expiresAt_initializers, void 0));
|
|
139
|
+
consumedAt = (__runInitializers(this, _expiresAt_extraInitializers), __runInitializers(this, _consumedAt_initializers, void 0));
|
|
140
|
+
constructor() {
|
|
141
|
+
super(...arguments);
|
|
142
|
+
__runInitializers(this, _consumedAt_extraInitializers);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return WitnessPairingCodeDoc = _classThis;
|
|
146
|
+
})();
|
|
147
|
+
export { WitnessPairingCodeDoc };
|
|
148
|
+
/** Binds the models to `dbArg`, so several witnesses (a restart in a test) use their own database. */
|
|
149
|
+
export const bindWitnessModels = (dbArg) => {
|
|
150
|
+
const manager = { db: dbArg };
|
|
151
|
+
return {
|
|
152
|
+
Record: plugins.smartdata.bindDocToManager(manager, WitnessRecordDoc),
|
|
153
|
+
PairingCode: plugins.smartdata.bindDocToManager(manager, WitnessPairingCodeDoc),
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/** Every witness model, for preparation at start. */
|
|
157
|
+
export const listWitnessModels = (modelsArg) => [modelsArg.Record, modelsArg.PairingCode];
|
|
158
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5tb2RlbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jbGFzc2VzLm1vZGVscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxjQUFjLENBQUM7SUF5QzNCLGdCQUFnQjs0QkFENUIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsRUFBRSxjQUFjLEVBQUUsZ0JBQWdCLEVBQUUsQ0FBQzs7OztzQkFFdEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxjQUFjOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O2dDQUF4QyxTQUFRLFdBQTBFOzs7O3dDQUVqRixPQUFPLENBQUMs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LENBQUMsU0FBeUIsRUFBRSxFQUFFLENBQUMsQ0FBQyxTQUFTLENBQUMsTUFBTSxFQUFFLFNBQVMsQ0FBQyxXQUFXLENBQVUsQ0FBQyJ9
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type { TWitnessLogValue } from './witness.log.js';
|
|
3
|
+
type TWitnessRefusal = plugins.servezoneInterfaces.data.TWitnessRefusal;
|
|
4
|
+
/**
|
|
5
|
+
* A witness refusal on its way to the caller. The message is the wire text: the code and a detail
|
|
6
|
+
* that never carries a bearer or a pairing code. `logFields` stay in the witness log; they name what
|
|
7
|
+
* the caller must not learn, such as which case of `credential-invalid` it was (ruling 73 Q8).
|
|
8
|
+
*/
|
|
9
|
+
export declare class WitnessRefusalError extends Error {
|
|
10
|
+
readonly code: TWitnessRefusal;
|
|
11
|
+
readonly logFields: Readonly<Record<string, TWitnessLogValue>>;
|
|
12
|
+
constructor(code: TWitnessRefusal, detailArg: string, logFields?: Readonly<Record<string, TWitnessLogValue>>);
|
|
13
|
+
/** The refusal as the contract answers it: a `TypedResponseError` with `IWitnessRefusalErrorData`. */
|
|
14
|
+
toTypedResponseError(): plugins.typedrequest.TypedResponseError;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
/**
|
|
3
|
+
* A witness refusal on its way to the caller. The message is the wire text: the code and a detail
|
|
4
|
+
* that never carries a bearer or a pairing code. `logFields` stay in the witness log; they name what
|
|
5
|
+
* the caller must not learn, such as which case of `credential-invalid` it was (ruling 73 Q8).
|
|
6
|
+
*/
|
|
7
|
+
export class WitnessRefusalError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
logFields;
|
|
10
|
+
constructor(code, detailArg, logFields = {}) {
|
|
11
|
+
super(`${code}: ${detailArg}`);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.logFields = logFields;
|
|
14
|
+
this.name = 'WitnessRefusalError';
|
|
15
|
+
}
|
|
16
|
+
/** The refusal as the contract answers it: a `TypedResponseError` with `IWitnessRefusalErrorData`. */
|
|
17
|
+
toTypedResponseError() {
|
|
18
|
+
return new plugins.typedrequest.TypedResponseError(this.message, plugins.servezoneInterfaces.data.createWitnessRefusalErrorData(this.code));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5yZWZ1c2FsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2xhc3Nlcy5yZWZ1c2FsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sY0FBYyxDQUFDO0FBS3hDOzs7O0dBSUc7QUFDSCxNQUFNLE9BQU8sbUJBQW9CLFNBQVEsS0FBSztJQUUxQixJQUFJO0lBRUosU0FBUztJQUgzQixZQUNrQixJQUFxQixFQUNyQyxTQUFpQixFQUNELFNBQVMsR0FBK0MsRUFBRTtRQUUxRSxLQUFLLENBQUMsR0FBRyxJQUFJLEtBQUssU0FBUyxFQUFFLENBQUMsQ0FBQztvQkFKZixJQUFJO3lCQUVKLFNBQVM7UUFHekIsSUFBSSxDQUFDLElBQUksR0FBRyxxQkFBcUIsQ0FBQztJQUNwQyxDQUFDO0lBRUQsc0dBQXNHO0lBQy9GLG9CQUFvQjtRQUN6QixPQUFPLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxrQkFBa0IsQ0FDaEQsSUFBSSxDQUFDLE9BQU8sRUFDWixPQUFPLENBQUMsbUJBQW1CLENBQUMsSUFBSSxDQUFDLDZCQUE2QixDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FDMUUsQ0FBQztJQUNKLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type { WitnessStorage } from './classes.storage.js';
|
|
3
|
+
import { WitnessLog } from './witness.log.js';
|
|
4
|
+
type IWitnessRecord = plugins.servezoneInterfaces.data.IWitnessRecord;
|
|
5
|
+
type IWitnessHealth = plugins.servezoneInterfaces.data.IWitnessHealth;
|
|
6
|
+
/** How long a pairing code lives: minutes (ruling 73). */
|
|
7
|
+
export declare const witnessPairingCodeLifetime: Readonly<{
|
|
8
|
+
readonly defaultMinutes: 10;
|
|
9
|
+
readonly maximumMinutes: 60;
|
|
10
|
+
}>;
|
|
11
|
+
/** A pairing code as the operator receives it, once. */
|
|
12
|
+
export interface IWitnessIssuedPairingCode {
|
|
13
|
+
controllerId: string;
|
|
14
|
+
/** Base64url of 32 random bytes. The witness keeps only its SHA-256. */
|
|
15
|
+
pairingCode: string;
|
|
16
|
+
/** ISO time from which the code is refused `pairing-code-expired`. */
|
|
17
|
+
expiresAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IWitnessRegisterOptions {
|
|
20
|
+
storage: WitnessStorage;
|
|
21
|
+
log: WitnessLog;
|
|
22
|
+
/** Witness clock in milliseconds since the epoch; pairing codes expire against it. */
|
|
23
|
+
clock: () => number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The witness's register: the five contract requests over the stored records, each answered after
|
|
27
|
+
* its gates in the contract's order (`request-invalid`, then the pairing code or the authentication,
|
|
28
|
+
* then `revision-stale`, then the judge's first refusal) and, for a change, after a durable
|
|
29
|
+
* compare-and-set on `{controllerId, revision}`.
|
|
30
|
+
*/
|
|
31
|
+
export declare class WitnessRegister {
|
|
32
|
+
private readonly options;
|
|
33
|
+
constructor(options: IWitnessRegisterOptions);
|
|
34
|
+
private get models();
|
|
35
|
+
/**
|
|
36
|
+
* Makes a one-time pairing code for one controller id: the operator's step on the witness host.
|
|
37
|
+
* The code is answered once and stored only as its SHA-256.
|
|
38
|
+
*/
|
|
39
|
+
issuePairingCode(controllerIdArg: string, lifetimeMinutesArg?: number): Promise<IWitnessIssuedPairingCode>;
|
|
40
|
+
/**
|
|
41
|
+
* `pairWitnessController`: consumes the code and creates the record in one transaction, so a
|
|
42
|
+
* caller whose answer was lost finds the record with its own bearer exactly when the code was
|
|
43
|
+
* consumed.
|
|
44
|
+
*/
|
|
45
|
+
pairWitnessController(requestArg: unknown): Promise<IWitnessRecord>;
|
|
46
|
+
/** `getWitnessRecord`: the record, for a member. */
|
|
47
|
+
getWitnessRecord(requestArg: unknown): Promise<IWitnessRecord>;
|
|
48
|
+
/** `enrollWitnessMember`: the active adds a member or replaces a member's bearer hash. */
|
|
49
|
+
enrollWitnessMember(requestArg: unknown): Promise<IWitnessRecord>;
|
|
50
|
+
/** `compareAndSetWitnessRecord`: a member changes the state, as `judgeWitnessChange` admits. */
|
|
51
|
+
compareAndSetWitnessRecord(requestArg: unknown): Promise<IWitnessRecord>;
|
|
52
|
+
/** `getWitnessHealth`: unauthenticated, names no controller. */
|
|
53
|
+
getWitnessHealth(): Promise<IWitnessHealth>;
|
|
54
|
+
/**
|
|
55
|
+
* The authentication gate. An unknown controller, a non-member and a bad bearer answer the same
|
|
56
|
+
* `credential-invalid` with the same text; the log keeps which it was (ruling 73 Q8). The bearer
|
|
57
|
+
* is compared by its SHA-256 in constant time (ruling 73 Q5).
|
|
58
|
+
*/
|
|
59
|
+
private authenticate;
|
|
60
|
+
private requireRevision;
|
|
61
|
+
/**
|
|
62
|
+
* The compare-and-set (ruling 73 Q4): `atomicFindOneAndUpdate` filtered on
|
|
63
|
+
* `{controllerId, revision}`, raising the revision by one. Every change raises the revision, so of
|
|
64
|
+
* two changes naming one revision at most one is stored. Its answer arrives after NoSQLDB
|
|
65
|
+
* acknowledged the write, which file storage does only once the write is durable.
|
|
66
|
+
*/
|
|
67
|
+
private commitChange;
|
|
68
|
+
private storageFailure;
|
|
69
|
+
}
|
|
70
|
+
export {};
|