@noy-db/hub 0.2.0-pre.1 → 0.2.0-pre.2
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/aggregate/index.cjs.map +1 -1
- package/dist/aggregate/index.js +2 -2
- package/dist/attestation/index.cjs +305 -0
- package/dist/attestation/index.cjs.map +1 -0
- package/dist/attestation/index.d.cts +52 -0
- package/dist/attestation/index.d.ts +52 -0
- package/dist/attestation/index.js +36 -0
- package/dist/attestation/index.js.map +1 -0
- package/dist/blobs/index.cjs.map +1 -1
- package/dist/blobs/index.d.cts +4 -3
- package/dist/blobs/index.d.ts +4 -3
- package/dist/blobs/index.js +9 -7
- package/dist/blobs/index.js.map +1 -1
- package/dist/bundle/index.cjs +16701 -129
- package/dist/bundle/index.cjs.map +1 -1
- package/dist/bundle/index.d.cts +172 -3
- package/dist/bundle/index.d.ts +172 -3
- package/dist/bundle/index.js +533 -5
- package/dist/bundle/index.js.map +1 -1
- package/dist/{chunk-5SCJ5UEF.js → chunk-243PNUA6.js} +2 -2
- package/dist/{chunk-WCA2NROQ.js → chunk-2PAQNPE3.js} +2 -2
- package/dist/chunk-3QAKZ37R.js +83 -0
- package/dist/chunk-3QAKZ37R.js.map +1 -0
- package/dist/chunk-3S4BJX25.js +36 -0
- package/dist/chunk-3S4BJX25.js.map +1 -0
- package/dist/chunk-3XHOCQK4.js +118 -0
- package/dist/chunk-3XHOCQK4.js.map +1 -0
- package/dist/{chunk-4TFSM22V.js → chunk-3Y53S2SA.js} +3 -3
- package/dist/{chunk-6HPZY4ON.js → chunk-3Z2TPHC4.js} +3 -3
- package/dist/chunk-4HIL6AHQ.js +57 -0
- package/dist/chunk-4HIL6AHQ.js.map +1 -0
- package/dist/{chunk-DYECX3IX.js → chunk-7BRE6EUA.js} +2 -2
- package/dist/{chunk-DYBQG5PQ.js → chunk-7BUTTVMR.js} +2 -2
- package/dist/{chunk-KESP7GOK.js → chunk-7Q5PLD5C.js} +3 -3
- package/dist/{chunk-UA4RI7OT.js → chunk-7Z23ZFLV.js} +4 -4
- package/dist/chunk-AHPFONIL.js +59 -0
- package/dist/chunk-AHPFONIL.js.map +1 -0
- package/dist/{chunk-EGQYGYIU.js → chunk-CXSCDO5T.js} +2 -2
- package/dist/chunk-E535SAN4.js +8834 -0
- package/dist/chunk-E535SAN4.js.map +1 -0
- package/dist/{chunk-CBAHB2BF.js → chunk-EUYOGYGV.js} +6 -69
- package/dist/chunk-EUYOGYGV.js.map +1 -0
- package/dist/{chunk-OMLIZL2P.js → chunk-FAQVNJD4.js} +2 -2
- package/dist/{chunk-I6MX32UC.js → chunk-G6FRSBKK.js} +4 -4
- package/dist/{chunk-FCXOFQAJ.js → chunk-GIV6DWBG.js} +2 -2
- package/dist/{chunk-34YSDCDP.js → chunk-HXJXPZRE.js} +2 -2
- package/dist/{chunk-23TTQXVO.js → chunk-J4KLMEUL.js} +2 -2
- package/dist/{chunk-VMIO4IXG.js → chunk-JYQTXEIO.js} +5 -228
- package/dist/chunk-JYQTXEIO.js.map +1 -0
- package/dist/{chunk-NIOHFJPJ.js → chunk-LRAZDV5X.js} +6 -118
- package/dist/chunk-LRAZDV5X.js.map +1 -0
- package/dist/{chunk-P7EQ2S5O.js → chunk-MUWOSVEP.js} +2 -2
- package/dist/chunk-NWZ3I6R6.js +79 -0
- package/dist/chunk-NWZ3I6R6.js.map +1 -0
- package/dist/{chunk-HB3Z2GCR.js → chunk-OVZDFEOR.js} +2 -2
- package/dist/chunk-PFSNOPBQ.js +233 -0
- package/dist/chunk-PFSNOPBQ.js.map +1 -0
- package/dist/{chunk-UZXLQCHP.js → chunk-PLI5TV7N.js} +2 -2
- package/dist/{chunk-PA6R5ZCI.js → chunk-Q6W2CMEJ.js} +3 -3
- package/dist/{chunk-537VFZTR.js → chunk-QPEXPHJR.js} +4 -4
- package/dist/{chunk-ZNOEIM6Y.js → chunk-QXQRKXCU.js} +2 -2
- package/dist/{chunk-RD5LYKD6.js → chunk-RTZVQAJ7.js} +2 -2
- package/dist/{chunk-DPMFBCV6.js → chunk-TBKOGSYR.js} +2 -2
- package/dist/{chunk-DPMFBCV6.js.map → chunk-TBKOGSYR.js.map} +1 -1
- package/dist/chunk-UND4XIB6.js +251 -0
- package/dist/chunk-UND4XIB6.js.map +1 -0
- package/dist/{chunk-7H6DOO3E.js → chunk-VCGTOS2A.js} +211 -36
- package/dist/chunk-VCGTOS2A.js.map +1 -0
- package/dist/{chunk-MKSA2V7A.js → chunk-VE6YVP32.js} +2 -2
- package/dist/{chunk-5DWL3JBF.js → chunk-VK5EER6C.js} +2 -2
- package/dist/{chunk-MIQHZESA.js → chunk-VPSUZLOJ.js} +4 -4
- package/dist/{chunk-MIQHZESA.js.map → chunk-VPSUZLOJ.js.map} +1 -1
- package/dist/{chunk-XGSOTWYX.js → chunk-VRBCTEKQ.js} +2 -2
- package/dist/{chunk-ADQ5MQ54.js → chunk-W3XXT26A.js} +29 -1
- package/dist/{chunk-ADQ5MQ54.js.map → chunk-W3XXT26A.js.map} +1 -1
- package/dist/{chunk-2AXFIYHT.js → chunk-XG3PTSCD.js} +1 -1
- package/dist/chunk-XG3PTSCD.js.map +1 -0
- package/dist/{chunk-SIZWEV2Y.js → chunk-Y2RKOPNC.js} +4 -4
- package/dist/{chunk-SIZWEV2Y.js.map → chunk-Y2RKOPNC.js.map} +1 -1
- package/dist/{chunk-Z72JH4KG.js → chunk-YTXSFG3C.js} +4 -34
- package/dist/chunk-YTXSFG3C.js.map +1 -0
- package/dist/consent/index.cjs.map +1 -1
- package/dist/consent/index.d.cts +4 -3
- package/dist/consent/index.d.ts +4 -3
- package/dist/consent/index.js +3 -3
- package/dist/{crypto-A7FRXYHC.js → crypto-5ZDIY3NG.js} +3 -3
- package/dist/{delegation-YBA4X4JN.js → delegation-QYXZW25W.js} +5 -5
- package/dist/derivations/index.cjs.map +1 -1
- package/dist/derivations/index.d.cts +5 -4
- package/dist/derivations/index.d.ts +5 -4
- package/dist/derivations/index.js +4 -4
- package/dist/{dev-unlock-DRwVSy2S.d.cts → dev-unlock-DQCNDfFp.d.cts} +1 -1
- package/dist/{dev-unlock-D9s-loPr.d.ts → dev-unlock-utkybTKb.d.ts} +1 -1
- package/dist/executor-AS2IDHKZ.js +11 -0
- package/dist/executor-HLXFXNFM.js +8 -0
- package/dist/executor-HN6YBHZ5.js +8 -0
- package/dist/guards/index.cjs.map +1 -1
- package/dist/guards/index.d.cts +5 -4
- package/dist/guards/index.d.ts +5 -4
- package/dist/guards/index.js +3 -3
- package/dist/{hash-DXXXusyk.d.ts → hash-DcoYWfJ_.d.ts} +1 -1
- package/dist/{hash-DtRih9MQ.d.cts → hash-jDowCrK2.d.cts} +1 -1
- package/dist/history/index.cjs +1 -1
- package/dist/history/index.cjs.map +1 -1
- package/dist/history/index.d.cts +5 -4
- package/dist/history/index.d.ts +5 -4
- package/dist/history/index.js +5 -5
- package/dist/i18n/index.cjs.map +1 -1
- package/dist/i18n/index.d.cts +4 -3
- package/dist/i18n/index.d.ts +4 -3
- package/dist/i18n/index.js +13 -11
- package/dist/i18n/index.js.map +1 -1
- package/dist/{index-CNwA-B6-.d.ts → index-BCKdioeh.d.ts} +29 -1
- package/dist/{index-CmVgTkqk.d.cts → index-BMjrzNZr.d.cts} +29 -1
- package/dist/index.cjs +507 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -11
- package/dist/index.d.ts +12 -11
- package/dist/index.js +106 -8817
- package/dist/index.js.map +1 -1
- package/dist/indexing/index.cjs.map +1 -1
- package/dist/indexing/index.js +2 -2
- package/dist/issue-ORP37MVW.js +12 -0
- package/dist/{ledger-3TXNP47J.js → ledger-3IU5GMXA.js} +5 -5
- package/dist/materialized-views/index.cjs.map +1 -1
- package/dist/materialized-views/index.d.cts +6 -5
- package/dist/materialized-views/index.d.ts +6 -5
- package/dist/materialized-views/index.js +6 -6
- package/dist/noydb-5H3C24GG.js +34 -0
- package/dist/overlay-views/index.cjs.map +1 -1
- package/dist/overlay-views/index.d.cts +5 -4
- package/dist/overlay-views/index.d.ts +5 -4
- package/dist/overlay-views/index.js +6 -4
- package/dist/periods/index.cjs.map +1 -1
- package/dist/periods/index.d.cts +4 -3
- package/dist/periods/index.d.ts +4 -3
- package/dist/periods/index.js +5 -5
- package/dist/{public-envelope-PY6NKFLI.js → public-envelope-U3CMEOMV.js} +3 -3
- package/dist/query/index.cjs.map +1 -1
- package/dist/query/index.d.cts +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +3 -3
- package/dist/{registry-3L3N3PTG.js → registry-3ALP62P6.js} +3 -3
- package/dist/registry-7HE6VJGC.js +8 -0
- package/dist/registry-PSIPG2QR.js +8 -0
- package/dist/registry-PSIPG2QR.js.map +1 -0
- package/dist/revoke-KY2GB4KP.js +17 -0
- package/dist/revoke-KY2GB4KP.js.map +1 -0
- package/dist/session/index.cjs.map +1 -1
- package/dist/session/index.d.cts +5 -4
- package/dist/session/index.d.ts +5 -4
- package/dist/session/index.js +3 -3
- package/dist/shadow/index.cjs.map +1 -1
- package/dist/shadow/index.d.cts +4 -3
- package/dist/shadow/index.d.ts +4 -3
- package/dist/shadow/index.js +2 -2
- package/dist/signer-GRI5TZKH.js +18 -0
- package/dist/signer-GRI5TZKH.js.map +1 -0
- package/dist/{stale-HSC5YO2O.js → stale-OTOF3FH7.js} +2 -2
- package/dist/stale-OTOF3FH7.js.map +1 -0
- package/dist/store/index.cjs.map +1 -1
- package/dist/store/index.d.cts +4 -3
- package/dist/store/index.d.ts +4 -3
- package/dist/store/index.js +2 -2
- package/dist/sync/index.cjs.map +1 -1
- package/dist/sync/index.d.cts +3 -2
- package/dist/sync/index.d.ts +3 -2
- package/dist/sync/index.js +3 -3
- package/dist/team/index.cjs.map +1 -1
- package/dist/team/index.d.cts +4 -3
- package/dist/team/index.d.ts +4 -3
- package/dist/team/index.js +12 -10
- package/dist/tx/index.cjs.map +1 -1
- package/dist/tx/index.d.cts +4 -3
- package/dist/tx/index.d.ts +4 -3
- package/dist/tx/index.js +2 -2
- package/dist/{types-DW9RGSSs.d.ts → types-BoFFiskX.d.ts} +119 -3
- package/dist/{types-C4lwMKKF.d.cts → types-DJG8HG6F.d.cts} +119 -3
- package/dist/{index-hdFvZkBP.d.cts → ulid-BmBgooGm.d.ts} +51 -33
- package/dist/{index-4agOpzqd.d.ts → ulid-C7ms9oli.d.cts} +51 -33
- package/dist/util/index.cjs.map +1 -1
- package/dist/util/index.js +1 -1
- package/dist/{with-derivation-g-pGoMzL.d.ts → with-derivation-BKXXa8Vt.d.ts} +1 -1
- package/dist/{with-derivation-C8LDlV7t.d.cts → with-derivation-BjQ7q4NE.d.cts} +1 -1
- package/dist/{with-guard-DWOCK4Ca.d.ts → with-guard-C25yNjzd.d.ts} +1 -1
- package/dist/{with-guard-jI1x9Z3k.d.cts → with-guard-DQme5DKE.d.cts} +1 -1
- package/dist/{with-materialized-view-DcTx4H3j.d.cts → with-materialized-view-BbEPFIIJ.d.cts} +1 -1
- package/dist/{with-materialized-view-DaKR-N6J.d.ts → with-materialized-view-CqnRwI2S.d.ts} +1 -1
- package/dist/{with-overlayed-view-N7jYuNOS.d.ts → with-overlayed-view-Ct1fSJt-.d.ts} +1 -1
- package/dist/{with-overlayed-view-D-6oWAgM.d.cts → with-overlayed-view-bwlmmFjx.d.cts} +1 -1
- package/package.json +15 -3
- package/dist/chunk-2AXFIYHT.js.map +0 -1
- package/dist/chunk-7H6DOO3E.js.map +0 -1
- package/dist/chunk-CBAHB2BF.js.map +0 -1
- package/dist/chunk-NIOHFJPJ.js.map +0 -1
- package/dist/chunk-VMIO4IXG.js.map +0 -1
- package/dist/chunk-Z72JH4KG.js.map +0 -1
- package/dist/executor-7E3VFGW7.js +0 -11
- package/dist/executor-CEWX2FQI.js +0 -8
- package/dist/executor-X4SQ3ZLC.js +0 -8
- package/dist/registry-O47PUPSY.js +0 -8
- package/dist/registry-WLLMODKN.js +0 -8
- /package/dist/{chunk-5SCJ5UEF.js.map → chunk-243PNUA6.js.map} +0 -0
- /package/dist/{chunk-WCA2NROQ.js.map → chunk-2PAQNPE3.js.map} +0 -0
- /package/dist/{chunk-4TFSM22V.js.map → chunk-3Y53S2SA.js.map} +0 -0
- /package/dist/{chunk-6HPZY4ON.js.map → chunk-3Z2TPHC4.js.map} +0 -0
- /package/dist/{chunk-DYECX3IX.js.map → chunk-7BRE6EUA.js.map} +0 -0
- /package/dist/{chunk-DYBQG5PQ.js.map → chunk-7BUTTVMR.js.map} +0 -0
- /package/dist/{chunk-KESP7GOK.js.map → chunk-7Q5PLD5C.js.map} +0 -0
- /package/dist/{chunk-UA4RI7OT.js.map → chunk-7Z23ZFLV.js.map} +0 -0
- /package/dist/{chunk-EGQYGYIU.js.map → chunk-CXSCDO5T.js.map} +0 -0
- /package/dist/{chunk-OMLIZL2P.js.map → chunk-FAQVNJD4.js.map} +0 -0
- /package/dist/{chunk-I6MX32UC.js.map → chunk-G6FRSBKK.js.map} +0 -0
- /package/dist/{chunk-FCXOFQAJ.js.map → chunk-GIV6DWBG.js.map} +0 -0
- /package/dist/{chunk-34YSDCDP.js.map → chunk-HXJXPZRE.js.map} +0 -0
- /package/dist/{chunk-23TTQXVO.js.map → chunk-J4KLMEUL.js.map} +0 -0
- /package/dist/{chunk-P7EQ2S5O.js.map → chunk-MUWOSVEP.js.map} +0 -0
- /package/dist/{chunk-HB3Z2GCR.js.map → chunk-OVZDFEOR.js.map} +0 -0
- /package/dist/{chunk-UZXLQCHP.js.map → chunk-PLI5TV7N.js.map} +0 -0
- /package/dist/{chunk-PA6R5ZCI.js.map → chunk-Q6W2CMEJ.js.map} +0 -0
- /package/dist/{chunk-537VFZTR.js.map → chunk-QPEXPHJR.js.map} +0 -0
- /package/dist/{chunk-ZNOEIM6Y.js.map → chunk-QXQRKXCU.js.map} +0 -0
- /package/dist/{chunk-RD5LYKD6.js.map → chunk-RTZVQAJ7.js.map} +0 -0
- /package/dist/{chunk-MKSA2V7A.js.map → chunk-VE6YVP32.js.map} +0 -0
- /package/dist/{chunk-5DWL3JBF.js.map → chunk-VK5EER6C.js.map} +0 -0
- /package/dist/{chunk-XGSOTWYX.js.map → chunk-VRBCTEKQ.js.map} +0 -0
- /package/dist/{crypto-A7FRXYHC.js.map → crypto-5ZDIY3NG.js.map} +0 -0
- /package/dist/{delegation-YBA4X4JN.js.map → delegation-QYXZW25W.js.map} +0 -0
- /package/dist/{executor-7E3VFGW7.js.map → executor-AS2IDHKZ.js.map} +0 -0
- /package/dist/{executor-CEWX2FQI.js.map → executor-HLXFXNFM.js.map} +0 -0
- /package/dist/{executor-X4SQ3ZLC.js.map → executor-HN6YBHZ5.js.map} +0 -0
- /package/dist/{ledger-3TXNP47J.js.map → issue-ORP37MVW.js.map} +0 -0
- /package/dist/{public-envelope-PY6NKFLI.js.map → ledger-3IU5GMXA.js.map} +0 -0
- /package/dist/{registry-3L3N3PTG.js.map → noydb-5H3C24GG.js.map} +0 -0
- /package/dist/{registry-O47PUPSY.js.map → public-envelope-U3CMEOMV.js.map} +0 -0
- /package/dist/{registry-WLLMODKN.js.map → registry-3ALP62P6.js.map} +0 -0
- /package/dist/{stale-HSC5YO2O.js.map → registry-7HE6VJGC.js.map} +0 -0
package/dist/aggregate/index.js
CHANGED
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
groupAndReduce,
|
|
17
17
|
reduceRecords,
|
|
18
18
|
resetGroupByWarnings
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-VRBCTEKQ.js";
|
|
20
20
|
import "../chunk-MRIBLZL3.js";
|
|
21
|
-
import "../chunk-
|
|
21
|
+
import "../chunk-W3XXT26A.js";
|
|
22
22
|
|
|
23
23
|
// src/aggregate/active.ts
|
|
24
24
|
function withAggregate() {
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/attestation/index.ts
|
|
21
|
+
var attestation_exports = {};
|
|
22
|
+
__export(attestation_exports, {
|
|
23
|
+
ATTESTATIONS_COLLECTION: () => ATTESTATIONS_COLLECTION,
|
|
24
|
+
AttestationError: () => AttestationError,
|
|
25
|
+
decodeQr: () => import_attestation4.decodeQr,
|
|
26
|
+
getRevokedDocIdsCore: () => getRevokedDocIdsCore,
|
|
27
|
+
isRevoked: () => import_attestation4.isRevoked,
|
|
28
|
+
issueAttestationCore: () => issueAttestationCore,
|
|
29
|
+
publishRevocationListCore: () => publishRevocationListCore,
|
|
30
|
+
revokeDocCore: () => revokeDocCore,
|
|
31
|
+
signRevocationList: () => import_attestation4.signRevocationList,
|
|
32
|
+
unrevokeDocCore: () => unrevokeDocCore,
|
|
33
|
+
verifyAttestation: () => import_attestation4.verifyAttestation,
|
|
34
|
+
verifyRevocationList: () => import_attestation4.verifyRevocationList
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(attestation_exports);
|
|
37
|
+
|
|
38
|
+
// src/types.ts
|
|
39
|
+
var NOYDB_FORMAT_VERSION = 1;
|
|
40
|
+
|
|
41
|
+
// src/errors.ts
|
|
42
|
+
var NoydbError = class extends Error {
|
|
43
|
+
/** Machine-readable error code. Stable across library versions. */
|
|
44
|
+
code;
|
|
45
|
+
constructor(code, message) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "NoydbError";
|
|
48
|
+
this.code = code;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var DecryptionError = class extends NoydbError {
|
|
52
|
+
constructor(message = "Decryption failed") {
|
|
53
|
+
super("DECRYPTION_FAILED", message);
|
|
54
|
+
this.name = "DecryptionError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var TamperedError = class extends NoydbError {
|
|
58
|
+
constructor(message = "Data integrity check failed \u2014 record may have been tampered with") {
|
|
59
|
+
super("TAMPERED", message);
|
|
60
|
+
this.name = "TamperedError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var ConflictError = class extends NoydbError {
|
|
64
|
+
/** The actual stored version at the time of conflict. */
|
|
65
|
+
version;
|
|
66
|
+
constructor(version, message = "Version conflict") {
|
|
67
|
+
super("CONFLICT", message);
|
|
68
|
+
this.name = "ConflictError";
|
|
69
|
+
this.version = version;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var AttestationError = class extends NoydbError {
|
|
73
|
+
constructor(message) {
|
|
74
|
+
super("ATTESTATION", message);
|
|
75
|
+
this.name = "AttestationError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/crypto.ts
|
|
80
|
+
var IV_BYTES = 12;
|
|
81
|
+
var subtle = globalThis.crypto.subtle;
|
|
82
|
+
async function encrypt(plaintext, dek) {
|
|
83
|
+
const iv = generateIV();
|
|
84
|
+
const encoded = new TextEncoder().encode(plaintext);
|
|
85
|
+
const ciphertext = await subtle.encrypt(
|
|
86
|
+
{ name: "AES-GCM", iv },
|
|
87
|
+
dek,
|
|
88
|
+
encoded
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
iv: bufferToBase64(iv),
|
|
92
|
+
data: bufferToBase64(ciphertext)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function decrypt(ivBase64, dataBase64, dek) {
|
|
96
|
+
const iv = base64ToBuffer(ivBase64);
|
|
97
|
+
const ciphertext = base64ToBuffer(dataBase64);
|
|
98
|
+
try {
|
|
99
|
+
const plaintext = await subtle.decrypt(
|
|
100
|
+
{ name: "AES-GCM", iv },
|
|
101
|
+
dek,
|
|
102
|
+
ciphertext
|
|
103
|
+
);
|
|
104
|
+
return new TextDecoder().decode(plaintext);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof Error && err.name === "OperationError") {
|
|
107
|
+
throw new TamperedError();
|
|
108
|
+
}
|
|
109
|
+
throw new DecryptionError(
|
|
110
|
+
err instanceof Error ? err.message : "Decryption failed"
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function generateIV() {
|
|
115
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(IV_BYTES));
|
|
116
|
+
}
|
|
117
|
+
function bufferToBase64(buffer) {
|
|
118
|
+
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
119
|
+
let binary = "";
|
|
120
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
121
|
+
binary += String.fromCharCode(bytes[i]);
|
|
122
|
+
}
|
|
123
|
+
return btoa(binary);
|
|
124
|
+
}
|
|
125
|
+
function base64ToBuffer(base64) {
|
|
126
|
+
const binary = atob(base64);
|
|
127
|
+
const bytes = new Uint8Array(binary.length);
|
|
128
|
+
for (let i = 0; i < binary.length; i++) {
|
|
129
|
+
bytes[i] = binary.charCodeAt(i);
|
|
130
|
+
}
|
|
131
|
+
return bytes;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/bundle/ulid.ts
|
|
135
|
+
var CROCKFORD_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
136
|
+
function encodeBase32(value, length) {
|
|
137
|
+
let out = "";
|
|
138
|
+
let v = value;
|
|
139
|
+
for (let i = 0; i < length; i++) {
|
|
140
|
+
out = CROCKFORD_ALPHABET[v % 32] + out;
|
|
141
|
+
v = Math.floor(v / 32);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
function generateULID() {
|
|
146
|
+
const now = Date.now();
|
|
147
|
+
const timestampHigh = Math.floor(now / 16777216);
|
|
148
|
+
const timestampLow = now & 16777215;
|
|
149
|
+
const tsPart = encodeBase32(timestampHigh, 5) + encodeBase32(timestampLow, 5);
|
|
150
|
+
const randBytes = new Uint8Array(10);
|
|
151
|
+
crypto.getRandomValues(randBytes);
|
|
152
|
+
const rand1 = randBytes[0] * 2 ** 32 + (randBytes[1] << 24 >>> 0) + (randBytes[2] << 16) + (randBytes[3] << 8) + randBytes[4];
|
|
153
|
+
const rand2 = randBytes[5] * 2 ** 32 + (randBytes[6] << 24 >>> 0) + (randBytes[7] << 16) + (randBytes[8] << 8) + randBytes[9];
|
|
154
|
+
const randPart = encodeBase32(rand1, 8) + encodeBase32(rand2, 8);
|
|
155
|
+
return tsPart + randPart;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/attestation/signer.ts
|
|
159
|
+
var import_attestation = require("@noy-db/attestation");
|
|
160
|
+
var ATTESTATIONS_COLLECTION = "_attestations";
|
|
161
|
+
var SIGNER_RECORD_ID = "_signer";
|
|
162
|
+
var REVOKED_RECORD_ID = "_revoked";
|
|
163
|
+
async function loadSigner(store, vault, getDEK) {
|
|
164
|
+
const existing = await store.get(vault, ATTESTATIONS_COLLECTION, SIGNER_RECORD_ID);
|
|
165
|
+
if (!existing) return null;
|
|
166
|
+
const dek = await getDEK(ATTESTATIONS_COLLECTION);
|
|
167
|
+
const json = await decrypt(existing._iv, existing._data, dek);
|
|
168
|
+
return JSON.parse(json);
|
|
169
|
+
}
|
|
170
|
+
async function loadOrCreateSigner(store, vault, getDEK) {
|
|
171
|
+
const existing = await loadSigner(store, vault, getDEK);
|
|
172
|
+
if (existing) return existing;
|
|
173
|
+
const dek = await getDEK(ATTESTATIONS_COLLECTION);
|
|
174
|
+
const signer = await (0, import_attestation.generateDocSigningKeyPair)();
|
|
175
|
+
const { iv, data } = await encrypt(JSON.stringify(signer), dek);
|
|
176
|
+
const env = {
|
|
177
|
+
_noydb: NOYDB_FORMAT_VERSION,
|
|
178
|
+
_v: 1,
|
|
179
|
+
_ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
180
|
+
_iv: iv,
|
|
181
|
+
_data: data
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
await store.put(vault, ATTESTATIONS_COLLECTION, SIGNER_RECORD_ID, env, 0);
|
|
185
|
+
return signer;
|
|
186
|
+
} catch (e) {
|
|
187
|
+
if (!(e instanceof ConflictError)) throw e;
|
|
188
|
+
const winner = await loadSigner(store, vault, getDEK);
|
|
189
|
+
if (!winner) {
|
|
190
|
+
throw new ConflictError(0, "loadOrCreateSigner: signer mint lost a concurrent race but the winning record could not be re-read.");
|
|
191
|
+
}
|
|
192
|
+
return winner;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/attestation/issue.ts
|
|
197
|
+
var import_attestation2 = require("@noy-db/attestation");
|
|
198
|
+
async function issueAttestationCore(ctx, args) {
|
|
199
|
+
if (ctx.role !== "owner") {
|
|
200
|
+
throw new AttestationError(`issueAttestation requires the 'owner' role; caller is '${ctx.role}'. Issuing a signed attestation is the firm's identity operation.`);
|
|
201
|
+
}
|
|
202
|
+
const src = await ctx.readRecord(args.collection, args.id);
|
|
203
|
+
if (!src) throw new AttestationError(`issueAttestation: source record '${args.collection}/${args.id}' not found.`);
|
|
204
|
+
const dek = await ctx.getDEK();
|
|
205
|
+
const signer = await loadOrCreateSigner(ctx.store, ctx.vault, () => Promise.resolve(dek));
|
|
206
|
+
const saltB64 = (0, import_attestation2.bytesToB64url)(crypto.getRandomValues(new Uint8Array(16)));
|
|
207
|
+
let fieldHashes;
|
|
208
|
+
try {
|
|
209
|
+
fieldHashes = await (0, import_attestation2.computeFieldHashes)(saltB64, args.fieldSchema, src.record);
|
|
210
|
+
} catch (e) {
|
|
211
|
+
throw new AttestationError(`issueAttestation: ${e.message}`);
|
|
212
|
+
}
|
|
213
|
+
const docId = generateULID();
|
|
214
|
+
const sig = await (0, import_attestation2.signPayloadCore)({ v: 1, docId, salt: saltB64, keyId: signer.keyId, fieldHashes }, signer.privateKeyPkcs8B64);
|
|
215
|
+
const payload = { v: 1, docId, salt: saltB64, alg: "ed25519", keyId: signer.keyId, fieldHashes, sig };
|
|
216
|
+
const index = {
|
|
217
|
+
docId,
|
|
218
|
+
issuedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
219
|
+
keyId: signer.keyId,
|
|
220
|
+
fieldPaths: args.fieldSchema.fields.map((f) => f.path),
|
|
221
|
+
sourceRefs: [{ collection: args.collection, id: args.id, version: src.version }]
|
|
222
|
+
};
|
|
223
|
+
const { iv, data } = await encrypt(JSON.stringify(index), dek);
|
|
224
|
+
const env = { _noydb: NOYDB_FORMAT_VERSION, _v: 1, _ts: index.issuedAt, _iv: iv, _data: data };
|
|
225
|
+
await ctx.store.put(ctx.vault, ATTESTATIONS_COLLECTION, docId, env);
|
|
226
|
+
return { docId, qr: (0, import_attestation2.encodeQr)(payload), payload, keyId: signer.keyId, publicKeyB64: signer.publicKeyB64 };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/attestation/revoke.ts
|
|
230
|
+
var import_attestation3 = require("@noy-db/attestation");
|
|
231
|
+
function requireOwner(ctx, op) {
|
|
232
|
+
if (ctx.role !== "owner") {
|
|
233
|
+
throw new AttestationError(`${op} requires the 'owner' role; caller is '${ctx.role}'. Revocation is the firm's identity operation.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function readSet(store, vault, dek) {
|
|
237
|
+
const env = await store.get(vault, ATTESTATIONS_COLLECTION, REVOKED_RECORD_ID);
|
|
238
|
+
if (!env) return { docIds: /* @__PURE__ */ new Set(), version: void 0 };
|
|
239
|
+
const set = JSON.parse(await decrypt(env._iv, env._data, dek));
|
|
240
|
+
return { docIds: new Set(set.docIds), version: env._v };
|
|
241
|
+
}
|
|
242
|
+
async function mutateSet(ctx, mutate) {
|
|
243
|
+
const dek = await ctx.getDEK();
|
|
244
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
245
|
+
const { docIds, version } = await readSet(ctx.store, ctx.vault, dek);
|
|
246
|
+
mutate(docIds);
|
|
247
|
+
const payload = { docIds: [...docIds].sort(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
248
|
+
const { iv, data } = await encrypt(JSON.stringify(payload), dek);
|
|
249
|
+
const expectedVersion = version ?? 0;
|
|
250
|
+
const env = {
|
|
251
|
+
_noydb: NOYDB_FORMAT_VERSION,
|
|
252
|
+
_v: expectedVersion + 1,
|
|
253
|
+
_ts: payload.updatedAt,
|
|
254
|
+
_iv: iv,
|
|
255
|
+
_data: data
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
await ctx.store.put(ctx.vault, ATTESTATIONS_COLLECTION, REVOKED_RECORD_ID, env, expectedVersion);
|
|
259
|
+
return;
|
|
260
|
+
} catch (e) {
|
|
261
|
+
if (e instanceof ConflictError && attempt === 0) continue;
|
|
262
|
+
throw e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function revokeDocCore(ctx, docId) {
|
|
267
|
+
requireOwner(ctx, "revokeAttestation");
|
|
268
|
+
const issued = await ctx.store.get(ctx.vault, ATTESTATIONS_COLLECTION, docId);
|
|
269
|
+
if (!issued) throw new AttestationError(`revokeAttestation: attestation '${docId}' not found (was it issued by this vault?).`);
|
|
270
|
+
await mutateSet(ctx, (ids) => ids.add(docId));
|
|
271
|
+
}
|
|
272
|
+
async function unrevokeDocCore(ctx, docId) {
|
|
273
|
+
requireOwner(ctx, "unrevokeAttestation");
|
|
274
|
+
await mutateSet(ctx, (ids) => ids.delete(docId));
|
|
275
|
+
}
|
|
276
|
+
async function getRevokedDocIdsCore(ctx) {
|
|
277
|
+
const dek = await ctx.getDEK();
|
|
278
|
+
const { docIds } = await readSet(ctx.store, ctx.vault, dek);
|
|
279
|
+
return [...docIds].sort();
|
|
280
|
+
}
|
|
281
|
+
async function publishRevocationListCore(ctx) {
|
|
282
|
+
requireOwner(ctx, "publishRevocationList");
|
|
283
|
+
const docIds = await getRevokedDocIdsCore(ctx);
|
|
284
|
+
const signer = await loadOrCreateSigner(ctx.store, ctx.vault, () => ctx.getDEK());
|
|
285
|
+
return (0, import_attestation3.signRevocationList)(docIds, (/* @__PURE__ */ new Date()).toISOString(), signer.keyId, signer.privateKeyPkcs8B64);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/attestation/index.ts
|
|
289
|
+
var import_attestation4 = require("@noy-db/attestation");
|
|
290
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
291
|
+
0 && (module.exports = {
|
|
292
|
+
ATTESTATIONS_COLLECTION,
|
|
293
|
+
AttestationError,
|
|
294
|
+
decodeQr,
|
|
295
|
+
getRevokedDocIdsCore,
|
|
296
|
+
isRevoked,
|
|
297
|
+
issueAttestationCore,
|
|
298
|
+
publishRevocationListCore,
|
|
299
|
+
revokeDocCore,
|
|
300
|
+
signRevocationList,
|
|
301
|
+
unrevokeDocCore,
|
|
302
|
+
verifyAttestation,
|
|
303
|
+
verifyRevocationList
|
|
304
|
+
});
|
|
305
|
+
//# sourceMappingURL=index.cjs.map
|