@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/errors.ts ADDED
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Base error for all Auths SDK operations.
3
+ *
4
+ * All errors thrown by the SDK inherit from this class, carrying a
5
+ * machine-readable {@link AuthsError.code | code} and human-readable
6
+ * {@link AuthsError.message | message}.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Auths, AuthsError } from '@auths-dev/sdk'
11
+ *
12
+ * try {
13
+ * auths.signAs({ message: data, identityDid: did })
14
+ * } catch (e) {
15
+ * if (e instanceof AuthsError) {
16
+ * console.log(e.code, e.message)
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export class AuthsError extends Error {
22
+ /** Machine-readable error code (e.g. `'key_not_found'`, `'invalid_signature'`). */
23
+ code: string
24
+ constructor(message: string, code: string) {
25
+ super(message)
26
+ this.name = 'AuthsError'
27
+ this.code = code
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Raised when attestation or chain verification fails.
33
+ *
34
+ * Common codes: `'invalid_signature'`, `'expired_attestation'`,
35
+ * `'revoked_device'`, `'missing_capability'`.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { verifyAttestation, VerificationError } from '@auths-dev/sdk'
40
+ *
41
+ * try {
42
+ * await verifyAttestation(json, publicKey)
43
+ * } catch (e) {
44
+ * if (e instanceof VerificationError) {
45
+ * console.log('Verification failed:', e.code)
46
+ * }
47
+ * }
48
+ * ```
49
+ */
50
+ export class VerificationError extends AuthsError {
51
+ constructor(message: string, code: string) {
52
+ super(message, code)
53
+ this.name = 'VerificationError'
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Raised when a cryptographic operation fails.
59
+ *
60
+ * Common codes: `'invalid_key'`, `'key_not_found'`, `'signing_failed'`.
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * import { Auths, CryptoError } from '@auths-dev/sdk'
65
+ *
66
+ * try {
67
+ * auths.signAs({ message: data, identityDid: did })
68
+ * } catch (e) {
69
+ * if (e instanceof CryptoError && e.code === 'key_not_found') {
70
+ * console.log('Identity key not in keychain')
71
+ * }
72
+ * }
73
+ * ```
74
+ */
75
+ export class CryptoError extends AuthsError {
76
+ constructor(message: string, code: string) {
77
+ super(message, code)
78
+ this.name = 'CryptoError'
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Raised when the platform keychain is inaccessible or locked.
84
+ *
85
+ * Common codes: `'keychain_locked'`.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * import { Auths, KeychainError } from '@auths-dev/sdk'
90
+ *
91
+ * try {
92
+ * auths.identities.create({ label: 'main' })
93
+ * } catch (e) {
94
+ * if (e instanceof KeychainError) {
95
+ * console.log('Unlock your keychain or set AUTHS_KEYCHAIN_BACKEND=file')
96
+ * }
97
+ * }
98
+ * ```
99
+ */
100
+ export class KeychainError extends AuthsError {
101
+ constructor(message: string, code: string) {
102
+ super(message, code)
103
+ this.name = 'KeychainError'
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Raised when a storage or registry operation fails.
109
+ *
110
+ * Common codes: `'repo_not_found'`, `'trust_error'`, `'witness_error'`.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * import { Auths, StorageError } from '@auths-dev/sdk'
115
+ *
116
+ * try {
117
+ * auths.trust.pin({ did: 'did:keri:ENOTREAL' })
118
+ * } catch (e) {
119
+ * if (e instanceof StorageError) {
120
+ * console.log('Storage error:', e.message)
121
+ * }
122
+ * }
123
+ * ```
124
+ */
125
+ export class StorageError extends AuthsError {
126
+ constructor(message: string, code: string) {
127
+ super(message, code)
128
+ this.name = 'StorageError'
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Raised when a network operation fails (e.g. witness communication).
134
+ *
135
+ * Common codes: `'server_error'`.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * import { NetworkError } from '@auths-dev/sdk'
140
+ *
141
+ * try {
142
+ * // network operation
143
+ * } catch (e) {
144
+ * if (e instanceof NetworkError && e.shouldRetry) {
145
+ * // safe to retry
146
+ * }
147
+ * }
148
+ * ```
149
+ */
150
+ export class NetworkError extends AuthsError {
151
+ /** Whether the operation is safe to retry. Defaults to `true`. */
152
+ shouldRetry: boolean
153
+ constructor(message: string, code: string, shouldRetry = true) {
154
+ super(message, code)
155
+ this.name = 'NetworkError'
156
+ this.shouldRetry = shouldRetry
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Raised when an identity or device operation fails.
162
+ *
163
+ * Common codes: `'identity_not_found'`, `'unknown'`.
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * import { Auths, IdentityError } from '@auths-dev/sdk'
168
+ *
169
+ * try {
170
+ * auths.devices.link({ identityDid: did, capabilities: ['sign'] })
171
+ * } catch (e) {
172
+ * if (e instanceof IdentityError) {
173
+ * console.log('Identity error:', e.code)
174
+ * }
175
+ * }
176
+ * ```
177
+ */
178
+ export class IdentityError extends AuthsError {
179
+ constructor(message: string, code: string) {
180
+ super(message, code)
181
+ this.name = 'IdentityError'
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Raised when an organization operation fails.
187
+ *
188
+ * Common codes: `'org_error'`.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { Auths, OrgError } from '@auths-dev/sdk'
193
+ *
194
+ * try {
195
+ * auths.orgs.addMember({ orgDid, memberDid, role: 'member' })
196
+ * } catch (e) {
197
+ * if (e instanceof OrgError) {
198
+ * console.log('Org error:', e.message)
199
+ * }
200
+ * }
201
+ * ```
202
+ */
203
+ export class OrgError extends AuthsError {
204
+ constructor(message: string, code: string) {
205
+ super(message, code)
206
+ this.name = 'OrgError'
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Raised when a device pairing operation fails or times out.
212
+ *
213
+ * Common codes: `'pairing_error'`, `'timeout'`.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * import { PairingError } from '@auths-dev/sdk'
218
+ *
219
+ * try {
220
+ * await auths.pairing.createSession({ bindAddress: '127.0.0.1' })
221
+ * } catch (e) {
222
+ * if (e instanceof PairingError && e.shouldRetry) {
223
+ * // safe to retry
224
+ * }
225
+ * }
226
+ * ```
227
+ */
228
+ export class PairingError extends AuthsError {
229
+ /** Whether the operation is safe to retry. Defaults to `true`. */
230
+ shouldRetry: boolean
231
+ constructor(message: string, code: string, shouldRetry = true) {
232
+ super(message, code)
233
+ this.name = 'PairingError'
234
+ this.shouldRetry = shouldRetry
235
+ }
236
+ }
237
+
238
+ const ERROR_CODE_MAP: Record<string, [string, new (message: string, code: string) => AuthsError]> = {
239
+ AUTHS_ISSUER_SIG_FAILED: ['invalid_signature', VerificationError],
240
+ AUTHS_DEVICE_SIG_FAILED: ['invalid_signature', VerificationError],
241
+ AUTHS_ATTESTATION_EXPIRED: ['expired_attestation', VerificationError],
242
+ AUTHS_ATTESTATION_REVOKED: ['revoked_device', VerificationError],
243
+ AUTHS_TIMESTAMP_IN_FUTURE: ['future_timestamp', VerificationError],
244
+ AUTHS_MISSING_CAPABILITY: ['missing_capability', VerificationError],
245
+ AUTHS_CRYPTO_ERROR: ['invalid_key', CryptoError],
246
+ AUTHS_DID_RESOLUTION_ERROR: ['invalid_key', CryptoError],
247
+ AUTHS_INVALID_INPUT: ['invalid_signature', VerificationError],
248
+ AUTHS_SERIALIZATION_ERROR: ['invalid_signature', VerificationError],
249
+ AUTHS_BUNDLE_EXPIRED: ['expired_attestation', VerificationError],
250
+ AUTHS_KEY_NOT_FOUND: ['key_not_found', CryptoError],
251
+ AUTHS_INCORRECT_PASSPHRASE: ['signing_failed', CryptoError],
252
+ AUTHS_SIGNING_FAILED: ['signing_failed', CryptoError],
253
+ AUTHS_SIGNING_ERROR: ['signing_failed', CryptoError],
254
+ AUTHS_INPUT_TOO_LARGE: ['invalid_signature', VerificationError],
255
+ AUTHS_INTERNAL_ERROR: ['unknown', VerificationError],
256
+ AUTHS_ORG_VERIFICATION_FAILED: ['invalid_signature', VerificationError],
257
+ AUTHS_ORG_ATTESTATION_EXPIRED: ['expired_attestation', VerificationError],
258
+ AUTHS_ORG_DID_RESOLUTION_FAILED: ['invalid_key', CryptoError],
259
+ AUTHS_REGISTRY_ERROR: ['repo_not_found', StorageError],
260
+ AUTHS_KEYCHAIN_ERROR: ['keychain_locked', KeychainError],
261
+ AUTHS_IDENTITY_ERROR: ['identity_not_found', IdentityError],
262
+ AUTHS_DEVICE_ERROR: ['unknown', IdentityError],
263
+ AUTHS_ROTATION_ERROR: ['unknown', IdentityError],
264
+ AUTHS_NETWORK_ERROR: ['server_error', NetworkError],
265
+ AUTHS_VERIFICATION_FAILED: ['invalid_signature', VerificationError],
266
+ AUTHS_ORG_ERROR: ['org_error', OrgError],
267
+ AUTHS_PAIRING_ERROR: ['pairing_error', PairingError],
268
+ AUTHS_PAIRING_TIMEOUT: ['timeout', PairingError],
269
+ AUTHS_TRUST_ERROR: ['trust_error', StorageError],
270
+ AUTHS_WITNESS_ERROR: ['witness_error', StorageError],
271
+ AUTHS_AUDIT_ERROR: ['audit_error', VerificationError],
272
+ AUTHS_DIAGNOSTIC_ERROR: ['diagnostic_error', VerificationError],
273
+ }
274
+
275
+ /**
276
+ * Maps a native napi-rs error into a typed {@link AuthsError} subclass.
277
+ *
278
+ * Parses the `[AUTHS_CODE] message` format emitted by the Rust layer
279
+ * and instantiates the appropriate error class with a machine-readable code.
280
+ *
281
+ * @param err - The raw error from the native binding.
282
+ * @param defaultCls - Fallback error class when the code is unrecognized.
283
+ * @returns A typed {@link AuthsError} instance.
284
+ */
285
+ export function mapNativeError(err: unknown, defaultCls: new (message: string, code: string) => AuthsError = VerificationError): AuthsError {
286
+ const msg = err instanceof Error ? err.message : String(err)
287
+
288
+ // Parse [AUTHS_CODE] prefix from native errors
289
+ if (msg.startsWith('[AUTHS_') && msg.includes('] ')) {
290
+ const code = msg.substring(1, msg.indexOf(']'))
291
+ const message = msg.substring(msg.indexOf('] ') + 2)
292
+ const mapping = ERROR_CODE_MAP[code]
293
+ if (mapping) {
294
+ const [pyCode, Cls] = mapping
295
+ return new Cls(message, pyCode)
296
+ }
297
+ }
298
+
299
+ // Fallback heuristics
300
+ const low = msg.toLowerCase()
301
+ if (low.includes('public key') || low.includes('private key') || low.includes('invalid key') || low.includes('hex')) {
302
+ return new CryptoError(msg, 'invalid_key')
303
+ }
304
+
305
+ return new defaultCls(msg, 'unknown')
306
+ }
@@ -0,0 +1,280 @@
1
+ import native from './native'
2
+ import { mapNativeError, CryptoError, IdentityError } from './errors'
3
+ import type { Auths } from './client'
4
+
5
+ /** A cryptographic identity anchored in a KERI key event log. */
6
+ export interface Identity {
7
+ /** The KERI decentralized identifier (e.g. `did:keri:EBfd...`). */
8
+ did: string
9
+ /** Keychain alias used to retrieve the signing key. */
10
+ keyAlias: string
11
+ /** Human-readable label for this identity. */
12
+ label: string
13
+ /** Path to the Git registry that stores this identity. */
14
+ repoPath: string
15
+ /** Hex-encoded Ed25519 public key. */
16
+ publicKey: string
17
+ }
18
+
19
+ /** A standalone agent identity with its self-signed attestation. */
20
+ export interface AgentIdentity {
21
+ /** The agent's KERI decentralized identifier. */
22
+ did: string
23
+ /** Keychain alias for the agent's signing key. */
24
+ keyAlias: string
25
+ /** JSON-serialized self-signed attestation. */
26
+ attestation: string
27
+ /** Hex-encoded Ed25519 public key. */
28
+ publicKey: string
29
+ }
30
+
31
+ /** An agent delegated under an existing identity. */
32
+ export interface DelegatedAgent {
33
+ /** The delegated agent's DID (typically `did:key:z...`). */
34
+ did: string
35
+ /** Keychain alias for the agent's signing key. */
36
+ keyAlias: string
37
+ /** JSON-serialized delegation attestation signed by the parent identity. */
38
+ attestation: string
39
+ /** Hex-encoded Ed25519 public key. */
40
+ publicKey: string
41
+ }
42
+
43
+ /** Result of a key rotation operation. */
44
+ export interface RotationResult {
45
+ /** The controller DID whose keys were rotated. */
46
+ controllerDid: string
47
+ /** Fingerprint of the new signing key. */
48
+ newKeyFingerprint: string
49
+ /** Fingerprint of the previous signing key. */
50
+ previousKeyFingerprint: string
51
+ /** New KERI event sequence number after rotation. */
52
+ sequence: number
53
+ }
54
+
55
+ /** Options for {@link IdentityService.create}. */
56
+ export interface CreateIdentityOptions {
57
+ /** Human-readable label. Defaults to `'main'`. */
58
+ label?: string
59
+ /** Override the client's repo path. */
60
+ repoPath?: string
61
+ /** Override the client's passphrase. */
62
+ passphrase?: string
63
+ }
64
+
65
+ /** Options for {@link IdentityService.createAgent}. */
66
+ export interface CreateAgentOptions {
67
+ /** Name for the agent identity. */
68
+ name: string
69
+ /** Capabilities to grant (e.g. `['sign']`). */
70
+ capabilities: string[]
71
+ /** Override the client's passphrase. */
72
+ passphrase?: string
73
+ }
74
+
75
+ /** Options for {@link IdentityService.delegateAgent}. */
76
+ export interface DelegateAgentOptions {
77
+ /** DID of the parent identity that delegates authority. */
78
+ identityDid: string
79
+ /** Name for the delegated agent. */
80
+ name: string
81
+ /** Capabilities to grant (e.g. `['sign']`). */
82
+ capabilities: string[]
83
+ /** Optional expiration in days. */
84
+ expiresInDays?: number
85
+ /** Override the client's passphrase. */
86
+ passphrase?: string
87
+ }
88
+
89
+ /** Options for {@link IdentityService.rotate}. */
90
+ export interface RotateKeysOptions {
91
+ /** DID of the identity to rotate. Defaults to the primary identity. */
92
+ identityDid?: string
93
+ /** Override the client's passphrase. */
94
+ passphrase?: string
95
+ }
96
+
97
+ /** Options for {@link IdentityService.getPublicKey}. */
98
+ export interface GetPublicKeyOptions {
99
+ /** DID of the identity whose public key to retrieve. */
100
+ identityDid: string
101
+ /** Override the client's passphrase. */
102
+ passphrase?: string
103
+ }
104
+
105
+ /**
106
+ * Manages cryptographic identities, agents, and key rotation.
107
+ *
108
+ * Access via {@link Auths.identities}.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const auths = new Auths()
113
+ * const identity = auths.identities.create({ label: 'laptop' })
114
+ * console.log(identity.did) // did:keri:EBfd...
115
+ * ```
116
+ */
117
+ export class IdentityService {
118
+ constructor(private client: Auths) {}
119
+
120
+ /**
121
+ * Creates a new cryptographic identity backed by an Ed25519 keypair.
122
+ *
123
+ * @param opts - Creation options.
124
+ * @returns The newly created identity.
125
+ * @throws {@link IdentityError} if the identity cannot be created.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const identity = auths.identities.create({ label: 'laptop' })
130
+ * console.log(identity.did) // did:keri:EBfd...
131
+ * console.log(identity.publicKey) // hex-encoded Ed25519 key
132
+ * ```
133
+ */
134
+ create(opts: CreateIdentityOptions = {}): Identity {
135
+ const rp = opts.repoPath ?? this.client.repoPath
136
+ const pp = opts.passphrase ?? this.client.passphrase
137
+ try {
138
+ const result = native.createIdentity(opts.label ?? 'main', rp, pp)
139
+ return {
140
+ did: result.did,
141
+ keyAlias: result.keyAlias,
142
+ label: opts.label ?? 'main',
143
+ repoPath: rp,
144
+ publicKey: result.publicKeyHex,
145
+ }
146
+ } catch (err) {
147
+ throw mapNativeError(err, IdentityError)
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Creates a standalone agent identity with a self-signed attestation.
153
+ *
154
+ * @param opts - Agent creation options.
155
+ * @returns The agent identity with its attestation.
156
+ * @throws {@link IdentityError} if the agent cannot be created.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const agent = auths.identities.createAgent({
161
+ * name: 'ci-bot',
162
+ * capabilities: ['sign'],
163
+ * })
164
+ * console.log(agent.did) // did:keri:...
165
+ * ```
166
+ */
167
+ createAgent(opts: CreateAgentOptions): AgentIdentity {
168
+ const pp = opts.passphrase ?? this.client.passphrase
169
+ try {
170
+ const bundle = native.createAgentIdentity(
171
+ opts.name,
172
+ opts.capabilities,
173
+ this.client.repoPath,
174
+ pp,
175
+ )
176
+ return {
177
+ did: bundle.agentDid,
178
+ keyAlias: bundle.keyAlias,
179
+ attestation: bundle.attestationJson,
180
+ publicKey: bundle.publicKeyHex,
181
+ }
182
+ } catch (err) {
183
+ throw mapNativeError(err, IdentityError)
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Delegates an agent under an existing identity with scoped capabilities.
189
+ *
190
+ * @param opts - Delegation options.
191
+ * @returns The delegated agent with its signed attestation.
192
+ * @throws {@link IdentityError} if delegation fails.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const agent = auths.identities.delegateAgent({
197
+ * identityDid: identity.did,
198
+ * name: 'deploy-bot',
199
+ * capabilities: ['sign'],
200
+ * expiresInDays: 90,
201
+ * })
202
+ * ```
203
+ */
204
+ delegateAgent(opts: DelegateAgentOptions): DelegatedAgent {
205
+ const pp = opts.passphrase ?? this.client.passphrase
206
+ try {
207
+ const bundle = native.delegateAgent(
208
+ opts.name,
209
+ opts.capabilities,
210
+ this.client.repoPath,
211
+ pp,
212
+ opts.expiresInDays ?? null,
213
+ opts.identityDid,
214
+ )
215
+ return {
216
+ did: bundle.agentDid,
217
+ keyAlias: bundle.keyAlias,
218
+ attestation: bundle.attestationJson,
219
+ publicKey: bundle.publicKeyHex,
220
+ }
221
+ } catch (err) {
222
+ throw mapNativeError(err, IdentityError)
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Rotates the signing keys for an identity, advancing the KERI event log.
228
+ *
229
+ * @param opts - Rotation options.
230
+ * @returns The rotation result with old and new key fingerprints.
231
+ * @throws {@link IdentityError} if rotation fails.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const result = auths.identities.rotate({ identityDid: identity.did })
236
+ * console.log(result.sequence) // incremented sequence number
237
+ * ```
238
+ */
239
+ rotate(opts: RotateKeysOptions = {}): RotationResult {
240
+ const pp = opts.passphrase ?? this.client.passphrase
241
+ try {
242
+ const result = native.rotateIdentityKeys(
243
+ this.client.repoPath,
244
+ opts.identityDid ?? null,
245
+ null,
246
+ pp,
247
+ )
248
+ return {
249
+ controllerDid: result.controllerDid,
250
+ newKeyFingerprint: result.newKeyFingerprint,
251
+ previousKeyFingerprint: result.previousKeyFingerprint,
252
+ sequence: result.sequence,
253
+ }
254
+ } catch (err) {
255
+ throw mapNativeError(err, IdentityError)
256
+ }
257
+ }
258
+
259
+ /**
260
+ * Retrieves the hex-encoded Ed25519 public key for an identity.
261
+ *
262
+ * @param opts - Lookup options.
263
+ * @returns Hex-encoded public key string (64 characters).
264
+ * @throws {@link CryptoError} if the key cannot be found.
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * const pk = auths.identities.getPublicKey({ identityDid: identity.did })
269
+ * console.log(pk.length) // 64
270
+ * ```
271
+ */
272
+ getPublicKey(opts: GetPublicKeyOptions): string {
273
+ const pp = opts.passphrase ?? this.client.passphrase
274
+ try {
275
+ return native.getIdentityPublicKey(opts.identityDid, this.client.repoPath, pp)
276
+ } catch (err) {
277
+ throw mapNativeError(err, CryptoError)
278
+ }
279
+ }
280
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,125 @@
1
+ export { Auths, type ClientConfig, type VerifyOptions, type VerifyChainOptions } from './client'
2
+ export {
3
+ IdentityService,
4
+ type Identity,
5
+ type AgentIdentity,
6
+ type DelegatedAgent,
7
+ type RotationResult,
8
+ type CreateIdentityOptions,
9
+ type CreateAgentOptions,
10
+ type DelegateAgentOptions,
11
+ type RotateKeysOptions,
12
+ type GetPublicKeyOptions,
13
+ } from './identity'
14
+ export {
15
+ DeviceService,
16
+ type Device,
17
+ type DeviceExtension,
18
+ type LinkDeviceOptions,
19
+ type RevokeDeviceOptions,
20
+ type ExtendDeviceOptions,
21
+ } from './devices'
22
+ export {
23
+ SigningService,
24
+ type SignResult,
25
+ type ActionEnvelope,
26
+ type SignAsIdentityOptions,
27
+ type SignActionAsIdentityOptions,
28
+ type SignAsAgentOptions,
29
+ type SignActionAsAgentOptions,
30
+ } from './signing'
31
+ export {
32
+ OrgService,
33
+ isAdmin,
34
+ type OrgResult,
35
+ type OrgMember,
36
+ type CreateOrgOptions,
37
+ type AddOrgMemberOptions,
38
+ type RevokeOrgMemberOptions,
39
+ type ListOrgMembersOptions,
40
+ } from './org'
41
+ export { TrustService, TrustLevel, type PinnedIdentity, type PinIdentityOptions } from './trust'
42
+ export { WitnessService, type WitnessEntry, type AddWitnessOptions } from './witness'
43
+ export { AttestationService, type AttestationInfo } from './attestations'
44
+ export {
45
+ ArtifactService,
46
+ type ArtifactResult,
47
+ type SignArtifactOptions,
48
+ type SignArtifactBytesOptions,
49
+ } from './artifacts'
50
+ export { CommitService, type CommitSignResult, type SignCommitOptions } from './commits'
51
+ export {
52
+ AuditService,
53
+ parseIdentityBundle,
54
+ parseIdentityBundleInfo,
55
+ type AuditReport,
56
+ type AuditCommit,
57
+ type AuditSummary,
58
+ type AuditReportOptions,
59
+ type AuditComplianceOptions,
60
+ type IdentityBundleInfo,
61
+ } from './audit'
62
+ export {
63
+ PolicyBuilder,
64
+ Outcome,
65
+ ReasonCode,
66
+ compilePolicy,
67
+ evaluatePolicy,
68
+ evalContextFromCommitResult,
69
+ type PolicyDecision,
70
+ type EvalContextOpts,
71
+ type CommitResultLike,
72
+ } from './policy'
73
+ export {
74
+ PairingService,
75
+ type PairingSession,
76
+ type PairingResponse,
77
+ type PairingResult,
78
+ type CreatePairingSessionOptions,
79
+ type WaitForPairingResponseOptions,
80
+ type JoinPairingOptions,
81
+ type CompletePairingOptions,
82
+ } from './pairing'
83
+ export {
84
+ verifyAttestation,
85
+ verifyAttestationWithCapability,
86
+ verifyChain,
87
+ verifyChainWithCapability,
88
+ verifyDeviceAuthorization,
89
+ verifyAtTime,
90
+ verifyAtTimeWithCapability,
91
+ verifyChainWithWitnesses,
92
+ type VerificationResult,
93
+ type VerificationReport,
94
+ type VerificationStatus,
95
+ type ChainLink,
96
+ type WitnessConfig,
97
+ type WitnessKey,
98
+ } from './verify'
99
+ export {
100
+ AuthsError,
101
+ VerificationError,
102
+ CryptoError,
103
+ KeychainError,
104
+ StorageError,
105
+ NetworkError,
106
+ IdentityError,
107
+ OrgError,
108
+ PairingError,
109
+ mapNativeError,
110
+ } from './errors'
111
+
112
+ export {
113
+ parseIdentityDid,
114
+ parseDeviceDid,
115
+ SignerType,
116
+ Role,
117
+ WellKnownCapability,
118
+ type IdentityDID,
119
+ type DeviceDID,
120
+ type BundleAttestation,
121
+ type IdentityBundle,
122
+ } from './types'
123
+
124
+ import native from './native'
125
+ export const version: () => string = native.version