@macula-io/ts 0.17.0 → 0.19.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/README.md +106 -272
- package/dist/binding.d.ts +50 -45
- package/dist/binding.js +8 -125
- package/dist/binding.js.map +1 -1
- package/dist/content.d.ts +32 -13
- package/dist/content.js +43 -41
- package/dist/content.js.map +1 -1
- package/dist/index.d.ts +5 -9
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/key.d.ts +31 -0
- package/dist/key.js +72 -0
- package/dist/key.js.map +1 -0
- package/dist/pool.d.ts +185 -131
- package/dist/pool.js +223 -576
- package/dist/pool.js.map +1 -1
- package/dist/stream.d.ts +63 -0
- package/dist/stream.js +93 -0
- package/dist/stream.js.map +1 -0
- package/dist/wire.d.ts +53 -0
- package/dist/wire.js +79 -0
- package/dist/wire.js.map +1 -0
- package/package.json +7 -5
- package/prebuilds/darwin-arm64/@macula-io+ts.node +0 -0
- package/prebuilds/darwin-x64/@macula-io+ts.node +0 -0
- package/prebuilds/linux-arm64/@macula-io+ts.node +0 -0
- package/prebuilds/linux-x64/@macula-io+ts.node +0 -0
- package/prebuilds/win32-x64/@macula-io+ts.node +0 -0
- package/dist/dht.d.ts +0 -55
- package/dist/dht.js +0 -25
- package/dist/dht.js.map +0 -1
- package/dist/directdial.d.ts +0 -79
- package/dist/directdial.js +0 -76
- package/dist/directdial.js.map +0 -1
- package/dist/identity.d.ts +0 -43
- package/dist/identity.js +0 -83
- package/dist/identity.js.map +0 -1
- package/dist/pubsub.d.ts +0 -60
- package/dist/pubsub.js +0 -8
- package/dist/pubsub.js.map +0 -1
- package/dist/rpc.d.ts +0 -86
- package/dist/rpc.js +0 -57
- package/dist/rpc.js.map +0 -1
- package/dist/session.d.ts +0 -481
- package/dist/session.js +0 -810
- package/dist/session.js.map +0 -1
- package/dist/ucan.d.ts +0 -110
- package/dist/ucan.js +0 -140
- package/dist/ucan.js.map +0 -1
package/dist/binding.js
CHANGED
|
@@ -1,133 +1,16 @@
|
|
|
1
|
-
// Loads the compiled N-API addon (addon/binding.cc) and
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// -buildmode=c-archive, not loaded separately at runtime).
|
|
1
|
+
// Loads the compiled N-API addon (addon/binding.cc) and types its functions.
|
|
2
|
+
// cabi/'s Go code is linked into the addon statically, so it is one
|
|
3
|
+
// self-contained .node file. node-gyp-build picks, at require time, a local
|
|
4
|
+
// build (build/Release/*.node) or the published prebuild for this platform
|
|
5
|
+
// (prebuilds/<platform>-<arch>/*.node), so a consumer installing from npm
|
|
6
|
+
// never runs a compiler.
|
|
8
7
|
//
|
|
9
|
-
//
|
|
10
|
-
// build/Release/*.node (a local dev build via `npm run build:addon:dev`)
|
|
11
|
-
// or prebuilds/<platform>-<arch>/*.node (baked in by `npm run
|
|
12
|
-
// build:prebuilds` / prebuildify, and published as part of the npm
|
|
13
|
-
// package) -- this is the whole point: a consumer installing this
|
|
14
|
-
// package from npm never runs a compiler or fetches anything, because
|
|
15
|
-
// the matching prebuild is already sitting in the downloaded tarball.
|
|
8
|
+
// Internal to the package: the public API is key.ts, pool.ts and stream.ts.
|
|
16
9
|
import { createRequire } from "node:module";
|
|
17
10
|
import { fileURLToPath } from "node:url";
|
|
18
11
|
import { dirname, join } from "node:path";
|
|
19
12
|
const require = createRequire(import.meta.url);
|
|
20
13
|
const repoRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
21
14
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
22
|
-
const
|
|
23
|
-
export const native = {
|
|
24
|
-
identityGenerate() {
|
|
25
|
-
return addon.identityGenerate();
|
|
26
|
-
},
|
|
27
|
-
identityFromSeedBytes(seed32) {
|
|
28
|
-
if (seed32.length !== 32) {
|
|
29
|
-
throw new Error(`macula-ts: seed must be exactly 32 bytes, got ${seed32.length}`);
|
|
30
|
-
}
|
|
31
|
-
return addon.identityFromSeedBytes(seed32);
|
|
32
|
-
},
|
|
33
|
-
identityNodeId(handle) {
|
|
34
|
-
return addon.identityNodeId(handle);
|
|
35
|
-
},
|
|
36
|
-
identityPrivateBytes(handle) {
|
|
37
|
-
return addon.identityPrivateBytes(handle);
|
|
38
|
-
},
|
|
39
|
-
identityFree(handle) {
|
|
40
|
-
addon.identityFree(handle);
|
|
41
|
-
},
|
|
42
|
-
identitySign(handle, data) {
|
|
43
|
-
return addon.identitySign(handle, data);
|
|
44
|
-
},
|
|
45
|
-
sessionConnect(host, port, identityHandle) {
|
|
46
|
-
return addon.sessionConnect(host, port, identityHandle);
|
|
47
|
-
},
|
|
48
|
-
sessionRemoteAddr(handle) {
|
|
49
|
-
return addon.sessionRemoteAddr(handle);
|
|
50
|
-
},
|
|
51
|
-
sessionStationNodeId(handle) {
|
|
52
|
-
return addon.sessionStationNodeId(handle);
|
|
53
|
-
},
|
|
54
|
-
sessionClose(handle, identityHandle, reason) {
|
|
55
|
-
return addon.sessionClose(handle, identityHandle, reason);
|
|
56
|
-
},
|
|
57
|
-
sessionCall(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, bytesMode) {
|
|
58
|
-
return addon.sessionCall(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, bytesMode);
|
|
59
|
-
},
|
|
60
|
-
ucanMint(identityHandle, issuer, audience, capabilitiesJson, expiresAt, notBefore, nonce, factsJson, proofsJson) {
|
|
61
|
-
return addon.ucanMint(identityHandle, issuer, audience, capabilitiesJson, expiresAt, notBefore, nonce, factsJson, proofsJson);
|
|
62
|
-
},
|
|
63
|
-
ucanDecode(token) {
|
|
64
|
-
return addon.ucanDecode(token);
|
|
65
|
-
},
|
|
66
|
-
sessionCallWithUcan(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, ucanToken, bytesMode) {
|
|
67
|
-
return addon.sessionCallWithUcan(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, ucanToken, bytesMode);
|
|
68
|
-
},
|
|
69
|
-
sessionAdvertise(sessionHandle, identityHandle, realm, procedure) {
|
|
70
|
-
return addon.sessionAdvertise(sessionHandle, identityHandle, realm, procedure);
|
|
71
|
-
},
|
|
72
|
-
sessionUnadvertise(sessionHandle, identityHandle, realm, procedure) {
|
|
73
|
-
return addon.sessionUnadvertise(sessionHandle, identityHandle, realm, procedure);
|
|
74
|
-
},
|
|
75
|
-
serveWaitForCall(sessionHandle, identityHandle, realm, procedure, timeoutMs) {
|
|
76
|
-
return addon.serveWaitForCall(sessionHandle, identityHandle, realm, procedure, timeoutMs);
|
|
77
|
-
},
|
|
78
|
-
pendingCallProcedure(pendingHandle) {
|
|
79
|
-
return addon.pendingCallProcedure(pendingHandle);
|
|
80
|
-
},
|
|
81
|
-
pendingCallPayloadJson(pendingHandle, bytesMode) {
|
|
82
|
-
return addon.pendingCallPayloadJson(pendingHandle, bytesMode);
|
|
83
|
-
},
|
|
84
|
-
pendingCallReplyResult(pendingHandle, resultJson) {
|
|
85
|
-
return addon.pendingCallReplyResult(pendingHandle, resultJson);
|
|
86
|
-
},
|
|
87
|
-
pendingCallReplyError(pendingHandle, detail) {
|
|
88
|
-
return addon.pendingCallReplyError(pendingHandle, detail);
|
|
89
|
-
},
|
|
90
|
-
dhtFindRecordsByType(sessionHandle, identityHandle, recordType) {
|
|
91
|
-
return addon.dhtFindRecordsByType(sessionHandle, identityHandle, recordType);
|
|
92
|
-
},
|
|
93
|
-
dhtFindRecords(sessionHandle, identityHandle, key32) {
|
|
94
|
-
return addon.dhtFindRecords(sessionHandle, identityHandle, key32);
|
|
95
|
-
},
|
|
96
|
-
dhtFindRecord(sessionHandle, identityHandle, key32) {
|
|
97
|
-
return addon.dhtFindRecord(sessionHandle, identityHandle, key32);
|
|
98
|
-
},
|
|
99
|
-
dhtPutProcedureAdvertisement(sessionHandle, identityHandle, realm, procedure, servingStation32, ttlMs) {
|
|
100
|
-
return addon.dhtPutProcedureAdvertisement(sessionHandle, identityHandle, realm, procedure, servingStation32, ttlMs);
|
|
101
|
-
},
|
|
102
|
-
dhtPutContentAnnouncement(sessionHandle, identityHandle, mcid34, endpoint, ttlMs) {
|
|
103
|
-
return addon.dhtPutContentAnnouncement(sessionHandle, identityHandle, mcid34, endpoint, ttlMs);
|
|
104
|
-
},
|
|
105
|
-
sessionPublish(sessionHandle, identityHandle, realm, topic, payloadJson, ttlMs) {
|
|
106
|
-
return addon.sessionPublish(sessionHandle, identityHandle, realm, topic, payloadJson, ttlMs);
|
|
107
|
-
},
|
|
108
|
-
sessionSubscribeStart(sessionHandle, identityHandle, realm, topic, onEvent, bytesMode) {
|
|
109
|
-
return addon.sessionSubscribeStart(sessionHandle, identityHandle, realm, topic, onEvent, bytesMode);
|
|
110
|
-
},
|
|
111
|
-
sessionSubscribeStop(subscriptionHandle) {
|
|
112
|
-
return addon.sessionSubscribeStop(subscriptionHandle);
|
|
113
|
-
},
|
|
114
|
-
contentPut(sessionHandle, identityHandle, data, name) {
|
|
115
|
-
return addon.contentPut(sessionHandle, identityHandle, data, name);
|
|
116
|
-
},
|
|
117
|
-
contentGet(sessionHandle, identityHandle, mcidHex) {
|
|
118
|
-
return addon.contentGet(sessionHandle, identityHandle, mcidHex);
|
|
119
|
-
},
|
|
120
|
-
directdialResolve(sessionHandle, identityHandle, realm, procedure, timeoutMs) {
|
|
121
|
-
return addon.directdialResolve(sessionHandle, identityHandle, realm, procedure, timeoutMs);
|
|
122
|
-
},
|
|
123
|
-
directdialCall(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, bytesMode) {
|
|
124
|
-
return addon.directdialCall(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, bytesMode);
|
|
125
|
-
},
|
|
126
|
-
directdialCallWithUcan(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, ucanToken, bytesMode) {
|
|
127
|
-
return addon.directdialCallWithUcan(sessionHandle, identityHandle, procedure, realm, payloadJson, timeoutMs, ucanToken, bytesMode);
|
|
128
|
-
},
|
|
129
|
-
directdialAdvertise(sessionHandle, identityHandle, realm, procedure, ttlMs) {
|
|
130
|
-
return addon.directdialAdvertise(sessionHandle, identityHandle, realm, procedure, ttlMs);
|
|
131
|
-
},
|
|
132
|
-
};
|
|
15
|
+
export const native = require("node-gyp-build")(repoRoot);
|
|
133
16
|
//# sourceMappingURL=binding.js.map
|
package/dist/binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,oEAAoE;AACpE,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,yBAAyB;AACzB,EAAE;AACF,4EAA4E;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAgBrE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CA+CvD,CAAC"}
|
package/dist/content.d.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly
|
|
13
|
-
|
|
1
|
+
/** A content id (MCID): 50 bytes, tag 2 (SHA-384), a codec byte (0x55 a raw
|
|
2
|
+
* block of at most 256 KiB, 0x56 a manifest over 256 KiB chunks) and the
|
|
3
|
+
* 48-byte hash. Given as 100 hex characters or 50 bytes. */
|
|
4
|
+
export type Mcid = string | Uint8Array;
|
|
5
|
+
/** A content id as the 50 bytes the native layer takes. */
|
|
6
|
+
export declare function mcid50(mcid: Mcid): Uint8Array;
|
|
7
|
+
/** Bounds on one fetch; each defaults as macula's does. */
|
|
8
|
+
export interface ContentOptions {
|
|
9
|
+
/** Largest content accepted, 256 MiB by default. */
|
|
10
|
+
readonly maxBytes?: number;
|
|
11
|
+
/** Most chunks a manifest may have, 16,384 by default. */
|
|
12
|
+
readonly maxChunks?: number;
|
|
13
|
+
/** Chunk streams open at once, 4 by default. */
|
|
14
|
+
readonly parallel?: number;
|
|
15
|
+
/** Deadline of one stream, 15 s by default. */
|
|
16
|
+
readonly chunkTimeoutMs?: number;
|
|
17
|
+
/** Deadline of the whole fetch, 5 minutes by default. */
|
|
18
|
+
readonly timeoutMs?: number;
|
|
14
19
|
}
|
|
20
|
+
/** Content no node announces in the realm. */
|
|
21
|
+
export declare class NotSharedError extends Error {
|
|
22
|
+
constructor();
|
|
23
|
+
}
|
|
24
|
+
/** Content every announcing node failed to give; `detail` names each failure
|
|
25
|
+
* (unreachable, not the content asked for, over the bounds, ...). */
|
|
26
|
+
export declare class ContentUnavailableError extends Error {
|
|
27
|
+
readonly detail: string;
|
|
28
|
+
constructor(detail: string);
|
|
29
|
+
}
|
|
30
|
+
/** The native layer's content errors, as the classes they name. */
|
|
31
|
+
export declare function contentError(e: unknown): Error;
|
|
32
|
+
/** How long a whole fetch waits when not told: 5 minutes. */
|
|
33
|
+
export declare const DEFAULT_CONTENT_TIMEOUT_MS = 300000;
|
package/dist/content.js
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// storage. A station may forget content after serving it, there is no
|
|
13
|
-
// "list what's stored here" operation, and there is no "delete"
|
|
14
|
-
// operation -- putContent()/getContent() hand a blob to a peer once,
|
|
15
|
-
// they do not give you a key-value store. Do not build anything on this
|
|
16
|
-
// SDK that assumes content survives indefinitely, or that a station is
|
|
17
|
-
// obligated to keep serving something it once accepted.
|
|
18
|
-
//
|
|
19
|
-
// mcid crosses the FFI boundary as a lowercase hex string (68 hex
|
|
20
|
-
// chars = 34 bytes: <<Version:8, Codec:8, Hash:32/binary>>, macula-go's
|
|
21
|
-
// manifest.Mcid) -- the same "raw byte identifier -> hex string"
|
|
22
|
-
// convention DhtRecord's key/version/signature already use (dht.ts),
|
|
23
|
-
// deliberately NOT rpc.ts's own "0x"-prefixed convention for bytes
|
|
24
|
-
// embedded *inside* a JSON payload -- an mcid stands on its own here,
|
|
25
|
-
// it isn't a payload field.
|
|
26
|
-
/** Thrown by Session.getContent() when the station reports the content
|
|
27
|
-
* isn't known to it (macula-go's content.ErrNotFound) -- an expected,
|
|
28
|
-
* routine outcome for a transfer mechanism with no durability
|
|
29
|
-
* guarantee, not a transport failure. Unlike DhtRecord's findRecord()
|
|
30
|
-
* (which resolves `null` for its own equivalent "not found" case),
|
|
31
|
-
* getContent() throws instead: its whole contract is "hand back the
|
|
32
|
-
* bytes or fail", and there is no sensible non-throwing value to return
|
|
33
|
-
* in place of the `Uint8Array` a caller asked for. */
|
|
34
|
-
export class ContentNotFoundError extends Error {
|
|
35
|
-
/** The mcid that produced this error, hex-encoded (the same string
|
|
36
|
-
* that was passed to getContent()). */
|
|
37
|
-
mcid;
|
|
38
|
-
constructor(mcid) {
|
|
39
|
-
super(`macula-ts: no content found for mcid ${mcid}`);
|
|
40
|
-
this.name = "ContentNotFoundError";
|
|
41
|
-
this.mcid = mcid;
|
|
1
|
+
// Node-served content (macula 12.6.0, D27): a node shares content by serving
|
|
2
|
+
// it on its own ~<node_id>/content_v1 and announcing it in the DHT; a fetch
|
|
3
|
+
// finds the announcements, dials each sharer through the station it names, and
|
|
4
|
+
// checks the block, the manifest and every chunk against the content id it
|
|
5
|
+
// asked for, so it trusts no sharer and needs no realm key.
|
|
6
|
+
/** A content id as the 50 bytes the native layer takes. */
|
|
7
|
+
export function mcid50(mcid) {
|
|
8
|
+
if (typeof mcid === "string") {
|
|
9
|
+
if (!/^[0-9a-fA-F]{100}$/.test(mcid))
|
|
10
|
+
throw new Error("macula-ts: a content id is 100 hex characters (50 bytes)");
|
|
11
|
+
return Uint8Array.from(Buffer.from(mcid, "hex"));
|
|
42
12
|
}
|
|
13
|
+
if (mcid.length !== 50)
|
|
14
|
+
throw new Error(`macula-ts: a content id is 50 bytes, got ${mcid.length}`);
|
|
15
|
+
return mcid;
|
|
43
16
|
}
|
|
17
|
+
/** Content no node announces in the realm. */
|
|
18
|
+
export class NotSharedError extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("macula-ts: no node shares that content in that realm");
|
|
21
|
+
this.name = "NotSharedError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Content every announcing node failed to give; `detail` names each failure
|
|
25
|
+
* (unreachable, not the content asked for, over the bounds, ...). */
|
|
26
|
+
export class ContentUnavailableError extends Error {
|
|
27
|
+
detail;
|
|
28
|
+
constructor(detail) {
|
|
29
|
+
super(`macula-ts: no sharer gave the content: ${detail}`);
|
|
30
|
+
this.detail = detail;
|
|
31
|
+
this.name = "ContentUnavailableError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The native layer's content errors, as the classes they name. */
|
|
35
|
+
export function contentError(e) {
|
|
36
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
37
|
+
if (message === "not_shared")
|
|
38
|
+
return new NotSharedError();
|
|
39
|
+
const unavailable = /^unavailable:([\s\S]*)$/.exec(message);
|
|
40
|
+
if (unavailable)
|
|
41
|
+
return new ContentUnavailableError(unavailable[1] ?? "");
|
|
42
|
+
return e instanceof Error ? e : new Error(message);
|
|
43
|
+
}
|
|
44
|
+
/** How long a whole fetch waits when not told: 5 minutes. */
|
|
45
|
+
export const DEFAULT_CONTENT_TIMEOUT_MS = 300_000;
|
|
44
46
|
//# sourceMappingURL=content.js.map
|
package/dist/content.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,2EAA2E;AAC3E,4DAA4D;AAO5D,2DAA2D;AAC3D,MAAM,UAAU,MAAM,CAAC,IAAU;IAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAClH,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACnG,OAAO,IAAI,CAAC;AACd,CAAC;AAgBD,8CAA8C;AAC9C,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;QACE,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED;qEACqE;AACrE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAC3B,MAAM;IAA3B,YAAqB,MAAc;QACjC,KAAK,CAAC,0CAA0C,MAAM,EAAE,CAAC,CAAC;sBADvC,MAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAC,CAAU;IACrC,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,IAAI,OAAO,KAAK,YAAY;QAAE,OAAO,IAAI,cAAc,EAAE,CAAC;IAC1D,MAAM,WAAW,GAAG,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,IAAI,WAAW;QAAE,OAAO,IAAI,uBAAuB,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export type { PublishOptions, PubsubEvent, SubscribeOptions } from "./pubsub.js";
|
|
7
|
-
export { ContentNotFoundError } from "./content.js";
|
|
8
|
-
export { Ucan, type UcanCapability, type UcanFactValue, type UcanMintOptions } from "./ucan.js";
|
|
9
|
-
export { keepAdvertisedDirect, KEEP_ADVERTISED_DIRECT_INTERVAL_MS, type DirectDialTarget, type AdvertiseDirectOptions, type KeepAdvertisedDirectOptions, } from "./directdial.js";
|
|
1
|
+
export { NodeKey, type Profile } from "./key.js";
|
|
2
|
+
export { Pool, Subscription, Served, RecordType, type Seed, type PoolOptions, type LinkStatus, type Provider, type Event, type Request, type DhtRecord, } from "./pool.js";
|
|
3
|
+
export { NotSharedError, ContentUnavailableError, DEFAULT_CONTENT_TIMEOUT_MS, type ContentOptions, type Mcid, } from "./content.js";
|
|
4
|
+
export { Stream, StreamMode, type StreamEvent, type StreamRequest } from "./stream.js";
|
|
5
|
+
export { ProviderError, RelayError, StreamError, DEFAULT_CALL_TIMEOUT_MS, type JsonValue, type BytesOutput, type Id, } from "./wire.js";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export { Pool,
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { Ucan } from "./ucan.js";
|
|
8
|
-
export { keepAdvertisedDirect, KEEP_ADVERTISED_DIRECT_INTERVAL_MS, } from "./directdial.js";
|
|
1
|
+
// @macula-io/ts: the macula 12 mesh from TypeScript, over macula-go.
|
|
2
|
+
export { NodeKey } from "./key.js";
|
|
3
|
+
export { Pool, Subscription, Served, RecordType, } from "./pool.js";
|
|
4
|
+
export { NotSharedError, ContentUnavailableError, DEFAULT_CONTENT_TIMEOUT_MS, } from "./content.js";
|
|
5
|
+
export { Stream, StreamMode } from "./stream.js";
|
|
6
|
+
export { ProviderError, RelayError, StreamError, DEFAULT_CALL_TIMEOUT_MS, } from "./wire.js";
|
|
9
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,OAAO,EAAgB,MAAM,UAAU,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,UAAU,GAQX,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAG3B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAwC,MAAM,aAAa,CAAC;AACvF,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,uBAAuB,GAIxB,MAAM,WAAW,CAAC"}
|
package/dist/key.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Handle } from "./binding.js";
|
|
2
|
+
/** A crypto profile: "pq_hybrid" (the fleet's) or "pq_pure". */
|
|
3
|
+
export type Profile = "pq_hybrid" | "pq_pure";
|
|
4
|
+
export declare class NodeKey {
|
|
5
|
+
private handle;
|
|
6
|
+
private constructor();
|
|
7
|
+
/** A new key whose node_id solves the admission puzzle; takes a second or
|
|
8
|
+
* so, off the event loop. */
|
|
9
|
+
static generate(profile?: Profile): Promise<NodeKey>;
|
|
10
|
+
/** The key in the key file at path. A file its group or others can read,
|
|
11
|
+
* or holding a key of another profile, is refused. */
|
|
12
|
+
static load(path: string, profile?: Profile): Promise<NodeKey>;
|
|
13
|
+
/** The key at path, or a new one saved there when the file does not exist. */
|
|
14
|
+
static loadOrCreate(path: string, profile?: Profile): Promise<NodeKey>;
|
|
15
|
+
/** Writes the key to path, readable by its owner only. */
|
|
16
|
+
save(path: string): Promise<void>;
|
|
17
|
+
/** The key's 32-byte node_id. */
|
|
18
|
+
nodeId(): Uint8Array;
|
|
19
|
+
/** The node_id as lowercase hex. */
|
|
20
|
+
nodeIdHex(): string;
|
|
21
|
+
/** The public key as carried on the wire. */
|
|
22
|
+
publicKey(): Uint8Array;
|
|
23
|
+
/** The key's profile. */
|
|
24
|
+
profile(): Profile;
|
|
25
|
+
/** Signs data as given. */
|
|
26
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/** Frees the native key. The NodeKey is unusable after. */
|
|
28
|
+
free(): void;
|
|
29
|
+
/** @internal */
|
|
30
|
+
live(): Handle;
|
|
31
|
+
}
|
package/dist/key.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// A node's identity key, as macula 12 has it: ML-DSA-87 (pq_pure) or the LAMPS
|
|
2
|
+
// composite ML-DSA-87 + RSA-4096-PSS (pq_hybrid, the fleet's profile), whose
|
|
3
|
+
// node_id solves the admission puzzle. Stored in a key file readable by its
|
|
4
|
+
// owner only.
|
|
5
|
+
import { access } from "node:fs/promises";
|
|
6
|
+
import { native } from "./binding.js";
|
|
7
|
+
import { hex } from "./wire.js";
|
|
8
|
+
export class NodeKey {
|
|
9
|
+
handle;
|
|
10
|
+
constructor(handle) {
|
|
11
|
+
this.handle = handle;
|
|
12
|
+
}
|
|
13
|
+
/** A new key whose node_id solves the admission puzzle; takes a second or
|
|
14
|
+
* so, off the event loop. */
|
|
15
|
+
static async generate(profile = "pq_hybrid") {
|
|
16
|
+
return new NodeKey(await native.keyGenerate(profile));
|
|
17
|
+
}
|
|
18
|
+
/** The key in the key file at path. A file its group or others can read,
|
|
19
|
+
* or holding a key of another profile, is refused. */
|
|
20
|
+
static async load(path, profile = "pq_hybrid") {
|
|
21
|
+
return new NodeKey(await native.keyLoad(path, profile));
|
|
22
|
+
}
|
|
23
|
+
/** The key at path, or a new one saved there when the file does not exist. */
|
|
24
|
+
static async loadOrCreate(path, profile = "pq_hybrid") {
|
|
25
|
+
try {
|
|
26
|
+
await access(path);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
const key = await NodeKey.generate(profile);
|
|
30
|
+
await key.save(path);
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
33
|
+
return NodeKey.load(path, profile);
|
|
34
|
+
}
|
|
35
|
+
/** Writes the key to path, readable by its owner only. */
|
|
36
|
+
async save(path) {
|
|
37
|
+
await native.keySave(this.live(), path);
|
|
38
|
+
}
|
|
39
|
+
/** The key's 32-byte node_id. */
|
|
40
|
+
nodeId() {
|
|
41
|
+
return native.keyNodeId(this.live());
|
|
42
|
+
}
|
|
43
|
+
/** The node_id as lowercase hex. */
|
|
44
|
+
nodeIdHex() {
|
|
45
|
+
return hex(this.nodeId());
|
|
46
|
+
}
|
|
47
|
+
/** The public key as carried on the wire. */
|
|
48
|
+
publicKey() {
|
|
49
|
+
return native.keyPublicKey(this.live());
|
|
50
|
+
}
|
|
51
|
+
/** The key's profile. */
|
|
52
|
+
profile() {
|
|
53
|
+
return native.keyProfile(this.live());
|
|
54
|
+
}
|
|
55
|
+
/** Signs data as given. */
|
|
56
|
+
async sign(data) {
|
|
57
|
+
return native.keySign(this.live(), data);
|
|
58
|
+
}
|
|
59
|
+
/** Frees the native key. The NodeKey is unusable after. */
|
|
60
|
+
free() {
|
|
61
|
+
if (this.handle !== null)
|
|
62
|
+
native.keyFree(this.handle);
|
|
63
|
+
this.handle = null;
|
|
64
|
+
}
|
|
65
|
+
/** @internal */
|
|
66
|
+
live() {
|
|
67
|
+
if (this.handle === null)
|
|
68
|
+
throw new Error("macula-ts: this NodeKey was freed");
|
|
69
|
+
return this.handle;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=key.js.map
|
package/dist/key.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../src/key.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,cAAc;AACd,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAKhC,MAAM,OAAO,OAAO;IACU,MAAM;IAAlC,YAA4B,MAAqB;sBAArB,MAAM;IAAkB,CAAC;IAErD;iCAC6B;IAC7B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,GAAY,WAAW;QAClD,OAAO,IAAI,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;0DACsD;IACtD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,OAAO,GAAY,WAAW;QAC5D,OAAO,IAAI,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,8EAA8E;IAC9E,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAY,EAAE,OAAO,GAAY,WAAW;QACpE,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC5C,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,iCAAiC;IACjC,MAAM;QACJ,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,oCAAoC;IACpC,SAAS;QACP,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,6CAA6C;IAC7C,SAAS;QACP,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,yBAAyB;IACzB,OAAO;QACL,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAY,CAAC;IACnD,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,IAAI,CAAC,IAAgB;QACzB,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,2DAA2D;IAC3D,IAAI;QACF,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,gBAAgB;IAChB,IAAI;QACF,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|