@layr8/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 (46) hide show
  1. package/README.md +582 -0
  2. package/dist/backoff.d.ts +10 -0
  3. package/dist/backoff.d.ts.map +1 -0
  4. package/dist/backoff.js +20 -0
  5. package/dist/backoff.js.map +1 -0
  6. package/dist/channel.d.ts +88 -0
  7. package/dist/channel.d.ts.map +1 -0
  8. package/dist/channel.js +522 -0
  9. package/dist/channel.js.map +1 -0
  10. package/dist/client.d.ts +119 -0
  11. package/dist/client.d.ts.map +1 -0
  12. package/dist/client.js +509 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/config.d.ts +49 -0
  15. package/dist/config.d.ts.map +1 -0
  16. package/dist/config.js +42 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/credentials.d.ts +55 -0
  19. package/dist/credentials.d.ts.map +1 -0
  20. package/dist/credentials.js +5 -0
  21. package/dist/credentials.js.map +1 -0
  22. package/dist/errors.d.ts +91 -0
  23. package/dist/errors.d.ts.map +1 -0
  24. package/dist/errors.js +132 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/handler.d.ts +28 -0
  27. package/dist/handler.d.ts.map +1 -0
  28. package/dist/handler.js +51 -0
  29. package/dist/handler.js.map +1 -0
  30. package/dist/index.d.ts +16 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +8 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/message.d.ts +67 -0
  35. package/dist/message.d.ts.map +1 -0
  36. package/dist/message.js +77 -0
  37. package/dist/message.js.map +1 -0
  38. package/dist/presentations.d.ts +24 -0
  39. package/dist/presentations.d.ts.map +1 -0
  40. package/dist/presentations.js +5 -0
  41. package/dist/presentations.js.map +1 -0
  42. package/dist/rest.d.ts +33 -0
  43. package/dist/rest.d.ts.map +1 -0
  44. package/dist/rest.js +150 -0
  45. package/dist/rest.js.map +1 -0
  46. package/package.json +38 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * W3C Verifiable Credential types and option interfaces.
3
+ */
4
+ /** CredentialFormat controls the signed credential output encoding. */
5
+ export type CredentialFormat = "compact_jwt" | "json" | "jwt" | "enveloped";
6
+ /** A W3C Verifiable Credential for signing. */
7
+ export interface Credential {
8
+ "@context"?: string[];
9
+ id?: string;
10
+ type?: string[];
11
+ issuer?: string;
12
+ credentialSubject: Record<string, unknown>;
13
+ validFrom?: string;
14
+ validUntil?: string;
15
+ }
16
+ /** Returned by verifyCredential — the decoded credential and JWT headers. */
17
+ export interface VerifiedCredential {
18
+ credential: Record<string, unknown>;
19
+ headers: Record<string, unknown>;
20
+ }
21
+ /** A credential stored in the node's credential store. */
22
+ export interface StoredCredential {
23
+ id: string;
24
+ holder_did: string;
25
+ credential_jwt: string;
26
+ issuer_did?: string;
27
+ valid_until?: string;
28
+ }
29
+ /** Options for signCredential. */
30
+ export interface SignCredentialOptions {
31
+ /** Override the issuer DID (defaults to client.did). */
32
+ issuerDid?: string;
33
+ /** Output format (defaults to "compact_jwt"). */
34
+ format?: CredentialFormat;
35
+ }
36
+ /** Options for verifyCredential. */
37
+ export interface VerifyCredentialOptions {
38
+ /** Override the verifier DID (defaults to client.did). */
39
+ verifierDid?: string;
40
+ }
41
+ /** Options for storeCredential. */
42
+ export interface StoreCredentialOptions {
43
+ /** Override the holder DID (defaults to client.did). */
44
+ holderDid?: string;
45
+ /** Optional issuer DID metadata. */
46
+ issuerDid?: string;
47
+ /** Optional expiration date. */
48
+ validUntil?: Date;
49
+ }
50
+ /** Options for listCredentials. */
51
+ export interface ListCredentialsOptions {
52
+ /** Override the holder DID (defaults to client.did). */
53
+ holderDid?: string;
54
+ }
55
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,uEAAuE;AACvE,MAAM,MAAM,gBAAgB,GAAG,a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,WAAW,sBAAsB;IACrC,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * W3C Verifiable Credential types and option interfaces.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,91 @@
1
+ /** Base class for all Layr8 SDK errors. */
2
+ export declare class Layr8Error extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /** Thrown when send/request is called before connect(). */
6
+ export declare class NotConnectedError extends Layr8Error {
7
+ constructor();
8
+ }
9
+ /** Thrown when handle() is called after connect(). */
10
+ export declare class AlreadyConnectedError extends Layr8Error {
11
+ constructor();
12
+ }
13
+ /** Thrown when connect() is called after close(). */
14
+ export declare class ClientClosedError extends Layr8Error {
15
+ constructor();
16
+ }
17
+ /**
18
+ * Represents a DIDComm problem report received from a remote agent.
19
+ * @see https://identity.foundation/didcomm-messaging/spec/#problem-reports
20
+ *
21
+ * Beyond the standard `code` + `comment`, holds the full report-problem
22
+ * `body` (typed as unknown — caller knows their protocol's report shape)
23
+ * and the raw `attachments` so a caller can inspect protocol-specific
24
+ * fields (e.g. PDP `decision_id`, `reason`, `required_scope`,
25
+ * `original_message`) without reaching into the underlying message.
26
+ */
27
+ export declare class ProblemReportError extends Layr8Error {
28
+ readonly code: string;
29
+ readonly comment: string;
30
+ readonly body: Record<string, unknown>;
31
+ readonly attachments: unknown[];
32
+ constructor(code: string, comment: string, body?: Record<string, unknown>, attachments?: unknown[]);
33
+ }
34
+ /** Represents a failure to connect to the cloud-node. */
35
+ export declare class ConnectionError extends Layr8Error {
36
+ readonly url: string;
37
+ readonly reason: string;
38
+ constructor(url: string, reason: string);
39
+ }
40
+ /** Thrown when the server rejects a message (e.g., authorization failure). */
41
+ export declare class ServerRejectError extends Layr8Error {
42
+ readonly reason: string;
43
+ constructor(reason: string);
44
+ }
45
+ /**
46
+ * Classifies the kind of SDK error that occurred.
47
+ * Mirrors the error kinds defined in the Go SDK for cross-language consistency.
48
+ */
49
+ export declare enum ErrorKind {
50
+ /** Inbound message could not be parsed as DIDComm. */
51
+ ParseFailure = 0,
52
+ /** No handler registered for the message type. */
53
+ NoHandler = 1,
54
+ /** A handler threw an exception. */
55
+ HandlerException = 2,
56
+ /** The server rejected a message (e.g., authz failure). */
57
+ ServerReject = 3,
58
+ /** Failed to write to the WebSocket connection. */
59
+ TransportWrite = 4
60
+ }
61
+ /**
62
+ * Structured error report for poka-yoke diagnostics.
63
+ *
64
+ * This is NOT a throwable Error — it is a plain object that carries
65
+ * machine-readable context about what went wrong, so that ErrorHandler
66
+ * callbacks can log, meter, or alert on SDK failures.
67
+ */
68
+ export declare class SDKError {
69
+ readonly kind: ErrorKind;
70
+ readonly messageId: string;
71
+ readonly type: string;
72
+ readonly from: string;
73
+ readonly cause: Error | null;
74
+ readonly raw: unknown;
75
+ readonly timestamp: Date;
76
+ constructor(kind: ErrorKind, opts?: {
77
+ messageId?: string;
78
+ type?: string;
79
+ from?: string;
80
+ cause?: Error;
81
+ raw?: unknown;
82
+ });
83
+ }
84
+ /** Callback signature for handling structured SDK errors. */
85
+ export type ErrorHandler = (error: SDKError) => void;
86
+ /**
87
+ * Returns an {@link ErrorHandler} that logs every error to `console.error`
88
+ * with structured metadata.
89
+ */
90
+ export declare function logErrors(): ErrorHandler;
91
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED,2DAA2D;AAC3D,qBAAa,iBAAkB,SAAQ,UAAU;;CAKhD;AAED,sDAAsD;AACtD,qBAAa,qBAAsB,SAAQ,UAAU;;CAKpD;AAED,q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AI,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAGvB,IAAI,EAAE,SAAS,EACf,IAAI,GAAE;QACJ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,GAAG,CAAC,EAAE,OAAO,CAAC;KACV;CAUT;AAED,6DAA6D;AAC7D,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAErD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,YAAY,CAYxC"}
package/dist/errors.js ADDED
@@ -0,0 +1,132 @@
1
+ /** Base class for all Layr8 SDK errors. */
2
+ export class Layr8Error extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "Layr8Error";
6
+ }
7
+ }
8
+ /** Thrown when send/request is called before connect(). */
9
+ export class NotConnectedError extends Layr8Error {
10
+ constructor() {
11
+ super("client is not connected");
12
+ this.name = "NotConnectedError";
13
+ }
14
+ }
15
+ /** Thrown when handle() is called after connect(). */
16
+ export class AlreadyConnectedError extends Layr8Error {
17
+ constructor() {
18
+ super("client is already connected");
19
+ this.name = "AlreadyConnectedError";
20
+ }
21
+ }
22
+ /** Thrown when connect() is called after close(). */
23
+ export class ClientClosedError extends Layr8Error {
24
+ constructor() {
25
+ super("client is closed");
26
+ this.name = "ClientClosedError";
27
+ }
28
+ }
29
+ /**
30
+ * Represents a DIDComm problem report received from a remote agent.
31
+ * @see https://identity.foundation/didcomm-messaging/spec/#problem-reports
32
+ *
33
+ * Beyond the standard `code` + `comment`, holds the full report-problem
34
+ * `body` (typed as unknown — caller knows their protocol's report shape)
35
+ * and the raw `attachments` so a caller can inspect protocol-specific
36
+ * fields (e.g. PDP `decision_id`, `reason`, `required_scope`,
37
+ * `original_message`) without reaching into the underlying message.
38
+ */
39
+ export class ProblemReportError extends Layr8Error {
40
+ code;
41
+ comment;
42
+ body;
43
+ attachments;
44
+ constructor(code, comment, body = {}, attachments = []) {
45
+ super(`problem report [${code}]: ${comment}`);
46
+ this.name = "ProblemReportError";
47
+ this.code = code;
48
+ this.comment = comment;
49
+ this.body = body;
50
+ this.attachments = attachments;
51
+ }
52
+ }
53
+ /** Represents a failure to connect to the cloud-node. */
54
+ export class ConnectionError extends Layr8Error {
55
+ url;
56
+ reason;
57
+ constructor(url, reason) {
58
+ super(`connection error [${url}]: ${reason}`);
59
+ this.name = "ConnectionError";
60
+ this.url = url;
61
+ this.reason = reason;
62
+ }
63
+ }
64
+ /** Thrown when the server rejects a message (e.g., authorization failure). */
65
+ export class ServerRejectError extends Layr8Error {
66
+ reason;
67
+ constructor(reason) {
68
+ super(`server rejected message: ${reason}`);
69
+ this.name = "ServerRejectError";
70
+ this.reason = reason;
71
+ }
72
+ }
73
+ // ---------------------------------------------------------------------------
74
+ // Poka-yoke structured error types
75
+ // ---------------------------------------------------------------------------
76
+ /**
77
+ * Classifies the kind of SDK error that occurred.
78
+ * Mirrors the error kinds defined in the Go SDK for cross-language consistency.
79
+ */
80
+ export var ErrorKind;
81
+ (function (ErrorKind) {
82
+ /** Inbound message could not be parsed as DIDComm. */
83
+ ErrorKind[ErrorKind["ParseFailure"] = 0] = "ParseFailure";
84
+ /** No handler registered for the message type. */
85
+ ErrorKind[ErrorKind["NoHandler"] = 1] = "NoHandler";
86
+ /** A handler threw an exception. */
87
+ ErrorKind[ErrorKind["HandlerException"] = 2] = "HandlerException";
88
+ /** The server rejected a message (e.g., authz failure). */
89
+ ErrorKind[ErrorKind["ServerReject"] = 3] = "ServerReject";
90
+ /** Failed to write to the WebSocket connection. */
91
+ ErrorKind[ErrorKind["TransportWrite"] = 4] = "TransportWrite";
92
+ })(ErrorKind || (ErrorKind = {}));
93
+ /**
94
+ * Structured error report for poka-yoke diagnostics.
95
+ *
96
+ * This is NOT a throwable Error — it is a plain object that carries
97
+ * machine-readable context about what went wrong, so that ErrorHandler
98
+ * callbacks can log, meter, or alert on SDK failures.
99
+ */
100
+ export class SDKError {
101
+ kind;
102
+ messageId;
103
+ type;
104
+ from;
105
+ cause;
106
+ raw;
107
+ timestamp;
108
+ constructor(kind, opts = {}) {
109
+ this.kind = kind;
110
+ this.messageId = opts.messageId ?? "";
111
+ this.type = opts.type ?? "";
112
+ this.from = opts.from ?? "";
113
+ this.cause = opts.cause ?? null;
114
+ this.raw = opts.raw ?? undefined;
115
+ this.timestamp = new Date();
116
+ }
117
+ }
118
+ /**
119
+ * Returns an {@link ErrorHandler} that logs every error to `console.error`
120
+ * with structured metadata.
121
+ */
122
+ export function logErrors() {
123
+ return (err) => {
124
+ console.error(`layr8 SDK error [${ErrorKind[err.kind]}]: ${err.cause?.message ?? "unknown"}`, {
125
+ kind: ErrorKind[err.kind],
126
+ messageId: err.messageId,
127
+ type: err.type,
128
+ from: err.from,
129
+ });
130
+ };
131
+ }
132
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,2DAA2D;AAC3D,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC/C;QACE,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,sDAAsD;AACtD,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,qDAAqD;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AC,SAAS;YACxB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Message } from "./message.js";
2
+ /** Sentinel value returned by handlers to signal "I don't handle this message". */
3
+ export declare const PASS: unique symbol;
4
+ /** Handler function signature. Return a response Message, null, or PASS. */
5
+ export type HandlerFn = (msg: Message) => Promise<Message | null | typeof PASS>;
6
+ /** Options for handler registration. */
7
+ export interface HandlerOptions {
8
+ manualAck?: boolean;
9
+ }
10
+ export interface HandlerEntry {
11
+ fn: HandlerFn;
12
+ manualAck: boolean;
13
+ }
14
+ /** Handler registry mapping message types to handlers, with optional catch-all. */
15
+ export declare class HandlerRegistry {
16
+ private readonly handlers;
17
+ private catchAll;
18
+ register(msgType: string, fn: HandlerFn, opts?: HandlerOptions): void;
19
+ registerCatchAll(fn: HandlerFn, opts?: HandlerOptions): void;
20
+ hasCatchAll(): boolean;
21
+ lookup(msgType: string): HandlerEntry | undefined;
22
+ /**
23
+ * Returns the unique protocol base URIs derived from registered handler message types.
24
+ * Appends "*" if a catch-all handler is registered.
25
+ */
26
+ protocols(): string[];
27
+ }
28
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,mFAAmF;AACnF,eAAO,MAAM,IAAI,EAAE,OAAO,MAAuB,CAAC;AAElD,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC;AAEhF,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,SAAS,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,mFAAmF;AACnF,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAC5D,OAAO,CAAC,QAAQ,CAA2B;IAE3C,QAAQ,CACN,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,SAAS,EACb,IAAI,CAAC,EAAE,cAAc,GACpB,IAAI;IAYP,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,IAAI;IAU5D,WAAW,IAAI,OAAO;IAItB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD;;;OAGG;IACH,SAAS,IAAI,MAAM,EAAE;CAUtB"}
@@ -0,0 +1,51 @@
1
+ /** Sentinel value returned by handlers to signal "I don't handle this message". */
2
+ export const PASS = Symbol("PASS");
3
+ /** Handler registry mapping message types to handlers, with optional catch-all. */
4
+ export class HandlerRegistry {
5
+ handlers = new Map();
6
+ catchAll;
7
+ register(msgType, fn, opts) {
8
+ if (this.handlers.has(msgType)) {
9
+ throw new Error(`handler already registered for message type "${msgType}"`);
10
+ }
11
+ this.handlers.set(msgType, {
12
+ fn,
13
+ manualAck: opts?.manualAck ?? false,
14
+ });
15
+ }
16
+ registerCatchAll(fn, opts) {
17
+ if (this.catchAll) {
18
+ throw new Error("catch-all handler already registered");
19
+ }
20
+ this.catchAll = {
21
+ fn,
22
+ manualAck: opts?.manualAck ?? false,
23
+ };
24
+ }
25
+ hasCatchAll() {
26
+ return this.catchAll !== undefined;
27
+ }
28
+ lookup(msgType) {
29
+ return this.handlers.get(msgType) ?? this.catchAll;
30
+ }
31
+ /**
32
+ * Returns the unique protocol base URIs derived from registered handler message types.
33
+ * Appends "*" if a catch-all handler is registered.
34
+ */
35
+ protocols() {
36
+ const seen = new Set();
37
+ for (const msgType of this.handlers.keys()) {
38
+ seen.add(deriveProtocol(msgType));
39
+ }
40
+ if (this.catchAll) {
41
+ seen.add("*");
42
+ }
43
+ return [...seen];
44
+ }
45
+ }
46
+ /** Extract the protocol base URI by removing the last path segment. */
47
+ function deriveProtocol(msgType) {
48
+ const idx = msgType.lastIndexOf("/");
49
+ return idx === -1 ? msgType : msgType.slice(0, idx);
50
+ }
51
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,CAAC,MAAM,IAAI,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC;AAelD,mFAAmF;AACnF,MAAM,OAAO,eAAe;IACT,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACpD,QAAQ,CAA2B;IAE3C,QAAQ,CACN,OAAe,EACf,EAAa,EACb,IAAqB;QAErB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,gDAAgD,OAAO,GAAG,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE;YACzB,EAAE;YACF,SAAS,EAAE,IAAI,EAAE,SAAS,IAAI,KAAK;SACpC,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB,CAAC,EAAa,EAAE,IAAqB;QACnD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG;YACd,EAAE;YACF,SAAS,EAAE,IAAI,EAAE,SAAS,IAAI,KAAK;SACpC,CAAC;IACJ,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC;IACrD,CAAC;IAED;;;OAGG;IACH,SAAS;QACP,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACnB,CAAC;CACF;AAED,uEAAuE;AACvE,SAAS,cAAc,CAAC,OAAe;IACrC,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,16 @@
1
+ export { Layr8Client } from "./client.js";
2
+ export type { RequestOptions, SendOptions } from "./client.js";
3
+ export type { Config, DidSpec, VerificationMethod } from "./config.js";
4
+ export { DEFAULT_DID_SPEC } from "./config.js";
5
+ export type { Attachment, Message, MessageContext, SenderCredential, InternalMessage, } from "./message.js";
6
+ export type { Credential as SenderCredentialCompat } from "./message.js";
7
+ export { unmarshalBody, ack, createMessage, } from "./message.js";
8
+ export type { HandlerFn, HandlerOptions } from "./handler.js";
9
+ export { PASS } from "./handler.js";
10
+ export { Layr8Error, NotConnectedError, AlreadyConnectedError, ClientClosedError, ProblemReportError, ConnectionError, ServerRejectError, ErrorKind, SDKError, logErrors, } from "./errors.js";
11
+ export type { ErrorHandler } from "./errors.js";
12
+ export type { ServerReply } from "./channel.js";
13
+ export { RESTError } from "./rest.js";
14
+ export type { Credential, CredentialFormat, VerifiedCredential, StoredCredential, SignCredentialOptions, VerifyCredentialOptions, StoreCredentialOptions, ListCredentialsOptions, } from "./credentials.js";
15
+ export type { VerifiedPresentation, SignPresentationOptions, VerifyPresentationOptions, } from "./presentations.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EACV,UAAU,EACV,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,UAAU,IAAI,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EACL,aAAa,EACb,GAAG,EACH,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { Layr8Client } from "./client.js";
2
+ export { DEFAULT_DID_SPEC } from "./config.js";
3
+ export { unmarshalBody, ack, createMessage, } from "./message.js";
4
+ export { PASS } from "./handler.js";
5
+ export { Layr8Error, NotConnectedError, AlreadyConnectedError, ClientClosedError, ProblemReportError, ConnectionError, ServerRejectError, ErrorKind, SDKError, logErrors, } from "./errors.js";
6
+ // REST client
7
+ export { RESTError } from "./rest.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAW/C,OAAO,EACL,aAAa,EACb,GAAG,EACH,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,aAAa,CAAC;AAIrB,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,67 @@
1
+ /** Metadata from the cloud-node, present on inbound messages. */
2
+ export interface MessageContext {
3
+ recipient: string;
4
+ authorized: boolean;
5
+ senderCredentials: SenderCredential[];
6
+ }
7
+ /** A sender credential from the cloud-node. */
8
+ export interface SenderCredential {
9
+ id: string;
10
+ name: string;
11
+ }
12
+ /**
13
+ * @deprecated Use {@link SenderCredential} instead. This alias exists for backwards compatibility.
14
+ */
15
+ export type Credential = SenderCredential;
16
+ /** A DIDComm v2 attachment. */
17
+ export interface Attachment {
18
+ id?: string;
19
+ description?: string;
20
+ filename?: string;
21
+ media_type?: string;
22
+ format?: string;
23
+ lastmod_time?: string;
24
+ byte_count?: number;
25
+ data: {
26
+ jws?: unknown;
27
+ hash?: string;
28
+ links?: string[];
29
+ base64?: string;
30
+ json?: unknown;
31
+ };
32
+ }
33
+ /** A DIDComm v2 message. */
34
+ export interface Message {
35
+ id: string;
36
+ type: string;
37
+ from: string;
38
+ to: string[];
39
+ threadId: string;
40
+ parentThreadId: string;
41
+ body: unknown;
42
+ attachments?: Attachment[];
43
+ context?: MessageContext;
44
+ }
45
+ /**
46
+ * Internal message representation with raw body bytes and ack function.
47
+ * Used within the SDK; handlers receive Message but internal routing uses this.
48
+ */
49
+ export interface InternalMessage extends Message {
50
+ /** Raw JSON body for lazy deserialization. */
51
+ bodyRaw?: unknown;
52
+ /** Manual ack function, set by client when manualAck is enabled. */
53
+ ackFn?: (id: string) => void;
54
+ }
55
+ /** Decode the body from an inbound message into a typed object. */
56
+ export declare function unmarshalBody<T>(msg: InternalMessage): T;
57
+ /** Manually acknowledge a message (only meaningful with manualAck). */
58
+ export declare function ack(msg: InternalMessage): void;
59
+ /** Create a Message with default empty fields, merging any partial input. */
60
+ export declare function createMessage(partial?: Partial<Message>): InternalMessage;
61
+ /** Generate a new unique message ID. */
62
+ export declare function generateId(): string;
63
+ /** Serialize a Message into DIDComm JSON wire format. */
64
+ export declare function marshalDIDComm(msg: InternalMessage): string;
65
+ /** Parse an inbound cloud-node message (context + plaintext) into an InternalMessage. */
66
+ export declare function parseDIDComm(data: unknown): InternalMessage;
67
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,MAAM,WA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;IAClB,oEAAoE;IACpE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,eAAe,GAAG,CAAC,CAKxD;AAED,uEAAuE;AACvE,wBAAgB,GAAG,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAI9C;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,eAAe,CAWzE;AAED,wCAAwC;AACxC,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAcD,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAY3D;AAuBD,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,CA+B3D"}
@@ -0,0 +1,77 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ /** Decode the body from an inbound message into a typed object. */
3
+ export function unmarshalBody(msg) {
4
+ if (msg.bodyRaw !== undefined) {
5
+ return msg.bodyRaw;
6
+ }
7
+ return msg.body;
8
+ }
9
+ /** Manually acknowledge a message (only meaningful with manualAck). */
10
+ export function ack(msg) {
11
+ if (msg.ackFn) {
12
+ msg.ackFn(msg.id);
13
+ }
14
+ }
15
+ /** Create a Message with default empty fields, merging any partial input. */
16
+ export function createMessage(partial) {
17
+ return {
18
+ id: "",
19
+ type: "",
20
+ from: "",
21
+ to: [],
22
+ threadId: "",
23
+ parentThreadId: "",
24
+ body: null,
25
+ ...partial,
26
+ };
27
+ }
28
+ /** Generate a new unique message ID. */
29
+ export function generateId() {
30
+ return uuidv4();
31
+ }
32
+ /** Serialize a Message into DIDComm JSON wire format. */
33
+ export function marshalDIDComm(msg) {
34
+ const env = {
35
+ id: msg.id,
36
+ type: msg.type,
37
+ from: msg.from,
38
+ to: msg.to,
39
+ body: msg.body ?? msg.bodyRaw ?? {},
40
+ };
41
+ if (msg.threadId)
42
+ env.thid = msg.threadId;
43
+ if (msg.parentThreadId)
44
+ env.pthid = msg.parentThreadId;
45
+ if (msg.attachments && msg.attachments.length > 0)
46
+ env.attachments = msg.attachments;
47
+ return JSON.stringify(env);
48
+ }
49
+ /** Parse an inbound cloud-node message (context + plaintext) into an InternalMessage. */
50
+ export function parseDIDComm(data) {
51
+ const env = data;
52
+ const pt = env.plaintext;
53
+ const msg = {
54
+ id: pt.id || "",
55
+ type: pt.type || "",
56
+ from: pt.from || "",
57
+ to: pt.to || [],
58
+ threadId: pt.thid || "",
59
+ parentThreadId: pt.pthid || "",
60
+ body: pt.body ?? null,
61
+ bodyRaw: pt.body,
62
+ ...(pt.attachments ? { attachments: pt.attachments } : {}),
63
+ };
64
+ if (env.context) {
65
+ const creds = (env.context.sender_credentials || []).map((c) => ({
66
+ id: c.credential_subject.id,
67
+ name: c.credential_subject.name,
68
+ }));
69
+ msg.context = {
70
+ recipient: env.context.recipient,
71
+ authorized: env.context.authorized,
72
+ senderCredentials: creds,
73
+ };
74
+ }
75
+ return msg;
76
+ }
77
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AA8DpC,mEAAmE;AACnE,MAAM,UAAU,aAAa,CAAI,GAAoB;IACnD,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,OAAY,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC,IAAS,CAAC;AACvB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,GAAG,CAAC,GAAoB;IACtC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC;AAC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I,EAAE;QACf,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE;QACnB,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE;QACnB,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE;QACf,QAAQ,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE;QACvB,cAAc,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE;QAC9B,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACrB,OAAO,EAAE,EAAE,CAAC,IAAI;QAChB,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3D,CAAC;IAEF,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,MAAM,KAAK,GAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,GAAG,CAC1E,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACN,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,EAAE;YAC3B,IAAI,EAAE,CAAC,CAAC,kBAAkB,CAAC,IAAI;SAChC,CAAC,CACH,CAAC;QACF,GAAG,CAAC,OAAO,GAAG;YACZ,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS;YAChC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU;YAClC,iBAAiB,EAAE,KAAK;SACzB,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * W3C Verifiable Presentation types and option interfaces.
3
+ */
4
+ import type { CredentialFormat } from "./credentials.js";
5
+ /** Returned by verifyPresentation — the decoded presentation and JWT headers. */
6
+ export interface VerifiedPresentation {
7
+ presentation: Record<string, unknown>;
8
+ headers: Record<string, unknown>;
9
+ }
10
+ /** Options for signPresentation. */
11
+ export interface SignPresentationOptions {
12
+ /** Override the holder DID (defaults to client.did). */
13
+ holderDid?: string;
14
+ /** Output format (defaults to "compact_jwt"). */
15
+ format?: CredentialFormat;
16
+ /** Optional nonce / challenge for the presentation. */
17
+ nonce?: string;
18
+ }
19
+ /** Options for verifyPresentation. */
20
+ export interface VerifyPresentationOptions {
21
+ /** Override the verifier DID (defaults to client.did). */
22
+ verifierDid?: string;
23
+ }
24
+ //# sourceMappingURL=presentations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentations.d.ts","sourceRoot":"","sources":["../src/presentations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,iFAAiF;AACjF,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,sCAAsC;AACtC,MAAM,WAAW,yBAAyB;IACxC,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * W3C Verifiable Presentation types and option interfaces.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=presentations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentations.js","sourceRoot":"","sources":["../src/presentations.ts"],"names":[],"mappings":"AAAA;;GAEG"}