@motebit/crypto 0.8.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/LICENSE +26 -0
- package/README.md +142 -0
- package/dist/artifacts.d.ts +268 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +506 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/credential-anchor.d.ts +97 -0
- package/dist/credential-anchor.d.ts.map +1 -0
- package/dist/credential-anchor.js +159 -0
- package/dist/credential-anchor.js.map +1 -0
- package/dist/credentials.d.ts +107 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +209 -0
- package/dist/credentials.js.map +1 -0
- package/dist/index.d.ts +212 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2513 -0
- package/dist/index.js.map +1 -0
- package/dist/signing.d.ts +97 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +282 -0
- package/dist/signing.js.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @motebit/crypto — Protocol cryptography for Motebit artifacts.
|
|
3
|
+
*
|
|
4
|
+
* Sign and verify identity files, execution receipts, verifiable credentials,
|
|
5
|
+
* delegation tokens, key successions, and presentations. One package, any
|
|
6
|
+
* artifact, zero monorepo dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Zero monorepo dependencies — only @noble/ed25519 for cryptography.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* import { verify } from "@motebit/crypto";
|
|
12
|
+
*
|
|
13
|
+
* // Verify any artifact
|
|
14
|
+
* const result = await verify(fs.readFileSync("motebit.md", "utf-8"));
|
|
15
|
+
*
|
|
16
|
+
* // Sign an execution receipt
|
|
17
|
+
* import { signExecutionReceipt } from "@motebit/crypto";
|
|
18
|
+
* const signed = await signExecutionReceipt(receipt, privateKey, publicKey);
|
|
19
|
+
*
|
|
20
|
+
* // Issue a verifiable credential
|
|
21
|
+
* import { issueReputationCredential } from "@motebit/crypto";
|
|
22
|
+
* const vc = await issueReputationCredential(snapshot, privateKey, publicKey, did);
|
|
23
|
+
*/
|
|
24
|
+
export interface MotebitIdentityFile {
|
|
25
|
+
spec: string;
|
|
26
|
+
motebit_id: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
owner_id: string;
|
|
29
|
+
type?: "personal" | "service" | "collaborative";
|
|
30
|
+
service_name?: string;
|
|
31
|
+
service_description?: string;
|
|
32
|
+
service_url?: string;
|
|
33
|
+
capabilities?: string[];
|
|
34
|
+
terms_url?: string;
|
|
35
|
+
identity: {
|
|
36
|
+
algorithm: "Ed25519";
|
|
37
|
+
public_key: string;
|
|
38
|
+
};
|
|
39
|
+
governance: {
|
|
40
|
+
trust_mode: "full" | "guarded" | "minimal";
|
|
41
|
+
max_risk_auto: string;
|
|
42
|
+
require_approval_above: string;
|
|
43
|
+
deny_above: string;
|
|
44
|
+
operator_mode: boolean;
|
|
45
|
+
};
|
|
46
|
+
privacy: {
|
|
47
|
+
default_sensitivity: string;
|
|
48
|
+
retention_days: Record<string, number>;
|
|
49
|
+
fail_closed: boolean;
|
|
50
|
+
};
|
|
51
|
+
memory: {
|
|
52
|
+
half_life_days: number;
|
|
53
|
+
confidence_threshold: number;
|
|
54
|
+
per_turn_limit: number;
|
|
55
|
+
};
|
|
56
|
+
/** Organizational guardian for key recovery and enterprise custody (§3.3). */
|
|
57
|
+
guardian?: {
|
|
58
|
+
public_key: string;
|
|
59
|
+
organization?: string;
|
|
60
|
+
organization_id?: string;
|
|
61
|
+
established_at: string;
|
|
62
|
+
/** Ed25519 signature proving guardian governs this agent. */
|
|
63
|
+
attestation?: string;
|
|
64
|
+
};
|
|
65
|
+
devices: Array<{
|
|
66
|
+
device_id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
public_key: string;
|
|
69
|
+
registered_at: string;
|
|
70
|
+
}>;
|
|
71
|
+
succession?: Array<SuccessionRecord>;
|
|
72
|
+
}
|
|
73
|
+
export interface SuccessionRecord {
|
|
74
|
+
old_public_key: string;
|
|
75
|
+
new_public_key: string;
|
|
76
|
+
timestamp: number;
|
|
77
|
+
reason?: string;
|
|
78
|
+
old_key_signature?: string;
|
|
79
|
+
new_key_signature: string;
|
|
80
|
+
/** True when succession was authorized by guardian, not old key. */
|
|
81
|
+
recovery?: boolean;
|
|
82
|
+
/** Guardian signature — present only when recovery is true. */
|
|
83
|
+
guardian_signature?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface ExecutionReceipt {
|
|
86
|
+
task_id: string;
|
|
87
|
+
motebit_id: string;
|
|
88
|
+
/** Signer's Ed25519 public key (hex). Enables verification without relay lookup. */
|
|
89
|
+
public_key?: string;
|
|
90
|
+
device_id: string;
|
|
91
|
+
submitted_at: number;
|
|
92
|
+
completed_at: number;
|
|
93
|
+
status: string;
|
|
94
|
+
result: string;
|
|
95
|
+
tools_used: string[];
|
|
96
|
+
memories_formed: number;
|
|
97
|
+
prompt_hash: string;
|
|
98
|
+
result_hash: string;
|
|
99
|
+
delegation_receipts?: ExecutionReceipt[];
|
|
100
|
+
delegated_scope?: string;
|
|
101
|
+
signature: string;
|
|
102
|
+
}
|
|
103
|
+
export type { DataIntegrityProof, VerifiableCredential, VerifiablePresentation, } from "./credentials.js";
|
|
104
|
+
import type { VerifiableCredential, VerifiablePresentation } from "./credentials.js";
|
|
105
|
+
export interface VerificationError {
|
|
106
|
+
message: string;
|
|
107
|
+
path?: string;
|
|
108
|
+
}
|
|
109
|
+
interface BaseResult {
|
|
110
|
+
valid: boolean;
|
|
111
|
+
errors?: VerificationError[];
|
|
112
|
+
}
|
|
113
|
+
export interface IdentityVerifyResult extends BaseResult {
|
|
114
|
+
type: "identity";
|
|
115
|
+
identity: MotebitIdentityFile | null;
|
|
116
|
+
did?: string;
|
|
117
|
+
/** First error message. Convenience accessor for backward compatibility. */
|
|
118
|
+
error?: string;
|
|
119
|
+
succession?: {
|
|
120
|
+
valid: boolean;
|
|
121
|
+
genesis_public_key?: string;
|
|
122
|
+
rotations: number;
|
|
123
|
+
error?: string;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export interface ReceiptVerifyResult extends BaseResult {
|
|
127
|
+
type: "receipt";
|
|
128
|
+
receipt: ExecutionReceipt | null;
|
|
129
|
+
signer?: string;
|
|
130
|
+
delegations?: ReceiptVerifyResult[];
|
|
131
|
+
}
|
|
132
|
+
export interface CredentialVerifyResult extends BaseResult {
|
|
133
|
+
type: "credential";
|
|
134
|
+
credential: VerifiableCredential | null;
|
|
135
|
+
issuer?: string;
|
|
136
|
+
subject?: string;
|
|
137
|
+
expired?: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface PresentationVerifyResult extends BaseResult {
|
|
140
|
+
type: "presentation";
|
|
141
|
+
presentation: VerifiablePresentation | null;
|
|
142
|
+
holder?: string;
|
|
143
|
+
credentials?: CredentialVerifyResult[];
|
|
144
|
+
}
|
|
145
|
+
export type VerifyResult = IdentityVerifyResult | ReceiptVerifyResult | CredentialVerifyResult | PresentationVerifyResult;
|
|
146
|
+
export type ArtifactType = VerifyResult["type"];
|
|
147
|
+
export interface VerifyOptions {
|
|
148
|
+
expectedType?: ArtifactType;
|
|
149
|
+
/** Clock skew tolerance in seconds for credential expiry checks. Default: 60. */
|
|
150
|
+
clockSkewSeconds?: number;
|
|
151
|
+
}
|
|
152
|
+
/** @deprecated Use VerifyResult instead. Kept for backward compatibility. */
|
|
153
|
+
export interface LegacyVerifyResult {
|
|
154
|
+
valid: boolean;
|
|
155
|
+
identity: MotebitIdentityFile | null;
|
|
156
|
+
did?: string;
|
|
157
|
+
error?: string;
|
|
158
|
+
succession?: {
|
|
159
|
+
valid: boolean;
|
|
160
|
+
genesis_public_key?: string;
|
|
161
|
+
rotations: number;
|
|
162
|
+
error?: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Parse a motebit.md file into its components.
|
|
167
|
+
* Does not verify the signature — use `verify()` for that.
|
|
168
|
+
*/
|
|
169
|
+
export declare function parse(content: string): {
|
|
170
|
+
frontmatter: MotebitIdentityFile;
|
|
171
|
+
signature: string;
|
|
172
|
+
rawFrontmatter: string;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Verify any Motebit artifact: identity file, execution receipt,
|
|
176
|
+
* verifiable credential, or verifiable presentation.
|
|
177
|
+
*
|
|
178
|
+
* Accepts strings (identity files, JSON) or parsed objects (receipts,
|
|
179
|
+
* credentials, presentations). Detects the artifact type automatically.
|
|
180
|
+
*
|
|
181
|
+
* Use `options.expectedType` to fail fast if the artifact doesn't match
|
|
182
|
+
* the expected type.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* import { verify } from "@motebit/crypto";
|
|
187
|
+
*
|
|
188
|
+
* // Identity file (string)
|
|
189
|
+
* const r1 = await verify(identityFileContent);
|
|
190
|
+
* if (r1.type === "identity" && r1.valid) console.log(r1.did);
|
|
191
|
+
*
|
|
192
|
+
* // Execution receipt (object or JSON string)
|
|
193
|
+
* const r2 = await verify(receipt, { expectedType: "receipt" });
|
|
194
|
+
* if (r2.type === "receipt" && r2.valid) console.log(r2.signer);
|
|
195
|
+
*
|
|
196
|
+
* // Verifiable credential
|
|
197
|
+
* const r3 = await verify(credential);
|
|
198
|
+
* if (r3.type === "credential" && r3.valid) console.log(r3.issuer);
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export declare function verify(artifact: unknown, options?: VerifyOptions): Promise<VerifyResult>;
|
|
202
|
+
/**
|
|
203
|
+
* Verify a motebit.md identity file. Backward-compatible with pre-0.4.0.
|
|
204
|
+
*
|
|
205
|
+
* @deprecated Use `verify(content)` instead — it handles all artifact types.
|
|
206
|
+
*/
|
|
207
|
+
export declare function verifyIdentityFile(content: string): Promise<LegacyVerifyResult>;
|
|
208
|
+
export * from "./signing.js";
|
|
209
|
+
export * from "./artifacts.js";
|
|
210
|
+
export { signVerifiableCredential, verifyVerifiableCredential, signVerifiablePresentation, verifyVerifiablePresentation, issueGradientCredential, issueReputationCredential, issueTrustCredential, createPresentation, type GradientCredentialSubject, type ReputationCredentialSubject, type TrustCredentialSubject, } from "./credentials.js";
|
|
211
|
+
export { computeCredentialLeaf, verifyCredentialAnchor, type CredentialAnchorVerifyResult, type CredentialAnchorProofFields, type ChainAnchorVerifier, } from "./credential-anchor.js";
|
|
212
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAcH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IAGjB,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,eAAe,CAAC;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,EAAE;QACR,SAAS,EAAE,SAAS,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF,UAAU,EAAE;QACV,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;QAC3C,aAAa,EAAE,MAAM,CAAC;QACtB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,OAAO,CAAC;KACxB,CAAC;IAEF,OAAO,EAAE;QACP,mBAAmB,EAAE,MAAM,CAAC;QAC5B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,M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