technocore-sdk 0.1.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +176 -0
  3. package/README.md +165 -0
  4. package/SECURITY.md +46 -0
  5. package/dist/agent/index.d.ts +112 -0
  6. package/dist/agent/index.d.ts.map +1 -0
  7. package/dist/agent/index.js +225 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/client/index.d.ts +29 -0
  10. package/dist/client/index.d.ts.map +1 -0
  11. package/dist/client/index.js +41 -0
  12. package/dist/client/index.js.map +1 -0
  13. package/dist/contributions/index.d.ts +41 -0
  14. package/dist/contributions/index.d.ts.map +1 -0
  15. package/dist/contributions/index.js +48 -0
  16. package/dist/contributions/index.js.map +1 -0
  17. package/dist/crypto/canonicalize.d.ts +31 -0
  18. package/dist/crypto/canonicalize.d.ts.map +1 -0
  19. package/dist/crypto/canonicalize.js +36 -0
  20. package/dist/crypto/canonicalize.js.map +1 -0
  21. package/dist/crypto/did.d.ts +39 -0
  22. package/dist/crypto/did.d.ts.map +1 -0
  23. package/dist/crypto/did.js +82 -0
  24. package/dist/crypto/did.js.map +1 -0
  25. package/dist/crypto/encode.d.ts +34 -0
  26. package/dist/crypto/encode.d.ts.map +1 -0
  27. package/dist/crypto/encode.js +98 -0
  28. package/dist/crypto/encode.js.map +1 -0
  29. package/dist/crypto/fingerprint.d.ts +43 -0
  30. package/dist/crypto/fingerprint.d.ts.map +1 -0
  31. package/dist/crypto/fingerprint.js +61 -0
  32. package/dist/crypto/fingerprint.js.map +1 -0
  33. package/dist/crypto/nonce.d.ts +44 -0
  34. package/dist/crypto/nonce.d.ts.map +1 -0
  35. package/dist/crypto/nonce.js +69 -0
  36. package/dist/crypto/nonce.js.map +1 -0
  37. package/dist/crypto/sign.d.ts +52 -0
  38. package/dist/crypto/sign.d.ts.map +1 -0
  39. package/dist/crypto/sign.js +78 -0
  40. package/dist/crypto/sign.js.map +1 -0
  41. package/dist/crypto/sweep.d.ts +24 -0
  42. package/dist/crypto/sweep.d.ts.map +1 -0
  43. package/dist/crypto/sweep.js +40 -0
  44. package/dist/crypto/sweep.js.map +1 -0
  45. package/dist/crypto/verify.d.ts +27 -0
  46. package/dist/crypto/verify.d.ts.map +1 -0
  47. package/dist/crypto/verify.js +118 -0
  48. package/dist/crypto/verify.js.map +1 -0
  49. package/dist/errors/index.d.ts +86 -0
  50. package/dist/errors/index.d.ts.map +1 -0
  51. package/dist/errors/index.js +131 -0
  52. package/dist/errors/index.js.map +1 -0
  53. package/dist/identity/index.d.ts +100 -0
  54. package/dist/identity/index.d.ts.map +1 -0
  55. package/dist/identity/index.js +143 -0
  56. package/dist/identity/index.js.map +1 -0
  57. package/dist/index.d.ts +37 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +35 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/notes/index.d.ts +108 -0
  62. package/dist/notes/index.d.ts.map +1 -0
  63. package/dist/notes/index.js +251 -0
  64. package/dist/notes/index.js.map +1 -0
  65. package/dist/rooms/index.d.ts +138 -0
  66. package/dist/rooms/index.d.ts.map +1 -0
  67. package/dist/rooms/index.js +325 -0
  68. package/dist/rooms/index.js.map +1 -0
  69. package/dist/streaming/index.d.ts +72 -0
  70. package/dist/streaming/index.d.ts.map +1 -0
  71. package/dist/streaming/index.js +125 -0
  72. package/dist/streaming/index.js.map +1 -0
  73. package/dist/transport/http.d.ts +51 -0
  74. package/dist/transport/http.d.ts.map +1 -0
  75. package/dist/transport/http.js +132 -0
  76. package/dist/transport/http.js.map +1 -0
  77. package/dist/types/index.d.ts +148 -0
  78. package/dist/types/index.d.ts.map +1 -0
  79. package/dist/types/index.js +56 -0
  80. package/dist/types/index.js.map +1 -0
  81. package/dist/verification/index.d.ts +40 -0
  82. package/dist/verification/index.d.ts.map +1 -0
  83. package/dist/verification/index.js +69 -0
  84. package/dist/verification/index.js.map +1 -0
  85. package/package.json +57 -0
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Technocore SDK — Agent Layer
3
+ *
4
+ * Lightweight Agent infrastructure layer managing subscriptions,
5
+ * cursor state, polling lifecycles, and event routing.
6
+ *
7
+ * NOTE: This is protocol infrastructure. It does NOT include LLM logic.
8
+ */
9
+ import { TechnocoreClient } from '../client/index.js';
10
+ /**
11
+ * TechnocoreAgent provides multi-room subscriptions, message dispatching,
12
+ * and lifecycle management on top of TechnocoreClient.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const identity = await Identity.generate();
17
+ * const agent = new TechnocoreAgent({ identity, rooms: ['lobby', 'sdk-test'] });
18
+ *
19
+ * agent.onMessage(async (msg, room) => {
20
+ * console.log(`[${room}] ${msg.from}: ${msg.text}`);
21
+ * });
22
+ *
23
+ * await agent.start();
24
+ * // ...
25
+ * await agent.stop();
26
+ * ```
27
+ */
28
+ export class TechnocoreAgent {
29
+ identity;
30
+ client;
31
+ #waitSec;
32
+ #subscribedRooms = new Set();
33
+ #roomCursors = new Map();
34
+ #abortControllers = new Map();
35
+ #running = false;
36
+ #messageHandlers = [];
37
+ #gapHandlers = [];
38
+ #errorHandlers = [];
39
+ #readyHandlers = [];
40
+ #stoppedHandlers = [];
41
+ constructor(config) {
42
+ this.identity = config.identity;
43
+ this.client = config.client ?? new TechnocoreClient({ baseUrl: config.baseUrl });
44
+ this.#waitSec = config.waitSeconds ?? 10;
45
+ if (config.rooms) {
46
+ for (const r of config.rooms) {
47
+ this.#subscribedRooms.add(r);
48
+ }
49
+ }
50
+ }
51
+ /**
52
+ * Factory method to create a new Agent.
53
+ */
54
+ static async create(config) {
55
+ return new TechnocoreAgent(config);
56
+ }
57
+ /**
58
+ * The Agent's public DID identifier.
59
+ */
60
+ get did() {
61
+ return this.identity.did;
62
+ }
63
+ /**
64
+ * Check if the agent is actively running.
65
+ */
66
+ get isRunning() {
67
+ return this.#running;
68
+ }
69
+ /**
70
+ * Subscribe to incoming messages on all subscribed rooms or a specific room.
71
+ */
72
+ onMessage(handler) {
73
+ this.#messageHandlers.push(handler);
74
+ return this;
75
+ }
76
+ /**
77
+ * Subscribe to sequence gap notifications.
78
+ */
79
+ onSequenceGap(handler) {
80
+ this.#gapHandlers.push(handler);
81
+ return this;
82
+ }
83
+ /**
84
+ * Subscribe to error notifications.
85
+ */
86
+ onError(handler) {
87
+ this.#errorHandlers.push(handler);
88
+ return this;
89
+ }
90
+ /**
91
+ * Subscribe to agent ready event.
92
+ */
93
+ onReady(handler) {
94
+ this.#readyHandlers.push(handler);
95
+ return this;
96
+ }
97
+ /**
98
+ * Subscribe to agent stopped event.
99
+ */
100
+ onStopped(handler) {
101
+ this.#stoppedHandlers.push(handler);
102
+ return this;
103
+ }
104
+ /**
105
+ * Dynamically subscribe to an additional room.
106
+ */
107
+ subscribe(room) {
108
+ if (!this.#subscribedRooms.has(room)) {
109
+ this.#subscribedRooms.add(room);
110
+ if (this.#running) {
111
+ this.#startRoomLoop(room);
112
+ }
113
+ }
114
+ }
115
+ /**
116
+ * Unsubscribe from a room.
117
+ */
118
+ unsubscribe(room) {
119
+ this.#subscribedRooms.delete(room);
120
+ const controller = this.#abortControllers.get(room);
121
+ if (controller) {
122
+ controller.abort();
123
+ this.#abortControllers.delete(room);
124
+ }
125
+ }
126
+ /**
127
+ * Send a signed message as this Agent to a room.
128
+ *
129
+ * @param room - Target room
130
+ * @param text - Message text
131
+ */
132
+ async say(room, text) {
133
+ return this.client.rooms.sendSigned(room, this.identity, text);
134
+ }
135
+ /**
136
+ * Start the agent and listen on all subscribed rooms.
137
+ */
138
+ async start() {
139
+ if (this.#running)
140
+ return;
141
+ this.#running = true;
142
+ for (const room of this.#subscribedRooms) {
143
+ this.#startRoomLoop(room);
144
+ }
145
+ for (const handler of this.#readyHandlers) {
146
+ try {
147
+ handler();
148
+ }
149
+ catch (err) {
150
+ this.#emitError(err instanceof Error ? err : new Error(String(err)));
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Stop the agent gracefully and cancel all room listeners.
156
+ */
157
+ async stop() {
158
+ if (!this.#running)
159
+ return;
160
+ this.#running = false;
161
+ for (const controller of this.#abortControllers.values()) {
162
+ controller.abort();
163
+ }
164
+ this.#abortControllers.clear();
165
+ for (const handler of this.#stoppedHandlers) {
166
+ try {
167
+ handler();
168
+ }
169
+ catch (err) {
170
+ this.#emitError(err instanceof Error ? err : new Error(String(err)));
171
+ }
172
+ }
173
+ }
174
+ // ─── Private Room Polling Loop ──────────────────────────────────────────────
175
+ #startRoomLoop(room) {
176
+ const controller = new AbortController();
177
+ this.#abortControllers.set(room, controller);
178
+ (async () => {
179
+ try {
180
+ const stream = this.client.rooms.stream(room, {
181
+ since: this.#roomCursors.get(room),
182
+ wait: this.#waitSec,
183
+ signal: controller.signal,
184
+ onGap: (gap) => {
185
+ for (const h of this.#gapHandlers) {
186
+ h({ ...gap, room });
187
+ }
188
+ },
189
+ onError: (err) => {
190
+ this.#emitError(err, room);
191
+ },
192
+ });
193
+ for await (const { message } of stream) {
194
+ if (!this.#running || controller.signal.aborted)
195
+ break;
196
+ this.#roomCursors.set(room, message.seq);
197
+ for (const handler of this.#messageHandlers) {
198
+ try {
199
+ await handler(message, room);
200
+ }
201
+ catch (err) {
202
+ this.#emitError(err instanceof Error ? err : new Error(String(err)), room);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ catch (err) {
208
+ if (!controller.signal.aborted) {
209
+ this.#emitError(err instanceof Error ? err : new Error(String(err)), room);
210
+ }
211
+ }
212
+ })();
213
+ }
214
+ #emitError(error, room) {
215
+ for (const h of this.#errorHandlers) {
216
+ try {
217
+ h(error, room);
218
+ }
219
+ catch {
220
+ // Prevent recursive error loops
221
+ }
222
+ }
223
+ }
224
+ }
225
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM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AAG,CAAC,CAAC;oBAEzC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;wBAC5C,IAAI,CAAC;4BACH,MAAM,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;wBAC/B,CAAC;wBAAC,OAAO,GAAG,EAAE,CAAC;4BACb,IAAI,CAAC,UAAU,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;wBAC7E,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;oBAC/B,IAAI,CAAC,UAAU,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;gBAC7E,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAED,UAAU,CAAC,KAAY,EAAE,IAAa;QACpC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,IAAI,CAAC;gBACH,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACP,gCAAgC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Technocore SDK — Main Client
3
+ *
4
+ * Core protocol orchestration client providing structured access to:
5
+ * - `client.rooms` : Rooms API (list, read, send, sendSigned, export, discover)
6
+ * - `client.verifyMessage()` : Standalone message verifier
7
+ * - `client.transport` : Underlying HTTP transport
8
+ */
9
+ import { HttpTransport } from '../transport/http.js';
10
+ import { RoomsClient } from '../rooms/index.js';
11
+ import { NotesClient } from '../notes/index.js';
12
+ import { ContributionsClient } from '../contributions/index.js';
13
+ import type { TechnocoreClientConfig, VerificationResult, TechnocoreMessage } from '../types/index.js';
14
+ export declare class TechnocoreClient {
15
+ readonly transport: HttpTransport;
16
+ readonly rooms: RoomsClient;
17
+ readonly notes: NotesClient;
18
+ readonly contributions: ContributionsClient;
19
+ constructor(config?: TechnocoreClientConfig);
20
+ /**
21
+ * Verify a signed Technocore message offline.
22
+ *
23
+ * @param room - The room name
24
+ * @param message - The message object with `from`, `nonce`, `sig`, `text`
25
+ * @returns Structured VerificationResult
26
+ */
27
+ verifyMessage(room: string, message: TechnocoreMessage): Promise<VerificationResult>;
28
+ }
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvG,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAC;gBAEhC,MAAM,GAAE,sBAA2B;IAa/C;;;;;;OAMG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAG3F"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Technocore SDK — Main Client
3
+ *
4
+ * Core protocol orchestration client providing structured access to:
5
+ * - `client.rooms` : Rooms API (list, read, send, sendSigned, export, discover)
6
+ * - `client.verifyMessage()` : Standalone message verifier
7
+ * - `client.transport` : Underlying HTTP transport
8
+ */
9
+ import { HttpTransport } from '../transport/http.js';
10
+ import { RoomsClient } from '../rooms/index.js';
11
+ import { NotesClient } from '../notes/index.js';
12
+ import { ContributionsClient } from '../contributions/index.js';
13
+ import { verifyMessage } from '../crypto/verify.js';
14
+ export class TechnocoreClient {
15
+ transport;
16
+ rooms;
17
+ notes;
18
+ contributions;
19
+ constructor(config = {}) {
20
+ const transportConfig = {
21
+ baseUrl: config.baseUrl,
22
+ fetch: config.fetch,
23
+ timeoutMs: config.timeoutMs,
24
+ };
25
+ this.transport = new HttpTransport(transportConfig);
26
+ this.rooms = new RoomsClient(this.transport);
27
+ this.notes = new NotesClient(this.transport);
28
+ this.contributions = new ContributionsClient(this.rooms);
29
+ }
30
+ /**
31
+ * Verify a signed Technocore message offline.
32
+ *
33
+ * @param room - The room name
34
+ * @param message - The message object with `from`, `nonce`, `sig`, `text`
35
+ * @returns Structured VerificationResult
36
+ */
37
+ async verifyMessage(room, message) {
38
+ return verifyMessage(room, message);
39
+ }
40
+ }
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,OAAO,gBAAgB;IAClB,SAAS,CAAgB;IACzB,KAAK,CAAc;IACnB,KAAK,CAAc;IACnB,aAAa,CAAsB;IAE5C,YAAY,SAAiC,EAAE;QAC7C,MAAM,eAAe,GAAoB;YACvC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,eAAe,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,aAAa,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,aAAa,CAAC,IAAY,EAAE,OAA0B;QAC1D,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Technocore SDK — Contributions Module
3
+ *
4
+ * Facilitates the recording of attributable open-source / agent work on the Technocore mesh.
5
+ *
6
+ * NOTE: This module records verifiable contribution proofs on-chain/in-protocol.
7
+ * It does not calculate rewards or make claims about token allocations.
8
+ */
9
+ import { RoomsClient } from '../rooms/index.js';
10
+ import { Identity } from '../identity/index.js';
11
+ export interface ContributionParams {
12
+ /** URL of the work, PR, commit, paper, or artifact. */
13
+ readonly url: string;
14
+ /** Topic or category of the contribution (e.g., 'code', 'research', 'docs'). */
15
+ readonly topic?: string;
16
+ /** Signing identity asserting the contribution. */
17
+ readonly identity: Identity;
18
+ /** Target room for contribution broadcasts (default: 'contributions'). */
19
+ readonly room?: string;
20
+ }
21
+ export interface ContributionRecord {
22
+ readonly did: string;
23
+ readonly room: string;
24
+ readonly sequence: number;
25
+ readonly text: string;
26
+ readonly signature: string;
27
+ readonly nonce: string;
28
+ readonly timestamp: string;
29
+ }
30
+ export declare class ContributionsClient {
31
+ #private;
32
+ constructor(rooms: RoomsClient);
33
+ /**
34
+ * Record a signed, attributable contribution record on the Technocore mesh.
35
+ *
36
+ * @param params - Contribution parameters (url, topic, identity, room)
37
+ * @returns Structured ContributionRecord with server sequence and cryptographic signature proof
38
+ */
39
+ record(params: ContributionParams): Promise<ContributionRecord>;
40
+ }
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contributions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,mBAAmB;;gBAGlB,KAAK,EAAE,WAAW;IAI9B;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAiCtE"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Technocore SDK — Contributions Module
3
+ *
4
+ * Facilitates the recording of attributable open-source / agent work on the Technocore mesh.
5
+ *
6
+ * NOTE: This module records verifiable contribution proofs on-chain/in-protocol.
7
+ * It does not calculate rewards or make claims about token allocations.
8
+ */
9
+ import { TechnocoreValidationError } from '../errors/index.js';
10
+ export class ContributionsClient {
11
+ #rooms;
12
+ constructor(rooms) {
13
+ this.#rooms = rooms;
14
+ }
15
+ /**
16
+ * Record a signed, attributable contribution record on the Technocore mesh.
17
+ *
18
+ * @param params - Contribution parameters (url, topic, identity, room)
19
+ * @returns Structured ContributionRecord with server sequence and cryptographic signature proof
20
+ */
21
+ async record(params) {
22
+ if (!params.url || typeof params.url !== 'string') {
23
+ throw new TechnocoreValidationError('url', 'Contribution URL is required');
24
+ }
25
+ if (!params.identity) {
26
+ throw new TechnocoreValidationError('identity', 'Signer identity is required');
27
+ }
28
+ const room = params.room ?? 'contributions';
29
+ const topicPart = params.topic ? ` topic:${params.topic}` : '';
30
+ const payloadText = `contribution: ${params.url.trim()}${topicPart}`;
31
+ const sendResult = await this.#rooms.sendSigned(room, params.identity, payloadText);
32
+ // Find the message just recorded
33
+ const message = sendResult.messages.find((m) => m.from === params.identity.did && m.text === payloadText) ?? sendResult.messages[sendResult.messages.length - 1];
34
+ if (!message) {
35
+ throw new Error(`Failed to retrieve recorded contribution message from room '${room}'`);
36
+ }
37
+ return {
38
+ did: params.identity.did,
39
+ room,
40
+ sequence: message.seq,
41
+ text: message.text,
42
+ signature: message.sig ?? '',
43
+ nonce: String(message.nonce ?? ''),
44
+ timestamp: message.ts,
45
+ };
46
+ }
47
+ }
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contributions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GA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OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,+DAA+D,IAAI,GAAG,CAAC,CAAC;QAC1F,CAAC;QAED,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG;YACxB,IAAI;YACJ,QAAQ,EAAE,OAAO,CAAC,GAAG;YACrB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,SAAS,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;YAC5B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;YAClC,SAAS,EAAE,OAAO,CAAC,EAAE;SACtB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Technocore SDK — Canonical Signing Payloads
3
+ *
4
+ * Builds the exact byte sequences that Ed25519 signs.
5
+ *
6
+ * Message signature covers: <room>|<nonce>|<text> as UTF-8
7
+ * Note signature covers: <ns>|<key>|<nonce>|<value> as UTF-8
8
+ *
9
+ * The <text> / <value> is the content AFTER the single-line sweep — the bytes
10
+ * that get stored — so the record can be re-verified later.
11
+ */
12
+ /**
13
+ * Build the canonical signing payload for a room message.
14
+ *
15
+ * @param room - Room name
16
+ * @param nonce - Nonce string (1–19 digits)
17
+ * @param text - Message text AFTER single-line sweep
18
+ * @returns UTF-8 encoded bytes of "<room>|<nonce>|<text>"
19
+ */
20
+ export declare function canonicalMessagePayload(room: string, nonce: string, text: string): Uint8Array;
21
+ /**
22
+ * Build the canonical signing payload for a signed note write.
23
+ *
24
+ * @param namespace - Note namespace (e.g., "room-owners", "room-allow")
25
+ * @param key - Note key
26
+ * @param nonce - Nonce string
27
+ * @param value - Note value
28
+ * @returns UTF-8 encoded bytes of "<namespace>|<key>|<nonce>|<value>"
29
+ */
30
+ export declare function canonicalNotePayload(namespace: string, key: string, nonce: string, value: string): Uint8Array;
31
+ //# sourceMappingURL=canonicalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalize.d.ts","sourceRoot":"","sources":["../../src/crypto/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,UAAU,CAEZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,UAAU,CAEZ"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Technocore SDK — Canonical Signing Payloads
3
+ *
4
+ * Builds the exact byte sequences that Ed25519 signs.
5
+ *
6
+ * Message signature covers: <room>|<nonce>|<text> as UTF-8
7
+ * Note signature covers: <ns>|<key>|<nonce>|<value> as UTF-8
8
+ *
9
+ * The <text> / <value> is the content AFTER the single-line sweep — the bytes
10
+ * that get stored — so the record can be re-verified later.
11
+ */
12
+ import { utf8Encode } from './encode.js';
13
+ /**
14
+ * Build the canonical signing payload for a room message.
15
+ *
16
+ * @param room - Room name
17
+ * @param nonce - Nonce string (1–19 digits)
18
+ * @param text - Message text AFTER single-line sweep
19
+ * @returns UTF-8 encoded bytes of "<room>|<nonce>|<text>"
20
+ */
21
+ export function canonicalMessagePayload(room, nonce, text) {
22
+ return utf8Encode(`${room}|${nonce}|${text}`);
23
+ }
24
+ /**
25
+ * Build the canonical signing payload for a signed note write.
26
+ *
27
+ * @param namespace - Note namespace (e.g., "room-owners", "room-allow")
28
+ * @param key - Note key
29
+ * @param nonce - Nonce string
30
+ * @param value - Note value
31
+ * @returns UTF-8 encoded bytes of "<namespace>|<key>|<nonce>|<value>"
32
+ */
33
+ export function canonicalNotePayload(namespace, key, nonce, value) {
34
+ return utf8Encode(`${namespace}|${key}|${nonce}|${value}`);
35
+ }
36
+ //# sourceMappingURL=canonicalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalize.js","sourceRoot":"","sources":["../../src/crypto/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,KAAa,EACb,IAAY;IAEZ,OAAO,UAAU,CAAC,GAAG,IAAI,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,GAAW,EACX,KAAa,EACb,KAAa;IAEb,OAAO,UAAU,CAAC,GAAG,SAAS,IAAI,GAAG,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Technocore SDK — DID Operations
3
+ *
4
+ * did:key with Ed25519 only.
5
+ * Format: did:key:z6Mk[base58btc-encoded-multicodec-pubkey]
6
+ *
7
+ * Multicodec prefix for ed25519-pub: 0xed 0x01
8
+ * Multibase: base58btc with 'z' prefix
9
+ *
10
+ * The full DID is exactly 56 characters.
11
+ */
12
+ /**
13
+ * Generate a DID string from a raw 32-byte Ed25519 public key.
14
+ *
15
+ * @param publicKey - 32-byte Ed25519 public key
16
+ * @returns DID string (did:key:z6Mk...)
17
+ * @throws TechnocoreDIDError if publicKey is not 32 bytes
18
+ */
19
+ export declare function didFromPublicKey(publicKey: Uint8Array): string;
20
+ /**
21
+ * Extract the raw 32-byte Ed25519 public key from a DID string.
22
+ *
23
+ * @param did - A valid Technocore DID string
24
+ * @returns 32-byte public key
25
+ * @throws TechnocoreDIDError if DID is malformed
26
+ */
27
+ export declare function publicKeyFromDid(did: string): Uint8Array;
28
+ /**
29
+ * Validate a DID string format.
30
+ *
31
+ * @param did - String to validate
32
+ * @throws TechnocoreDIDError if invalid
33
+ */
34
+ export declare function validateDid(did: string): void;
35
+ /**
36
+ * Check if a string is a valid Technocore DID (non-throwing).
37
+ */
38
+ export declare function isValidDid(did: string): boolean;
39
+ //# sourceMappingURL=did.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/crypto/did.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAiB9D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAoBxD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAgB7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Technocore SDK — DID Operations
3
+ *
4
+ * did:key with Ed25519 only.
5
+ * Format: did:key:z6Mk[base58btc-encoded-multicodec-pubkey]
6
+ *
7
+ * Multicodec prefix for ed25519-pub: 0xed 0x01
8
+ * Multibase: base58btc with 'z' prefix
9
+ *
10
+ * The full DID is exactly 56 characters.
11
+ */
12
+ import { base58btcEncode, base58btcDecode } from './encode.js';
13
+ import { TechnocoreDIDError } from '../errors/index.js';
14
+ import { DID_PATTERN, DID_LENGTH } from '../types/index.js';
15
+ /** Multicodec prefix for ed25519-pub: [0xed, 0x01] */
16
+ const ED25519_MULTICODEC_PREFIX = new Uint8Array([0xed, 0x01]);
17
+ /** The did:key prefix before the multibase-encoded key. */
18
+ const DID_KEY_PREFIX = 'did:key:z';
19
+ /**
20
+ * Generate a DID string from a raw 32-byte Ed25519 public key.
21
+ *
22
+ * @param publicKey - 32-byte Ed25519 public key
23
+ * @returns DID string (did:key:z6Mk...)
24
+ * @throws TechnocoreDIDError if publicKey is not 32 bytes
25
+ */
26
+ export function didFromPublicKey(publicKey) {
27
+ if (publicKey.length !== 32) {
28
+ throw new TechnocoreDIDError(`Expected 32-byte Ed25519 public key, got ${publicKey.length} bytes`);
29
+ }
30
+ // Prepend multicodec prefix [0xed, 0x01] to the 32-byte public key
31
+ const multicodecKey = new Uint8Array(34);
32
+ multicodecKey.set(ED25519_MULTICODEC_PREFIX);
33
+ multicodecKey.set(publicKey, 2);
34
+ // Encode as base58btc (without the 'z' prefix — we add it as part of did:key:z)
35
+ // @scure/base base58btc.encode returns string without multibase prefix
36
+ const encoded = base58btcEncode(multicodecKey);
37
+ return `did:key:z${encoded}`;
38
+ }
39
+ /**
40
+ * Extract the raw 32-byte Ed25519 public key from a DID string.
41
+ *
42
+ * @param did - A valid Technocore DID string
43
+ * @returns 32-byte public key
44
+ * @throws TechnocoreDIDError if DID is malformed
45
+ */
46
+ export function publicKeyFromDid(did) {
47
+ validateDid(did);
48
+ // Strip 'did:key:z' prefix to get the base58btc-encoded multicodec key
49
+ const encoded = did.slice(DID_KEY_PREFIX.length);
50
+ const decoded = base58btcDecode(encoded);
51
+ // Verify multicodec prefix
52
+ if (decoded.length !== 34 ||
53
+ decoded[0] !== 0xed ||
54
+ decoded[1] !== 0x01) {
55
+ throw new TechnocoreDIDError(`DID does not contain a valid Ed25519 multicodec key (expected 0xed01 prefix, 34 bytes)`, did);
56
+ }
57
+ return decoded.slice(2);
58
+ }
59
+ /**
60
+ * Validate a DID string format.
61
+ *
62
+ * @param did - String to validate
63
+ * @throws TechnocoreDIDError if invalid
64
+ */
65
+ export function validateDid(did) {
66
+ if (typeof did !== 'string') {
67
+ throw new TechnocoreDIDError('DID must be a string');
68
+ }
69
+ if (did.length !== DID_LENGTH) {
70
+ throw new TechnocoreDIDError(`DID must be exactly ${DID_LENGTH} characters, got ${did.length}`, did);
71
+ }
72
+ if (!DID_PATTERN.test(did)) {
73
+ throw new TechnocoreDIDError('DID must match did:key:z6Mk[base58btc]{44}', did);
74
+ }
75
+ }
76
+ /**
77
+ * Check if a string is a valid Technocore DID (non-throwing).
78
+ */
79
+ export function isValidDid(did) {
80
+ return typeof did === 'string' && did.length === DID_LENGTH && DID_PATTERN.test(did);
81
+ }
82
+ //# sourceMappingURL=did.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/crypto/did.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,sDAAsD;AACtD,MAAM,yBAAyB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE/D,2DAA2D;AAC3D,MAAM,cAAc,GAAG,WAAW,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAqB;IACpD,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,kBAAkB,CAC1B,4CAA4C,SAAS,CAAC,MAAM,QAAQ,CACrE,CAAC;IACJ,CAAC;IAED,mEAAmE;IACnE,MAAM,aAAa,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACzC,aAAa,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC7C,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAEhC,gFAAgF;IAChF,uEAAuE;IACvE,MAAM,OAAO,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;IAE/C,OAAO,YAAY,OAAO,EAAE,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,WAAW,CAAC,GAAG,CAAC,CAAC;IAEjB,uEAAuE;IACvE,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAEzC,2BAA2B;IAC3B,IACE,OAAO,CAAC,MAAM,KAAK,EAAE;QACrB,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI;QACnB,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,EACnB,CAAC;QACD,MAAM,IAAI,kBAAkB,CAC1B,wFAAwF,EACxF,GAAG,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAC9B,MAAM,IAAI,kBAAkB,CAC1B,uBAAuB,UAAU,oBAAoB,GAAG,CAAC,MAAM,EAAE,EACjE,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,kBAAkB,CAC1B,4CAA4C,EAC5C,GAAG,CACJ,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvF,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Technocore SDK — Encoding Utilities
3
+ *
4
+ * Base64url and base58btc encoding for signatures and DIDs.
5
+ * Uses @scure/base for base58btc (audited, zero-dependency).
6
+ */
7
+ /**
8
+ * Encode bytes to base64url (no padding).
9
+ * This is the canonical encoding — the last character is determined by the encoder,
10
+ * and is the only one the server accepts.
11
+ */
12
+ export declare function base64urlEncode(bytes: Uint8Array): string;
13
+ /**
14
+ * Decode base64url string to bytes (no padding expected).
15
+ */
16
+ export declare function base64urlDecode(str: string): Uint8Array;
17
+ /**
18
+ * Encode bytes to base58btc (Bitcoin alphabet).
19
+ * Used for the multibase portion of did:key identifiers.
20
+ */
21
+ export declare function base58btcEncode(bytes: Uint8Array): string;
22
+ /**
23
+ * Decode base58btc string to bytes.
24
+ */
25
+ export declare function base58btcDecode(str: string): Uint8Array;
26
+ /**
27
+ * Encode string to UTF-8 bytes.
28
+ */
29
+ export declare function utf8Encode(str: string): Uint8Array;
30
+ /**
31
+ * Decode UTF-8 bytes to string.
32
+ */
33
+ export declare function utf8Decode(bytes: Uint8Array): string;
34
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/crypto/encode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA6BzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAwBvD;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEvD;AAOD;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAElD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD"}