@auths-dev/sdk 0.0.1 → 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 (60) hide show
  1. package/Cargo.toml +45 -0
  2. package/README.md +163 -4
  3. package/__test__/client.spec.ts +78 -0
  4. package/__test__/exports.spec.ts +57 -0
  5. package/__test__/integration.spec.ts +407 -0
  6. package/__test__/policy.spec.ts +202 -0
  7. package/__test__/verify.spec.ts +88 -0
  8. package/build.rs +5 -0
  9. package/index.d.ts +259 -0
  10. package/index.js +622 -1
  11. package/lib/artifacts.ts +124 -0
  12. package/lib/attestations.ts +126 -0
  13. package/lib/audit.ts +189 -0
  14. package/lib/client.ts +293 -0
  15. package/lib/commits.ts +70 -0
  16. package/lib/devices.ts +178 -0
  17. package/lib/errors.ts +306 -0
  18. package/lib/identity.ts +280 -0
  19. package/lib/index.ts +125 -0
  20. package/lib/native.ts +255 -0
  21. package/lib/org.ts +235 -0
  22. package/lib/pairing.ts +271 -0
  23. package/lib/policy.ts +669 -0
  24. package/lib/signing.ts +204 -0
  25. package/lib/trust.ts +152 -0
  26. package/lib/types.ts +179 -0
  27. package/lib/verify.ts +241 -0
  28. package/lib/witness.ts +91 -0
  29. package/npm/darwin-arm64/README.md +3 -0
  30. package/npm/darwin-arm64/package.json +23 -0
  31. package/npm/linux-arm64-gnu/README.md +3 -0
  32. package/npm/linux-arm64-gnu/package.json +26 -0
  33. package/npm/linux-x64-gnu/README.md +3 -0
  34. package/npm/linux-x64-gnu/package.json +26 -0
  35. package/npm/win32-arm64-msvc/README.md +3 -0
  36. package/npm/win32-arm64-msvc/package.json +23 -0
  37. package/npm/win32-x64-msvc/README.md +3 -0
  38. package/npm/win32-x64-msvc/package.json +23 -0
  39. package/package.json +51 -16
  40. package/src/artifact.rs +217 -0
  41. package/src/attestation_query.rs +104 -0
  42. package/src/audit.rs +128 -0
  43. package/src/commit_sign.rs +63 -0
  44. package/src/device.rs +212 -0
  45. package/src/diagnostics.rs +106 -0
  46. package/src/error.rs +5 -0
  47. package/src/helpers.rs +60 -0
  48. package/src/identity.rs +467 -0
  49. package/src/lib.rs +26 -0
  50. package/src/org.rs +430 -0
  51. package/src/pairing.rs +454 -0
  52. package/src/policy.rs +147 -0
  53. package/src/sign.rs +215 -0
  54. package/src/trust.rs +189 -0
  55. package/src/types.rs +205 -0
  56. package/src/verify.rs +447 -0
  57. package/src/witness.rs +138 -0
  58. package/tsconfig.json +19 -0
  59. package/typedoc.json +18 -0
  60. package/vitest.config.ts +12 -0
package/lib/verify.ts ADDED
@@ -0,0 +1,241 @@
1
+ import native from './native'
2
+ import type { NapiVerificationResult, NapiVerificationReport } from './native'
3
+ import { mapNativeError, VerificationError } from './errors'
4
+
5
+ /** Result of verifying a single attestation. */
6
+ export interface VerificationResult {
7
+ /** Whether the attestation is valid. */
8
+ valid: boolean
9
+ /** Error message if verification failed, or `null`. */
10
+ error?: string | null
11
+ /** Machine-readable error code, or `null`. */
12
+ errorCode?: string | null
13
+ }
14
+
15
+ /** Status summary of a chain verification. */
16
+ export interface VerificationStatus {
17
+ /** Status type: `'Valid'`, `'Invalid'`, `'Expired'`, etc. */
18
+ statusType: string
19
+ /** Timestamp context for the status, or `null`. */
20
+ at?: string | null
21
+ /** Chain step where verification failed, or `null`. */
22
+ step?: number | null
23
+ /** DID of the missing link in the chain, or `null`. */
24
+ missingLink?: string | null
25
+ /** Number of required witnesses, or `null`. */
26
+ required?: number | null
27
+ /** Number of verified witnesses, or `null`. */
28
+ verified?: number | null
29
+ }
30
+
31
+ /** A single link in a verified attestation chain. */
32
+ export interface ChainLink {
33
+ /** DID of the issuer at this link. */
34
+ issuer: string
35
+ /** DID of the subject at this link. */
36
+ subject: string
37
+ /** Whether this link verified successfully. */
38
+ valid: boolean
39
+ /** Error message if this link failed, or `null`. */
40
+ error?: string | null
41
+ }
42
+
43
+ /** Full report from a chain verification. */
44
+ export interface VerificationReport {
45
+ /** Overall verification status. */
46
+ status: VerificationStatus
47
+ /** Individual chain link results. */
48
+ chain: ChainLink[]
49
+ /** Non-fatal warnings encountered during verification. */
50
+ warnings: string[]
51
+ }
52
+
53
+ /** Public key of a witness node. */
54
+ export interface WitnessKey {
55
+ /** DID of the witness. */
56
+ did: string
57
+ /** Hex-encoded Ed25519 public key of the witness. */
58
+ publicKeyHex: string
59
+ }
60
+
61
+ /** Configuration for witness-backed chain verification. */
62
+ export interface WitnessConfig {
63
+ /** JSON-serialized witness receipts. */
64
+ receipts: string[]
65
+ /** Witness public keys. */
66
+ keys: WitnessKey[]
67
+ /** Minimum number of witness receipts required. */
68
+ threshold: number
69
+ }
70
+
71
+ /**
72
+ * Verifies a single attestation against an issuer's public key.
73
+ *
74
+ * @param attestationJson - JSON-serialized attestation.
75
+ * @param issuerPkHex - Hex-encoded Ed25519 public key of the issuer.
76
+ * @returns The verification result.
77
+ * @throws {@link VerificationError} if verification encounters an error.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { verifyAttestation } from '@auths-dev/sdk'
82
+ *
83
+ * const result = await verifyAttestation(attestationJson, publicKeyHex)
84
+ * console.log(result.valid) // true
85
+ * ```
86
+ */
87
+ export async function verifyAttestation(attestationJson: string, issuerPkHex: string): Promise<VerificationResult> {
88
+ try {
89
+ return await native.verifyAttestation(attestationJson, issuerPkHex)
90
+ } catch (err) {
91
+ throw mapNativeError(err, VerificationError)
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Verifies a single attestation with a required capability check.
97
+ *
98
+ * @param attestationJson - JSON-serialized attestation.
99
+ * @param issuerPkHex - Hex-encoded Ed25519 public key of the issuer.
100
+ * @param requiredCapability - Capability the attestation must grant.
101
+ * @returns The verification result.
102
+ * @throws {@link VerificationError} if verification fails.
103
+ */
104
+ export async function verifyAttestationWithCapability(attestationJson: string, issuerPkHex: string, requiredCapability: string): Promise<VerificationResult> {
105
+ try {
106
+ return await native.verifyAttestationWithCapability(attestationJson, issuerPkHex, requiredCapability)
107
+ } catch (err) {
108
+ throw mapNativeError(err, VerificationError)
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Verifies an attestation chain from leaf to root.
114
+ *
115
+ * @param attestationsJson - Array of JSON-serialized attestations (leaf to root).
116
+ * @param rootPkHex - Hex-encoded Ed25519 public key of the root identity.
117
+ * @returns The verification report with chain link details.
118
+ * @throws {@link VerificationError} if verification encounters an error.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import { verifyChain } from '@auths-dev/sdk'
123
+ *
124
+ * const report = await verifyChain(attestationChain, rootPublicKeyHex)
125
+ * console.log(report.status.statusType) // 'Valid'
126
+ * ```
127
+ */
128
+ export async function verifyChain(attestationsJson: string[], rootPkHex: string): Promise<VerificationReport> {
129
+ try {
130
+ return await native.verifyChain(attestationsJson, rootPkHex)
131
+ } catch (err) {
132
+ throw mapNativeError(err, VerificationError)
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Verifies an attestation chain with a required capability at the leaf.
138
+ *
139
+ * @param attestationsJson - Array of JSON-serialized attestations (leaf to root).
140
+ * @param rootPkHex - Hex-encoded Ed25519 public key of the root identity.
141
+ * @param requiredCapability - Capability the leaf attestation must grant.
142
+ * @returns The verification report.
143
+ * @throws {@link VerificationError} if verification fails.
144
+ */
145
+ export async function verifyChainWithCapability(attestationsJson: string[], rootPkHex: string, requiredCapability: string): Promise<VerificationReport> {
146
+ try {
147
+ return await native.verifyChainWithCapability(attestationsJson, rootPkHex, requiredCapability)
148
+ } catch (err) {
149
+ throw mapNativeError(err, VerificationError)
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Verifies that a device is authorized by an identity through an attestation chain.
155
+ *
156
+ * @param identityDid - DID of the authorizing identity.
157
+ * @param deviceDid - DID of the device to verify.
158
+ * @param attestationsJson - Array of JSON-serialized attestations.
159
+ * @param identityPkHex - Hex-encoded Ed25519 public key of the identity.
160
+ * @returns The verification report.
161
+ * @throws {@link VerificationError} if verification fails.
162
+ */
163
+ export async function verifyDeviceAuthorization(identityDid: string, deviceDid: string, attestationsJson: string[], identityPkHex: string): Promise<VerificationReport> {
164
+ try {
165
+ return await native.verifyDeviceAuthorization(identityDid, deviceDid, attestationsJson, identityPkHex)
166
+ } catch (err) {
167
+ throw mapNativeError(err, VerificationError)
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Verifies a single attestation at a specific point in time.
173
+ *
174
+ * @param attestationJson - JSON-serialized attestation.
175
+ * @param issuerPkHex - Hex-encoded Ed25519 public key of the issuer.
176
+ * @param atRfc3339 - RFC 3339 timestamp to verify at.
177
+ * @returns The verification result.
178
+ * @throws {@link VerificationError} if verification fails.
179
+ */
180
+ export async function verifyAtTime(attestationJson: string, issuerPkHex: string, atRfc3339: string): Promise<VerificationResult> {
181
+ try {
182
+ return await native.verifyAtTime(attestationJson, issuerPkHex, atRfc3339)
183
+ } catch (err) {
184
+ throw mapNativeError(err, VerificationError)
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Verifies an attestation at a specific time with a required capability.
190
+ *
191
+ * @param attestationJson - JSON-serialized attestation.
192
+ * @param issuerPkHex - Hex-encoded Ed25519 public key of the issuer.
193
+ * @param atRfc3339 - RFC 3339 timestamp to verify at.
194
+ * @param requiredCapability - Capability the attestation must grant.
195
+ * @returns The verification result.
196
+ * @throws {@link VerificationError} if verification fails.
197
+ */
198
+ export async function verifyAtTimeWithCapability(attestationJson: string, issuerPkHex: string, atRfc3339: string, requiredCapability: string): Promise<VerificationResult> {
199
+ try {
200
+ return await native.verifyAtTimeWithCapability(attestationJson, issuerPkHex, atRfc3339, requiredCapability)
201
+ } catch (err) {
202
+ throw mapNativeError(err, VerificationError)
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Verifies an attestation chain with witness receipt validation.
208
+ *
209
+ * @param attestationsJson - Array of JSON-serialized attestations (leaf to root).
210
+ * @param rootPkHex - Hex-encoded Ed25519 public key of the root identity.
211
+ * @param witnesses - Witness configuration with receipts, keys, and threshold.
212
+ * @returns The verification report.
213
+ * @throws {@link VerificationError} if verification fails.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * import { verifyChainWithWitnesses } from '@auths-dev/sdk'
218
+ *
219
+ * const report = await verifyChainWithWitnesses(chain, rootKey, {
220
+ * receipts: witnessReceipts,
221
+ * keys: [{ did: witnessDid, publicKeyHex: witnessKey }],
222
+ * threshold: 1,
223
+ * })
224
+ * ```
225
+ */
226
+ export async function verifyChainWithWitnesses(attestationsJson: string[], rootPkHex: string, witnesses: WitnessConfig): Promise<VerificationReport> {
227
+ const keysJson = witnesses.keys.map(k =>
228
+ JSON.stringify({ did: k.did, public_key_hex: k.publicKeyHex }),
229
+ )
230
+ try {
231
+ return await native.verifyChainWithWitnesses(
232
+ attestationsJson,
233
+ rootPkHex,
234
+ witnesses.receipts,
235
+ keysJson,
236
+ witnesses.threshold,
237
+ )
238
+ } catch (err) {
239
+ throw mapNativeError(err, VerificationError)
240
+ }
241
+ }
package/lib/witness.ts ADDED
@@ -0,0 +1,91 @@
1
+ import native from './native'
2
+ import { mapNativeError, StorageError } from './errors'
3
+ import type { Auths } from './client'
4
+
5
+ /** A witness node entry in the local registry. */
6
+ export interface WitnessEntry {
7
+ /** URL of the witness endpoint. */
8
+ url: string
9
+ /** DID of the witness, or `null` if not yet resolved. */
10
+ did: string | null
11
+ /** Optional label for the witness. */
12
+ label: string | null
13
+ }
14
+
15
+ /** Options for {@link WitnessService.add}. */
16
+ export interface AddWitnessOptions {
17
+ /** URL of the witness endpoint (e.g. `'http://witness.example.com:3333'`). */
18
+ url: string
19
+ /** Optional label for the witness. */
20
+ label?: string
21
+ }
22
+
23
+ /**
24
+ * Manages witness nodes for receipt-based verification.
25
+ *
26
+ * Access via {@link Auths.witnesses}.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * auths.witnesses.add({ url: 'http://witness.example.com:3333' })
31
+ * const witnesses = auths.witnesses.list()
32
+ * ```
33
+ */
34
+ export class WitnessService {
35
+ constructor(private client: Auths) {}
36
+
37
+ /**
38
+ * Adds a witness node. Idempotent — adding the same URL twice is a no-op.
39
+ *
40
+ * @param opts - Witness options.
41
+ * @returns The witness entry.
42
+ * @throws {@link StorageError} if the operation fails.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const w = auths.witnesses.add({ url: 'http://witness.example.com:3333' })
47
+ * console.log(w.url) // http://witness.example.com:3333
48
+ * ```
49
+ */
50
+ add(opts: AddWitnessOptions): WitnessEntry {
51
+ try {
52
+ const result = native.addWitness(opts.url, this.client.repoPath, opts.label ?? null)
53
+ return {
54
+ url: result.url,
55
+ did: result.did ?? null,
56
+ label: result.label ?? null,
57
+ }
58
+ } catch (err) {
59
+ throw mapNativeError(err, StorageError)
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Removes a witness by URL.
65
+ *
66
+ * @param url - URL of the witness to remove.
67
+ * @throws {@link StorageError} if the operation fails.
68
+ */
69
+ remove(url: string): void {
70
+ try {
71
+ native.removeWitness(url, this.client.repoPath)
72
+ } catch (err) {
73
+ throw mapNativeError(err, StorageError)
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Lists all registered witnesses.
79
+ *
80
+ * @returns Array of witness entries.
81
+ * @throws {@link StorageError} if the operation fails.
82
+ */
83
+ list(): WitnessEntry[] {
84
+ try {
85
+ const json = native.listWitnesses(this.client.repoPath)
86
+ return JSON.parse(json)
87
+ } catch (err) {
88
+ throw mapNativeError(err, StorageError)
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,3 @@
1
+ # `@auths-dev/sdk-darwin-arm64`
2
+
3
+ This is the **aarch64-apple-darwin** binary for `@auths-dev/sdk`
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@auths-dev/sdk-darwin-arm64",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "auths.darwin-arm64.node",
8
+ "files": [
9
+ "auths.darwin-arm64.node"
10
+ ],
11
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
12
+ "license": "Apache-2.0",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/auths-dev/auths"
19
+ },
20
+ "os": [
21
+ "darwin"
22
+ ]
23
+ }
@@ -0,0 +1,3 @@
1
+ # `@auths-dev/sdk-linux-arm64-gnu`
2
+
3
+ This is the **aarch64-unknown-linux-gnu** binary for `@auths-dev/sdk`
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@auths-dev/sdk-linux-arm64-gnu",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "auths.linux-arm64-gnu.node",
8
+ "files": [
9
+ "auths.linux-arm64-gnu.node"
10
+ ],
11
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
12
+ "license": "Apache-2.0",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/auths-dev/auths"
19
+ },
20
+ "os": [
21
+ "linux"
22
+ ],
23
+ "libc": [
24
+ "glibc"
25
+ ]
26
+ }
@@ -0,0 +1,3 @@
1
+ # `@auths-dev/sdk-linux-x64-gnu`
2
+
3
+ This is the **x86_64-unknown-linux-gnu** binary for `@auths-dev/sdk`
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@auths-dev/sdk-linux-x64-gnu",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "x64"
6
+ ],
7
+ "main": "auths.linux-x64-gnu.node",
8
+ "files": [
9
+ "auths.linux-x64-gnu.node"
10
+ ],
11
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
12
+ "license": "Apache-2.0",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/auths-dev/auths"
19
+ },
20
+ "os": [
21
+ "linux"
22
+ ],
23
+ "libc": [
24
+ "glibc"
25
+ ]
26
+ }
@@ -0,0 +1,3 @@
1
+ # `@auths-dev/sdk-win32-arm64-msvc`
2
+
3
+ This is the **aarch64-pc-windows-msvc** binary for `@auths-dev/sdk`
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@auths-dev/sdk-win32-arm64-msvc",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "auths.win32-arm64-msvc.node",
8
+ "files": [
9
+ "auths.win32-arm64-msvc.node"
10
+ ],
11
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
12
+ "license": "Apache-2.0",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/auths-dev/auths"
19
+ },
20
+ "os": [
21
+ "win32"
22
+ ]
23
+ }
@@ -0,0 +1,3 @@
1
+ # `@auths-dev/sdk-win32-x64-msvc`
2
+
3
+ This is the **x86_64-pc-windows-msvc** binary for `@auths-dev/sdk`
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@auths-dev/sdk-win32-x64-msvc",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "x64"
6
+ ],
7
+ "main": "auths.win32-x64-msvc.node",
8
+ "files": [
9
+ "auths.win32-x64-msvc.node"
10
+ ],
11
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
12
+ "license": "Apache-2.0",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/auths-dev/auths"
19
+ },
20
+ "os": [
21
+ "win32"
22
+ ]
23
+ }
package/package.json CHANGED
@@ -1,21 +1,56 @@
1
1
  {
2
2
  "name": "@auths-dev/sdk",
3
- "version": "0.0.1",
4
- "description": "Auths SDK for decentralized identity management — coming soon",
5
- "main": "index.js",
6
- "keywords": [
7
- "auths",
8
- "identity",
9
- "decentralized-identity",
10
- "did",
11
- "keri",
12
- "sdk"
13
- ],
14
- "author": "auths-dev",
15
- "license": "MIT",
16
- "homepage": "https://auths.dev",
3
+ "version": "0.1.0",
4
+ "description": "Node.js bindings for the Auths decentralized identity SDK",
5
+ "license": "Apache-2.0",
17
6
  "repository": {
18
7
  "type": "git",
19
- "url": "https://github.com/auths-dev/auths.git"
8
+ "url": "https://github.com/auths-dev/auths"
9
+ },
10
+ "main": "index.js",
11
+ "types": "index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "default": "./index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "engines": {
20
+ "node": ">=20.0.0"
21
+ },
22
+ "napi": {
23
+ "binaryName": "auths",
24
+ "targets": [
25
+ "aarch64-apple-darwin",
26
+ "x86_64-unknown-linux-gnu",
27
+ "aarch64-unknown-linux-gnu",
28
+ "x86_64-pc-windows-msvc",
29
+ "aarch64-pc-windows-msvc"
30
+ ]
31
+ },
32
+ "scripts": {
33
+ "artifacts": "napi artifacts",
34
+ "build": "napi build --platform --release",
35
+ "build:debug": "napi build --platform",
36
+ "prepublishOnly": "napi prepublish -t npm --no-gh-release",
37
+ "docs": "typedoc",
38
+ "test": "vitest run",
39
+ "universal": "napi universal -t darwin"
40
+ },
41
+ "devDependencies": {
42
+ "@napi-rs/cli": "^3.0.0",
43
+ "@types/node": "^25.3.5",
44
+ "typedoc": "^0.28.17",
45
+ "typedoc-plugin-markdown": "^4.10.0",
46
+ "typescript": "^5.7.0",
47
+ "vitest": "^3.0.0"
48
+ },
49
+ "optionalDependencies": {
50
+ "@auths-dev/sdk-darwin-arm64": "0.1.0",
51
+ "@auths-dev/sdk-linux-x64-gnu": "0.1.0",
52
+ "@auths-dev/sdk-linux-arm64-gnu": "0.1.0",
53
+ "@auths-dev/sdk-win32-x64-msvc": "0.1.0",
54
+ "@auths-dev/sdk-win32-arm64-msvc": "0.1.0"
20
55
  }
21
- }
56
+ }