@bsv/sdk 1.2.20 → 1.2.22

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 (160) hide show
  1. package/dist/cjs/package.json +3 -3
  2. package/dist/cjs/src/auth/Peer.js +536 -0
  3. package/dist/cjs/src/auth/Peer.js.map +1 -0
  4. package/dist/cjs/src/auth/SessionManager.js +66 -0
  5. package/dist/cjs/src/auth/SessionManager.js.map +1 -0
  6. package/dist/cjs/src/auth/{Certificate.js → certificates/Certificate.js} +22 -26
  7. package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -0
  8. package/dist/cjs/src/auth/certificates/MasterCertificate.js +79 -0
  9. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -0
  10. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +49 -0
  11. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -0
  12. package/dist/cjs/src/auth/certificates/index.js +25 -0
  13. package/dist/cjs/src/auth/certificates/index.js.map +1 -0
  14. package/dist/cjs/src/auth/clients/AuthFetch.js +411 -0
  15. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -0
  16. package/dist/cjs/src/auth/clients/index.js +18 -0
  17. package/dist/cjs/src/auth/clients/index.js.map +1 -0
  18. package/dist/cjs/src/auth/index.js +20 -5
  19. package/dist/cjs/src/auth/index.js.map +1 -1
  20. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +259 -0
  21. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -0
  22. package/dist/cjs/src/auth/transports/index.js +18 -0
  23. package/dist/cjs/src/auth/transports/index.js.map +1 -0
  24. package/dist/cjs/src/auth/types.js +3 -0
  25. package/dist/cjs/src/auth/types.js.map +1 -0
  26. package/dist/cjs/src/auth/utils/certificateHelpers.js +51 -0
  27. package/dist/cjs/src/auth/utils/certificateHelpers.js.map +1 -0
  28. package/dist/cjs/src/auth/utils/createNonce.js +19 -0
  29. package/dist/cjs/src/auth/utils/createNonce.js.map +1 -0
  30. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js +31 -0
  31. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -0
  32. package/dist/cjs/src/auth/utils/index.js +22 -0
  33. package/dist/cjs/src/auth/utils/index.js.map +1 -0
  34. package/dist/cjs/src/auth/utils/validateCertificates.js +42 -0
  35. package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -0
  36. package/dist/cjs/src/auth/utils/verifyNonce.js +27 -0
  37. package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -0
  38. package/dist/cjs/src/primitives/Point.js +1 -1
  39. package/dist/cjs/src/primitives/Point.js.map +1 -1
  40. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +1 -1
  41. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  42. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +148 -148
  43. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  44. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  45. package/dist/esm/src/auth/Peer.js +533 -0
  46. package/dist/esm/src/auth/Peer.js.map +1 -0
  47. package/dist/esm/src/auth/SessionManager.js +63 -0
  48. package/dist/esm/src/auth/SessionManager.js.map +1 -0
  49. package/dist/esm/src/auth/{Certificate.js → certificates/Certificate.js} +1 -2
  50. package/dist/esm/src/auth/certificates/Certificate.js.map +1 -0
  51. package/dist/esm/src/auth/certificates/MasterCertificate.js +73 -0
  52. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -0
  53. package/dist/esm/src/auth/certificates/VerifiableCertificate.js +44 -0
  54. package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -0
  55. package/dist/esm/src/auth/certificates/index.js +4 -0
  56. package/dist/esm/src/auth/certificates/index.js.map +1 -0
  57. package/dist/esm/src/auth/clients/AuthFetch.js +409 -0
  58. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -0
  59. package/dist/esm/src/auth/clients/index.js +2 -0
  60. package/dist/esm/src/auth/clients/index.js.map +1 -0
  61. package/dist/esm/src/auth/index.js +7 -1
  62. package/dist/esm/src/auth/index.js.map +1 -1
  63. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +258 -0
  64. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -0
  65. package/dist/esm/src/auth/transports/index.js +2 -0
  66. package/dist/esm/src/auth/transports/index.js.map +1 -0
  67. package/dist/esm/src/auth/types.js +2 -0
  68. package/dist/esm/src/auth/types.js.map +1 -0
  69. package/dist/esm/src/auth/utils/certificateHelpers.js +47 -0
  70. package/dist/esm/src/auth/utils/certificateHelpers.js.map +1 -0
  71. package/dist/esm/src/auth/utils/createNonce.js +16 -0
  72. package/dist/esm/src/auth/utils/createNonce.js.map +1 -0
  73. package/dist/esm/src/auth/utils/getVerifiableCertificates.js +27 -0
  74. package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -0
  75. package/dist/esm/src/auth/utils/index.js +6 -0
  76. package/dist/esm/src/auth/utils/index.js.map +1 -0
  77. package/dist/esm/src/auth/utils/validateCertificates.js +38 -0
  78. package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -0
  79. package/dist/esm/src/auth/utils/verifyNonce.js +24 -0
  80. package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -0
  81. package/dist/esm/src/primitives/Point.js +1 -1
  82. package/dist/esm/src/primitives/Point.js.map +1 -1
  83. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +1 -1
  84. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  85. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +1 -1
  86. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  87. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  88. package/dist/types/src/auth/Peer.d.ts +193 -0
  89. package/dist/types/src/auth/Peer.d.ts.map +1 -0
  90. package/dist/types/src/auth/SessionManager.d.ts +42 -0
  91. package/dist/types/src/auth/SessionManager.d.ts.map +1 -0
  92. package/dist/types/src/auth/{Certificate.d.ts → certificates/Certificate.d.ts} +1 -1
  93. package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -0
  94. package/dist/types/src/auth/certificates/MasterCertificate.d.ts +38 -0
  95. package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -0
  96. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +26 -0
  97. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -0
  98. package/dist/types/src/auth/certificates/index.d.ts +4 -0
  99. package/dist/types/src/auth/certificates/index.d.ts.map +1 -0
  100. package/dist/types/src/auth/clients/AuthFetch.d.ts +87 -0
  101. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -0
  102. package/dist/types/src/auth/clients/index.d.ts +2 -0
  103. package/dist/types/src/auth/clients/index.d.ts.map +1 -0
  104. package/dist/types/src/auth/index.d.ts +7 -1
  105. package/dist/types/src/auth/index.d.ts.map +1 -1
  106. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts +51 -0
  107. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -0
  108. package/dist/types/src/auth/transports/index.d.ts +2 -0
  109. package/dist/types/src/auth/transports/index.d.ts.map +1 -0
  110. package/dist/types/src/auth/types.d.ts +31 -0
  111. package/dist/types/src/auth/types.d.ts.map +1 -0
  112. package/dist/types/src/auth/utils/certificateHelpers.d.ts +26 -0
  113. package/dist/types/src/auth/utils/certificateHelpers.d.ts.map +1 -0
  114. package/dist/types/src/auth/utils/createNonce.d.ts +8 -0
  115. package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -0
  116. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +13 -0
  117. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -0
  118. package/dist/types/src/auth/utils/index.d.ts +6 -0
  119. package/dist/types/src/auth/utils/index.d.ts.map +1 -0
  120. package/dist/types/src/auth/utils/validateCertificates.d.ts +12 -0
  121. package/dist/types/src/auth/utils/validateCertificates.d.ts.map +1 -0
  122. package/dist/types/src/auth/utils/verifyNonce.d.ts +9 -0
  123. package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -0
  124. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  125. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  126. package/dist/umd/bundle.js +1 -1
  127. package/docs/README.md +1 -0
  128. package/docs/auth.md +1193 -0
  129. package/package.json +13 -3
  130. package/src/auth/Peer.ts +600 -0
  131. package/src/auth/SessionManager.ts +71 -0
  132. package/src/auth/__tests/Peer.test.ts +599 -0
  133. package/src/auth/__tests/SessionManager.test.ts +87 -0
  134. package/src/auth/{Certificate.ts → certificates/Certificate.ts} +15 -8
  135. package/src/auth/certificates/MasterCertificate.ts +106 -0
  136. package/src/auth/certificates/VerifiableCertificate.ts +73 -0
  137. package/src/auth/certificates/__tests/Certificate.test.ts +282 -0
  138. package/src/auth/certificates/index.ts +3 -0
  139. package/src/auth/clients/AuthFetch.ts +482 -0
  140. package/src/auth/clients/index.ts +1 -0
  141. package/src/auth/index.ts +7 -1
  142. package/src/auth/transports/SimplifiedFetchTransport.ts +288 -0
  143. package/src/auth/transports/index.ts +1 -0
  144. package/src/auth/types.ts +41 -0
  145. package/src/auth/utils/__tests/cryptononce.test.ts +84 -0
  146. package/src/auth/utils/__tests/getVerifiableCertificates.test.ts +126 -0
  147. package/src/auth/utils/__tests/validateCertificates.test.ts +142 -0
  148. package/src/auth/utils/certificateHelpers.ts +86 -0
  149. package/src/auth/utils/createNonce.ts +16 -0
  150. package/src/auth/utils/getVerifiableCertificates.ts +40 -0
  151. package/src/auth/utils/index.ts +5 -0
  152. package/src/auth/utils/validateCertificates.ts +54 -0
  153. package/src/auth/utils/verifyNonce.ts +27 -0
  154. package/src/primitives/Point.ts +59 -59
  155. package/src/wallet/substrates/WalletWireProcessor.ts +1 -1
  156. package/src/wallet/substrates/WalletWireTransceiver.ts +1 -1
  157. package/dist/cjs/src/auth/Certificate.js.map +0 -1
  158. package/dist/esm/src/auth/Certificate.js.map +0 -1
  159. package/dist/types/src/auth/Certificate.d.ts.map +0 -1
  160. package/src/auth/__tests/Certificate.test.ts +0 -282
package/docs/auth.md ADDED
@@ -0,0 +1,1193 @@
1
+ # API
2
+
3
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
4
+
5
+ ## Interfaces
6
+
7
+ | |
8
+ | --- |
9
+ | [AuthMessage](#interface-authmessage) |
10
+ | [PeerSession](#interface-peersession) |
11
+ | [RequestedCertificateSet](#interface-requestedcertificateset) |
12
+ | [RequestedCertificateTypeIDAndFieldList](#interface-requestedcertificatetypeidandfieldlist) |
13
+ | [Transport](#interface-transport) |
14
+
15
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
16
+
17
+ ---
18
+
19
+ ### Interface: AuthMessage
20
+
21
+ ```ts
22
+ export interface AuthMessage {
23
+ version: string;
24
+ messageType: "initialRequest" | "initialResponse" | "certificateRequest" | "certificateResponse" | "general";
25
+ identityKey: string;
26
+ nonce?: string;
27
+ initialNonce?: string;
28
+ yourNonce?: string;
29
+ certificates?: VerifiableCertificate[];
30
+ requestedCertificates?: RequestedCertificateSet;
31
+ payload?: number[];
32
+ signature?: number[];
33
+ }
34
+ ```
35
+
36
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [VerifiableCertificate](#class-verifiablecertificate)
37
+
38
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
39
+
40
+ ---
41
+ ### Interface: PeerSession
42
+
43
+ ```ts
44
+ export interface PeerSession {
45
+ isAuthenticated: boolean;
46
+ sessionNonce?: string;
47
+ peerNonce?: string;
48
+ peerIdentityKey?: string;
49
+ }
50
+ ```
51
+
52
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
53
+
54
+ ---
55
+ ### Interface: RequestedCertificateSet
56
+
57
+ ```ts
58
+ export interface RequestedCertificateSet {
59
+ certifiers: string[];
60
+ types: RequestedCertificateTypeIDAndFieldList;
61
+ }
62
+ ```
63
+
64
+ See also: [RequestedCertificateTypeIDAndFieldList](#interface-requestedcertificatetypeidandfieldlist)
65
+
66
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
67
+
68
+ ---
69
+ ### Interface: RequestedCertificateTypeIDAndFieldList
70
+
71
+ ```ts
72
+ export interface RequestedCertificateTypeIDAndFieldList {
73
+ [certificateTypeID: string]: string[];
74
+ }
75
+ ```
76
+
77
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
78
+
79
+ ---
80
+ ### Interface: Transport
81
+
82
+ ```ts
83
+ export interface Transport {
84
+ send: (message: AuthMessage) => Promise<void>;
85
+ onData: (callback: (message: AuthMessage) => Promise<void>) => Promise<void>;
86
+ }
87
+ ```
88
+
89
+ See also: [AuthMessage](#interface-authmessage)
90
+
91
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
92
+
93
+ ---
94
+ ## Classes
95
+
96
+ | |
97
+ | --- |
98
+ | [AuthFetch](#class-authfetch) |
99
+ | [Certificate](#class-certificate) |
100
+ | [MasterCertificate](#class-mastercertificate) |
101
+ | [Peer](#class-peer) |
102
+ | [SessionManager](#class-sessionmanager) |
103
+ | [SimplifiedFetchTransport](#class-simplifiedfetchtransport) |
104
+ | [VerifiableCertificate](#class-verifiablecertificate) |
105
+
106
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
107
+
108
+ ---
109
+
110
+ ### Class: AuthFetch
111
+
112
+ AuthFetch provides a lightweight fetch client for interacting with servers
113
+ over a simplified HTTP transport mechanism. It integrates session management, peer communication,
114
+ and certificate handling to enable secure and mutually-authenticated requests.
115
+
116
+ Additionally, it automatically handles 402 Payment Required responses by creating
117
+ and sending BSV payment transactions when necessary.
118
+
119
+ ```ts
120
+ export class AuthFetch {
121
+ peers: Record<string, AuthPeer> = {};
122
+ constructor(wallet: Wallet, requestedCertificates?: RequestedCertificateSet, sessionManager?: SessionManager)
123
+ async fetch(url: string, config: SimplifiedFetchRequestOptions = {}): Promise<Response>
124
+ async sendCertificateRequest(baseUrl: string, certificatesToRequest: RequestedCertificateSet): Promise<VerifiableCertificate[]>
125
+ public consumeReceivedCertificates(): VerifiableCertificate[]
126
+ }
127
+ ```
128
+
129
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [SessionManager](#class-sessionmanager), [VerifiableCertificate](#class-verifiablecertificate), [Wallet](#interface-wallet)
130
+
131
+ <details>
132
+
133
+ <summary>Class AuthFetch Details</summary>
134
+
135
+ #### Constructor
136
+
137
+ Constructs a new SimplifiedFetch instance.
138
+
139
+ ```ts
140
+ constructor(wallet: Wallet, requestedCertificates?: RequestedCertificateSet, sessionManager?: SessionManager)
141
+ ```
142
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [SessionManager](#class-sessionmanager), [Wallet](#interface-wallet)
143
+
144
+ Argument Details
145
+
146
+ + **wallet**
147
+ + The wallet instance for signing and authentication.
148
+ + **requestedCertificates**
149
+ + Optional set of certificates to request from peers.
150
+
151
+ #### Method consumeReceivedCertificates
152
+
153
+ Return any certificates we've collected thus far, then clear them out.
154
+
155
+ ```ts
156
+ public consumeReceivedCertificates(): VerifiableCertificate[]
157
+ ```
158
+ See also: [VerifiableCertificate](#class-verifiablecertificate)
159
+
160
+ #### Method fetch
161
+
162
+ Mutually authenticates and sends a HTTP request to a server.
163
+
164
+ 1) Attempt the request.
165
+ 2) If 402 Payment Required, automatically create and send payment.
166
+ 3) Return the final response.
167
+
168
+ ```ts
169
+ async fetch(url: string, config: SimplifiedFetchRequestOptions = {}): Promise<Response>
170
+ ```
171
+
172
+ Returns
173
+
174
+ A promise that resolves with the server's response, structured as a Response-like object.
175
+
176
+ Argument Details
177
+
178
+ + **url**
179
+ + The URL to send the request to.
180
+ + **config**
181
+ + Configuration options for the request, including method, headers, and body.
182
+
183
+ Throws
184
+
185
+ Will throw an error if unsupported headers are used or other validation fails.
186
+
187
+ #### Method sendCertificateRequest
188
+
189
+ Request Certificates from a Peer
190
+
191
+ ```ts
192
+ async sendCertificateRequest(baseUrl: string, certificatesToRequest: RequestedCertificateSet): Promise<VerifiableCertificate[]>
193
+ ```
194
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [VerifiableCertificate](#class-verifiablecertificate)
195
+
196
+ </details>
197
+
198
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
199
+
200
+ ---
201
+ ### Class: Certificate
202
+
203
+ Represents an Identity Certificate as per the Wallet interface specifications.
204
+
205
+ This class provides methods to serialize and deserialize certificates, as well as signing and verifying the certificate's signature.
206
+
207
+ ```ts
208
+ export default class Certificate {
209
+ type: Base64String;
210
+ serialNumber: Base64String;
211
+ subject: PubKeyHex;
212
+ certifier: PubKeyHex;
213
+ revocationOutpoint: OutpointString;
214
+ fields: Record<CertificateFieldNameUnder50Bytes, string>;
215
+ signature?: HexString;
216
+ constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString)
217
+ toBin(includeSignature: boolean = true): number[]
218
+ static fromBin(bin: number[]): Certificate
219
+ async verify(): Promise<boolean>
220
+ async sign(certifier: Wallet): Promise<void>
221
+ }
222
+ ```
223
+
224
+ See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [PubKeyHex](#type-pubkeyhex), [Wallet](#interface-wallet), [sign](#variable-sign), [verify](#variable-verify)
225
+
226
+ <details>
227
+
228
+ <summary>Class Certificate Details</summary>
229
+
230
+ #### Constructor
231
+
232
+ Constructs a new Certificate.
233
+
234
+ ```ts
235
+ constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString)
236
+ ```
237
+ See also: [Base64String](#type-base64string), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [PubKeyHex](#type-pubkeyhex)
238
+
239
+ Argument Details
240
+
241
+ + **type**
242
+ + Type identifier for the certificate, base64 encoded string, 32 bytes.
243
+ + **serialNumber**
244
+ + Unique serial number of the certificate, base64 encoded string, 32 bytes.
245
+ + **subject**
246
+ + The public key belonging to the certificate's subject, compressed public key hex string.
247
+ + **certifier**
248
+ + Public key of the certifier who issued the certificate, compressed public key hex string.
249
+ + **revocationOutpoint**
250
+ + The outpoint used to confirm that the certificate has not been revoked (TXID.OutputIndex), as a string.
251
+ + **fields**
252
+ + All the fields present in the certificate.
253
+ + **signature**
254
+ + Certificate signature by the certifier's private key, DER encoded hex string.
255
+
256
+ #### Property certifier
257
+
258
+ Public key of the certifier who issued the certificate, compressed public key hex string.
259
+
260
+ ```ts
261
+ certifier: PubKeyHex
262
+ ```
263
+ See also: [PubKeyHex](#type-pubkeyhex)
264
+
265
+ #### Property fields
266
+
267
+ All the fields present in the certificate, with field names as keys and field values as strings.
268
+
269
+ ```ts
270
+ fields: Record<CertificateFieldNameUnder50Bytes, string>
271
+ ```
272
+ See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes)
273
+
274
+ #### Property revocationOutpoint
275
+
276
+ The outpoint used to confirm that the certificate has not been revoked (TXID.OutputIndex), as a string.
277
+
278
+ ```ts
279
+ revocationOutpoint: OutpointString
280
+ ```
281
+ See also: [OutpointString](#type-outpointstring)
282
+
283
+ #### Property serialNumber
284
+
285
+ Unique serial number of the certificate, base64 encoded string, 32 bytes.
286
+
287
+ ```ts
288
+ serialNumber: Base64String
289
+ ```
290
+ See also: [Base64String](#type-base64string)
291
+
292
+ #### Property signature
293
+
294
+ Certificate signature by the certifier's private key, DER encoded hex string.
295
+
296
+ ```ts
297
+ signature?: HexString
298
+ ```
299
+ See also: [HexString](#type-hexstring)
300
+
301
+ #### Property subject
302
+
303
+ The public key belonging to the certificate's subject, compressed public key hex string.
304
+
305
+ ```ts
306
+ subject: PubKeyHex
307
+ ```
308
+ See also: [PubKeyHex](#type-pubkeyhex)
309
+
310
+ #### Property type
311
+
312
+ Type identifier for the certificate, base64 encoded string, 32 bytes.
313
+
314
+ ```ts
315
+ type: Base64String
316
+ ```
317
+ See also: [Base64String](#type-base64string)
318
+
319
+ #### Method fromBin
320
+
321
+ Deserializes a certificate from binary format.
322
+
323
+ ```ts
324
+ static fromBin(bin: number[]): Certificate
325
+ ```
326
+ See also: [Certificate](#class-certificate)
327
+
328
+ Returns
329
+
330
+ - The deserialized Certificate object.
331
+
332
+ Argument Details
333
+
334
+ + **bin**
335
+ + The binary data representing the certificate.
336
+
337
+ #### Method sign
338
+
339
+ Signs the certificate using the provided certifier wallet.
340
+
341
+ ```ts
342
+ async sign(certifier: Wallet): Promise<void>
343
+ ```
344
+ See also: [Wallet](#interface-wallet)
345
+
346
+ Argument Details
347
+
348
+ + **certifier**
349
+ + The wallet representing the certifier.
350
+
351
+ #### Method toBin
352
+
353
+ Serializes the certificate into binary format, with or without a signature.
354
+
355
+ ```ts
356
+ toBin(includeSignature: boolean = true): number[]
357
+ ```
358
+
359
+ Returns
360
+
361
+ - The serialized certificate in binary format.
362
+
363
+ Argument Details
364
+
365
+ + **includeSignature**
366
+ + Whether to include the signature in the serialization.
367
+
368
+ #### Method verify
369
+
370
+ Verifies the certificate's signature.
371
+
372
+ ```ts
373
+ async verify(): Promise<boolean>
374
+ ```
375
+
376
+ Returns
377
+
378
+ - A promise that resolves to true if the signature is valid.
379
+
380
+ </details>
381
+
382
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
383
+
384
+ ---
385
+ ### Class: MasterCertificate
386
+
387
+ MasterCertificate extends the base Certificate class to manage a master keyring, enabling the creation of verifiable certificates.
388
+
389
+ It allows for the selective disclosure of certificate fields by creating a `VerifiableCertificate` for a specific verifier.
390
+ The `MasterCertificate` can securely decrypt each master key and re-encrypt it for a verifier, creating a customized
391
+ keyring containing only the keys necessary for the verifier to access designated fields.
392
+
393
+ ```ts
394
+ export class MasterCertificate extends Certificate {
395
+ declare type: Base64String;
396
+ declare serialNumber: Base64String;
397
+ declare subject: PubKeyHex;
398
+ declare certifier: PubKeyHex;
399
+ declare revocationOutpoint: OutpointString;
400
+ declare fields: Record<CertificateFieldNameUnder50Bytes, string>;
401
+ declare signature?: HexString;
402
+ masterKeyring: Record<CertificateFieldNameUnder50Bytes, string>;
403
+ constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, masterKeyring: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString)
404
+ async createKeyringForVerifier(subjectWallet: Wallet, verifierIdentityKey: string, fieldsToReveal: string[], originator?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
405
+ }
406
+ ```
407
+
408
+ See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [PubKeyHex](#type-pubkeyhex), [Wallet](#interface-wallet)
409
+
410
+ <details>
411
+
412
+ <summary>Class MasterCertificate Details</summary>
413
+
414
+ #### Method createKeyringForVerifier
415
+
416
+ Creates a verifiable certificate structure for a specific verifier, allowing them access to specified fields.
417
+ This method decrypts the master field keys for each field specified in `fieldsToReveal` and re-encrypts them
418
+ for the verifier's identity key. The resulting certificate structure includes only the fields intended to be
419
+ revealed and a verifier-specific keyring for field decryption.
420
+
421
+ ```ts
422
+ async createKeyringForVerifier(subjectWallet: Wallet, verifierIdentityKey: string, fieldsToReveal: string[], originator?: string): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
423
+ ```
424
+ See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [Wallet](#interface-wallet)
425
+
426
+ Returns
427
+
428
+ - A new certificate structure containing the original encrypted fields, the verifier-specific field decryption keyring, and essential certificate metadata.
429
+
430
+ Argument Details
431
+
432
+ + **subjectWallet**
433
+ + The wallet instance of the subject, used to decrypt and re-encrypt field keys.
434
+ + **verifierIdentityKey**
435
+ + The public identity key of the verifier who will receive access to the specified fields.
436
+ + **fieldsToReveal**
437
+ + An array of field names to be revealed to the verifier. Must be a subset of the certificate's fields.
438
+ + **originator**
439
+ + Optional originator identifier, used if additional context is needed for decryption and encryption operations.
440
+
441
+ Throws
442
+
443
+ Throws an error if:
444
+ - fieldsToReveal is empty or a field in `fieldsToReveal` does not exist in the certificate.
445
+ - The decrypted master field key fails to decrypt the corresponding field (indicating an invalid key).
446
+
447
+ </details>
448
+
449
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
450
+
451
+ ---
452
+ ### Class: Peer
453
+
454
+ Represents a peer capable of performing mutual authentication.
455
+ Manages sessions, handles authentication handshakes, certificate requests and responses,
456
+ and sending and receiving general messages over a transport layer.
457
+
458
+ ```ts
459
+ export class Peer {
460
+ public sessionManager: SessionManager;
461
+ certificatesToRequest: RequestedCertificateSet;
462
+ constructor(wallet: Wallet, transport: Transport, certificatesToRequest?: RequestedCertificateSet, sessionManager?: SessionManager)
463
+ async toPeer(message: number[], identityKey?: string, maxWaitTime?: number): Promise<void>
464
+ async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void>
465
+ async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession>
466
+ listenForGeneralMessages(callback: (senderPublicKey: string, payload: number[]) => void): number
467
+ stopListeningForGeneralMessages(callbackID: number): void
468
+ listenForCertificatesReceived(callback: (senderPublicKey: string, certs: VerifiableCertificate[]) => void): number
469
+ stopListeningForCertificatesReceived(callbackID: number): void
470
+ listenForCertificatesRequested(callback: (senderPublicKey: string, requestedCertificates: RequestedCertificateSet) => void): number
471
+ stopListeningForCertificatesRequested(callbackID: number): void
472
+ async processInitialRequest(message: AuthMessage)
473
+ async sendCertificateResponse(verifierIdentityKey: string, certificates: VerifiableCertificate[])
474
+ }
475
+ ```
476
+
477
+ See also: [AuthMessage](#interface-authmessage), [PeerSession](#interface-peersession), [RequestedCertificateSet](#interface-requestedcertificateset), [SessionManager](#class-sessionmanager), [Transport](#interface-transport), [VerifiableCertificate](#class-verifiablecertificate), [Wallet](#interface-wallet)
478
+
479
+ <details>
480
+
481
+ <summary>Class Peer Details</summary>
482
+
483
+ #### Constructor
484
+
485
+ Creates a new Peer instance
486
+
487
+ ```ts
488
+ constructor(wallet: Wallet, transport: Transport, certificatesToRequest?: RequestedCertificateSet, sessionManager?: SessionManager)
489
+ ```
490
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [SessionManager](#class-sessionmanager), [Transport](#interface-transport), [Wallet](#interface-wallet)
491
+
492
+ Argument Details
493
+
494
+ + **wallet**
495
+ + The wallet instance used for cryptographic operations.
496
+ + **transport**
497
+ + The transport mechanism used for sending and receiving messages.
498
+ + **certificatesToRequest**
499
+ + Optional set of certificates to request from a peer during the initial handshake.
500
+ + **sessionManager**
501
+ + Optional SessionManager to be used for managing peer sessions.
502
+
503
+ #### Method getAuthenticatedSession
504
+
505
+ Retrieves an authenticated session for a given peer identity. If no session exists
506
+ or the session is not authenticated, initiates a handshake to create or authenticate the session.
507
+
508
+ ```ts
509
+ async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession>
510
+ ```
511
+ See also: [PeerSession](#interface-peersession)
512
+
513
+ Returns
514
+
515
+ - A promise that resolves with an authenticated `PeerSession`.
516
+
517
+ Argument Details
518
+
519
+ + **identityKey**
520
+ + The identity public key of the peer. If provided, it attempts
521
+ to retrieve an existing session associated with this identity.
522
+ + **maxWaitTime**
523
+ + The maximum time in milliseconds to wait for the handshake
524
+ to complete if a new session is required. Defaults to a pre-defined timeout if not specified.
525
+
526
+ Throws
527
+
528
+ - Throws an error if the transport is not connected or if the handshake fails.
529
+
530
+ #### Method listenForCertificatesReceived
531
+
532
+ Registers a callback to listen for certificates received from peers.
533
+
534
+ ```ts
535
+ listenForCertificatesReceived(callback: (senderPublicKey: string, certs: VerifiableCertificate[]) => void): number
536
+ ```
537
+ See also: [VerifiableCertificate](#class-verifiablecertificate)
538
+
539
+ Returns
540
+
541
+ The ID of the callback listener.
542
+
543
+ Argument Details
544
+
545
+ + **callback**
546
+ + The function to call when certificates are received.
547
+
548
+ #### Method listenForCertificatesRequested
549
+
550
+ Registers a callback to listen for certificates requested from peers.
551
+
552
+ ```ts
553
+ listenForCertificatesRequested(callback: (senderPublicKey: string, requestedCertificates: RequestedCertificateSet) => void): number
554
+ ```
555
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset)
556
+
557
+ Returns
558
+
559
+ The ID of the callback listener.
560
+
561
+ Argument Details
562
+
563
+ + **callback**
564
+ + The function to call when a certificate request is received
565
+
566
+ #### Method listenForGeneralMessages
567
+
568
+ Registers a callback to listen for general messages from peers.
569
+
570
+ ```ts
571
+ listenForGeneralMessages(callback: (senderPublicKey: string, payload: number[]) => void): number
572
+ ```
573
+
574
+ Returns
575
+
576
+ The ID of the callback listener.
577
+
578
+ Argument Details
579
+
580
+ + **callback**
581
+ + The function to call when a general message is received.
582
+
583
+ #### Method processInitialRequest
584
+
585
+ Processes an initial request message from a peer.
586
+
587
+ ```ts
588
+ async processInitialRequest(message: AuthMessage)
589
+ ```
590
+ See also: [AuthMessage](#interface-authmessage)
591
+
592
+ Argument Details
593
+
594
+ + **message**
595
+ + The incoming initial request message.
596
+
597
+ #### Method requestCertificates
598
+
599
+ Sends a request for certificates to a peer.
600
+ This method allows a peer to dynamically request specific certificates after
601
+ an initial handshake or message has been exchanged.
602
+
603
+ ```ts
604
+ async requestCertificates(certificatesToRequest: RequestedCertificateSet, identityKey?: string, maxWaitTime = 10000): Promise<void>
605
+ ```
606
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset)
607
+
608
+ Returns
609
+
610
+ Resolves if the certificate request message is successfully sent.
611
+
612
+ Argument Details
613
+
614
+ + **certificatesToRequest**
615
+ + Specifies the certifiers and types of certificates required from the peer.
616
+ + **identityKey**
617
+ + The identity public key of the peer. If not provided, the current session identity is used.
618
+ + **maxWaitTime**
619
+ + Maximum time in milliseconds to wait for the peer session to be authenticated.
620
+
621
+ Throws
622
+
623
+ Will throw an error if the peer session is not authenticated or if sending the request fails.
624
+
625
+ #### Method sendCertificateResponse
626
+
627
+ Sends a certificate response message containing the specified certificates to a peer.
628
+
629
+ ```ts
630
+ async sendCertificateResponse(verifierIdentityKey: string, certificates: VerifiableCertificate[])
631
+ ```
632
+ See also: [VerifiableCertificate](#class-verifiablecertificate)
633
+
634
+ Returns
635
+
636
+ - A promise that resolves once the certificate response has been sent successfully.
637
+
638
+ Argument Details
639
+
640
+ + **verifierIdentityKey**
641
+ + The identity key of the peer requesting the certificates.
642
+ + **certificates**
643
+ + The list of certificates to be included in the response.
644
+
645
+ Throws
646
+
647
+ Throws an error if the peer session could not be authenticated or if message signing fails.
648
+
649
+ #### Method stopListeningForCertificatesReceived
650
+
651
+ Cancels and unsubscribes a certificatesReceived listener.
652
+
653
+ ```ts
654
+ stopListeningForCertificatesReceived(callbackID: number): void
655
+ ```
656
+
657
+ Argument Details
658
+
659
+ + **callbackID**
660
+ + The ID of the certificates received callback to cancel.
661
+
662
+ #### Method stopListeningForCertificatesRequested
663
+
664
+ Cancels and unsubscribes a certificatesRequested listener.
665
+
666
+ ```ts
667
+ stopListeningForCertificatesRequested(callbackID: number): void
668
+ ```
669
+
670
+ Argument Details
671
+
672
+ + **callbackID**
673
+ + The ID of the requested certificates callback to cancel.
674
+
675
+ #### Method stopListeningForGeneralMessages
676
+
677
+ Removes a general message listener.
678
+
679
+ ```ts
680
+ stopListeningForGeneralMessages(callbackID: number): void
681
+ ```
682
+
683
+ Argument Details
684
+
685
+ + **callbackID**
686
+ + The ID of the callback to remove.
687
+
688
+ #### Method toPeer
689
+
690
+ Sends a general message to a peer, and initiates a handshake if necessary.
691
+
692
+ ```ts
693
+ async toPeer(message: number[], identityKey?: string, maxWaitTime?: number): Promise<void>
694
+ ```
695
+
696
+ Argument Details
697
+
698
+ + **message**
699
+ + The message payload to send.
700
+ + **identityKey**
701
+ + The identity public key of the peer. If not provided, a handshake will be initiated.
702
+
703
+ Throws
704
+
705
+ Will throw an error if the message fails to send.
706
+
707
+ </details>
708
+
709
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
710
+
711
+ ---
712
+ ### Class: SessionManager
713
+
714
+ Manages sessions for peers, allowing sessions to be added, retrieved, updated, and removed
715
+ by relevant identifiers (sessionNonce and peerIdentityKey).
716
+
717
+ ```ts
718
+ export class SessionManager {
719
+ constructor()
720
+ addSession(session: PeerSession): void
721
+ updateSession(session: PeerSession): void
722
+ getSession(identifier: string): PeerSession | undefined
723
+ removeSession(session: PeerSession): void
724
+ hasSession(identifier: string): boolean
725
+ }
726
+ ```
727
+
728
+ See also: [PeerSession](#interface-peersession)
729
+
730
+ <details>
731
+
732
+ <summary>Class SessionManager Details</summary>
733
+
734
+ #### Method addSession
735
+
736
+ Adds a session to the manager, associating it with relevant identifiers for retrieval.
737
+
738
+ ```ts
739
+ addSession(session: PeerSession): void
740
+ ```
741
+ See also: [PeerSession](#interface-peersession)
742
+
743
+ Argument Details
744
+
745
+ + **session**
746
+ + The peer session to add.
747
+
748
+ #### Method getSession
749
+
750
+ Retrieves a session based on a given identifier.
751
+
752
+ ```ts
753
+ getSession(identifier: string): PeerSession | undefined
754
+ ```
755
+ See also: [PeerSession](#interface-peersession)
756
+
757
+ Returns
758
+
759
+ - The matching peer session, or undefined if not found.
760
+
761
+ Argument Details
762
+
763
+ + **identifier**
764
+ + The identifier for the session (sessionNonce or peerIdentityKey).
765
+
766
+ #### Method hasSession
767
+
768
+ Checks if a session exists based on a given identifier.
769
+
770
+ ```ts
771
+ hasSession(identifier: string): boolean
772
+ ```
773
+
774
+ Returns
775
+
776
+ - True if the session exists, false otherwise.
777
+
778
+ Argument Details
779
+
780
+ + **identifier**
781
+ + The identifier to check.
782
+
783
+ #### Method removeSession
784
+
785
+ Removes a session from the manager by clearing all associated identifiers.
786
+
787
+ ```ts
788
+ removeSession(session: PeerSession): void
789
+ ```
790
+ See also: [PeerSession](#interface-peersession)
791
+
792
+ Argument Details
793
+
794
+ + **session**
795
+ + The peer session to remove.
796
+
797
+ #### Method updateSession
798
+
799
+ Updates a session in the manager, ensuring that all identifiers are correctly associated.
800
+
801
+ ```ts
802
+ updateSession(session: PeerSession): void
803
+ ```
804
+ See also: [PeerSession](#interface-peersession)
805
+
806
+ Argument Details
807
+
808
+ + **session**
809
+ + The peer session to update.
810
+
811
+ </details>
812
+
813
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
814
+
815
+ ---
816
+ ### Class: SimplifiedFetchTransport
817
+
818
+ Implements an HTTP-specific transport for handling Peer mutual authentication messages.
819
+ This class integrates with fetch to send and receive authenticated messages between peers.
820
+
821
+ ```ts
822
+ export class SimplifiedFetchTransport implements Transport {
823
+ fetchClient: typeof fetch;
824
+ baseUrl: string;
825
+ constructor(baseUrl: string, fetchClient = fetch)
826
+ async send(message: AuthMessage): Promise<void>
827
+ async onData(callback: (message: AuthMessage) => Promise<void>): Promise<void>
828
+ deserializeRequestPayload(payload: number[]): {
829
+ method: string;
830
+ urlPostfix: string;
831
+ headers: Record<string, string>;
832
+ body: number[];
833
+ requestId: string;
834
+ }
835
+ }
836
+ ```
837
+
838
+ See also: [AuthMessage](#interface-authmessage), [Transport](#interface-transport)
839
+
840
+ <details>
841
+
842
+ <summary>Class SimplifiedFetchTransport Details</summary>
843
+
844
+ #### Constructor
845
+
846
+ Constructs a new instance of SimplifiedFetchTransport.
847
+
848
+ ```ts
849
+ constructor(baseUrl: string, fetchClient = fetch)
850
+ ```
851
+
852
+ Argument Details
853
+
854
+ + **baseUrl**
855
+ + The base URL for all HTTP requests made by this transport.
856
+ + **fetchClient**
857
+ + A fetch implementation to use for HTTP requests (default: global fetch).
858
+
859
+ #### Method deserializeRequestPayload
860
+
861
+ Deserializes a request payload from a byte array into an HTTP request-like structure.
862
+
863
+ ```ts
864
+ deserializeRequestPayload(payload: number[]): {
865
+ method: string;
866
+ urlPostfix: string;
867
+ headers: Record<string, string>;
868
+ body: number[];
869
+ requestId: string;
870
+ }
871
+ ```
872
+
873
+ Returns
874
+
875
+ An object representing the deserialized request, including the method,
876
+ URL postfix (path and query string), headers, body, and request ID.
877
+
878
+ Argument Details
879
+
880
+ + **payload**
881
+ + The serialized payload to deserialize.
882
+
883
+ #### Method onData
884
+
885
+ Registers a callback to handle incoming messages.
886
+ This must be called before sending any messages to ensure responses can be processed.
887
+
888
+ ```ts
889
+ async onData(callback: (message: AuthMessage) => Promise<void>): Promise<void>
890
+ ```
891
+ See also: [AuthMessage](#interface-authmessage)
892
+
893
+ Returns
894
+
895
+ A promise that resolves once the callback is set.
896
+
897
+ Argument Details
898
+
899
+ + **callback**
900
+ + A function to invoke when an incoming AuthMessage is received.
901
+
902
+ #### Method send
903
+
904
+ Sends a message to an HTTP server using the transport mechanism.
905
+ Handles both general and authenticated message types. For general messages,
906
+ the payload is deserialized and sent as an HTTP request. For other message types,
907
+ the message is sent as a POST request to the `/auth` endpoint.
908
+
909
+ ```ts
910
+ async send(message: AuthMessage): Promise<void>
911
+ ```
912
+ See also: [AuthMessage](#interface-authmessage)
913
+
914
+ Returns
915
+
916
+ A promise that resolves when the message is successfully sent.
917
+
918
+ Argument Details
919
+
920
+ + **message**
921
+ + The AuthMessage to send.
922
+
923
+ Throws
924
+
925
+ Will throw an error if no listener has been registered via `onData`.
926
+
927
+ </details>
928
+
929
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
930
+
931
+ ---
932
+ ### Class: VerifiableCertificate
933
+
934
+ VerifiableCertificate extends the Certificate class, adding functionality to manage a verifier-specific keyring.
935
+ This keyring allows selective decryption of certificate fields for authorized verifiers.
936
+
937
+ ```ts
938
+ export class VerifiableCertificate extends Certificate {
939
+ declare type: Base64String;
940
+ declare serialNumber: Base64String;
941
+ declare subject: PubKeyHex;
942
+ declare certifier: PubKeyHex;
943
+ declare revocationOutpoint: OutpointString;
944
+ declare fields: Record<CertificateFieldNameUnder50Bytes, string>;
945
+ declare signature?: HexString;
946
+ keyring: Record<CertificateFieldNameUnder50Bytes, string>;
947
+ decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>;
948
+ constructor(type: Base64String, serialNumber: Base64String, subject: PubKeyHex, certifier: PubKeyHex, revocationOutpoint: OutpointString, fields: Record<CertificateFieldNameUnder50Bytes, string>, signature?: HexString, keyring?: Record<CertificateFieldNameUnder50Bytes, string>, decryptedFields?: Record<CertificateFieldNameUnder50Bytes, Base64String>)
949
+ async decryptFields(verifierWallet: Wallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
950
+ }
951
+ ```
952
+
953
+ See also: [Base64String](#type-base64string), [Certificate](#class-certificate), [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [HexString](#type-hexstring), [OutpointString](#type-outpointstring), [PubKeyHex](#type-pubkeyhex), [Wallet](#interface-wallet)
954
+
955
+ <details>
956
+
957
+ <summary>Class VerifiableCertificate Details</summary>
958
+
959
+ #### Method decryptFields
960
+
961
+ Decrypts certificate fields using the provided keyring and verifier wallet
962
+
963
+ ```ts
964
+ async decryptFields(verifierWallet: Wallet): Promise<Record<CertificateFieldNameUnder50Bytes, string>>
965
+ ```
966
+ See also: [CertificateFieldNameUnder50Bytes](#type-certificatefieldnameunder50bytes), [Wallet](#interface-wallet)
967
+
968
+ Returns
969
+
970
+ - A promise that resolves to an object where each key is a field name and each value is the decrypted field value as a string.
971
+
972
+ Argument Details
973
+
974
+ + **verifierWallet**
975
+ + The wallet instance of the certificate's verifier, used to decrypt field keys.
976
+
977
+ Throws
978
+
979
+ Throws an error if any of the decryption operations fail, with a message indicating the failure context.
980
+
981
+ </details>
982
+
983
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
984
+
985
+ ---
986
+ ## Functions
987
+
988
+ | |
989
+ | --- |
990
+ | [createMasterCertificate](#function-createmastercertificate) |
991
+ | [createNonce](#function-createnonce) |
992
+ | [createVerifiableCertificate](#function-createverifiablecertificate) |
993
+ | [verifyNonce](#function-verifynonce) |
994
+
995
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
996
+
997
+ ---
998
+
999
+ ### Function: createMasterCertificate
1000
+
1001
+ Creates a Master Certificate by encrypting provided fields and generating a master keyring.
1002
+
1003
+ ```ts
1004
+ export async function createMasterCertificate(wallet: Wallet, fields: Record<string, string>, certificateType: string, certificateSerialNumber: string, certifierPublicKey: string): Promise<MasterCertificate>
1005
+ ```
1006
+
1007
+ See also: [MasterCertificate](#class-mastercertificate), [Wallet](#interface-wallet)
1008
+
1009
+ <details>
1010
+
1011
+ <summary>Function createMasterCertificate Details</summary>
1012
+
1013
+ Returns
1014
+
1015
+ A promise resolving to the created Master Certificate.
1016
+
1017
+ Argument Details
1018
+
1019
+ + **wallet**
1020
+ + The wallet instance used for encryption and public key retrieval.
1021
+ + **fields**
1022
+ + The certificate fields to encrypt.
1023
+ + **certificateType**
1024
+ + The type of the certificate being created.
1025
+ + **certificateSerialNumber**
1026
+ + The serial number of the certificate.
1027
+ + **certifierPublicKey**
1028
+ + The public key of the certifier.
1029
+
1030
+ </details>
1031
+
1032
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1033
+
1034
+ ---
1035
+ ### Function: createNonce
1036
+
1037
+ Creates a nonce derived from a privateKey
1038
+
1039
+ ```ts
1040
+ export async function createNonce(wallet: Wallet): Promise<string>
1041
+ ```
1042
+
1043
+ See also: [Wallet](#interface-wallet)
1044
+
1045
+ <details>
1046
+
1047
+ <summary>Function createNonce Details</summary>
1048
+
1049
+ Returns
1050
+
1051
+ A random nonce derived with a wallet
1052
+
1053
+ </details>
1054
+
1055
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1056
+
1057
+ ---
1058
+ ### Function: createVerifiableCertificate
1059
+
1060
+ Creates a Verifiable Certificate by signing a Master Certificate and generating a keyring for a verifier.
1061
+
1062
+ ```ts
1063
+ export async function createVerifiableCertificate(masterCertificate: MasterCertificate, wallet: Wallet, verifierIdentityKey: string, fieldsToReveal: string[], certifierPrivateKey: PrivateKey): Promise<VerifiableCertificate>
1064
+ ```
1065
+
1066
+ See also: [MasterCertificate](#class-mastercertificate), [PrivateKey](#class-privatekey), [VerifiableCertificate](#class-verifiablecertificate), [Wallet](#interface-wallet)
1067
+
1068
+ <details>
1069
+
1070
+ <summary>Function createVerifiableCertificate Details</summary>
1071
+
1072
+ Returns
1073
+
1074
+ A promise resolving to the created Verifiable Certificate.
1075
+
1076
+ Argument Details
1077
+
1078
+ + **masterCertificate**
1079
+ + The master certificate to convert into a verifiable certificate.
1080
+ + **wallet**
1081
+ + The wallet instance used for generating a keyring for the verifier.
1082
+ + **verifierIdentityKey**
1083
+ + The identity key of the verifier.
1084
+ + **fieldsToReveal**
1085
+ + The list of fields to reveal to the verifier.
1086
+ + **certifierPrivateKey**
1087
+ + The private key of the certifier for signing the certificate.
1088
+
1089
+ </details>
1090
+
1091
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1092
+
1093
+ ---
1094
+ ### Function: verifyNonce
1095
+
1096
+ Verifies a nonce derived from a wallet
1097
+
1098
+ ```ts
1099
+ export async function verifyNonce(nonce: string, wallet: Wallet): Promise<boolean>
1100
+ ```
1101
+
1102
+ See also: [Wallet](#interface-wallet)
1103
+
1104
+ <details>
1105
+
1106
+ <summary>Function verifyNonce Details</summary>
1107
+
1108
+ Returns
1109
+
1110
+ The status of the validation
1111
+
1112
+ Argument Details
1113
+
1114
+ + **nonce**
1115
+ + A nonce to verify as a base64 string.
1116
+
1117
+ </details>
1118
+
1119
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1120
+
1121
+ ---
1122
+ ## Types
1123
+
1124
+ ## Enums
1125
+
1126
+ ## Variables
1127
+
1128
+ | |
1129
+ | --- |
1130
+ | [getVerifiableCertificates](#variable-getverifiablecertificates) |
1131
+ | [validateCertificates](#variable-validatecertificates) |
1132
+
1133
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1134
+
1135
+ ---
1136
+
1137
+ ### Variable: getVerifiableCertificates
1138
+
1139
+ ```ts
1140
+ getVerifiableCertificates = async (wallet: Wallet, requestedCertificates: RequestedCertificateSet, verifierIdentityKey: string): Promise<VerifiableCertificate[]> => {
1141
+ const matchingCertificates = await wallet.listCertificates({
1142
+ certifiers: requestedCertificates.certifiers,
1143
+ types: Object.keys(requestedCertificates.types)
1144
+ });
1145
+ return await Promise.all(matchingCertificates.certificates.map(async (certificate) => {
1146
+ const { keyringForVerifier } = await wallet.proveCertificate({
1147
+ certificate,
1148
+ fieldsToReveal: requestedCertificates.types[certificate.type],
1149
+ verifier: verifierIdentityKey
1150
+ });
1151
+ return new VerifiableCertificate(certificate.type, certificate.serialNumber, certificate.subject, certificate.certifier, certificate.revocationOutpoint, certificate.fields, certificate.signature, keyringForVerifier);
1152
+ }));
1153
+ }
1154
+ ```
1155
+
1156
+ See also: [RequestedCertificateSet](#interface-requestedcertificateset), [VerifiableCertificate](#class-verifiablecertificate), [Wallet](#interface-wallet)
1157
+
1158
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1159
+
1160
+ ---
1161
+ ### Variable: validateCertificates
1162
+
1163
+ ```ts
1164
+ validateCertificates = async (verifierWallet: Wallet, message: AuthMessage, certificatesRequested?: RequestedCertificateSet): Promise<void> => {
1165
+ await Promise.all(message.certificates.map(async (incomingCert: VerifiableCertificate) => {
1166
+ if (incomingCert.subject !== message.identityKey) {
1167
+ throw new Error(`The subject of one of your certificates ("${incomingCert.subject}") is not the same as the request sender ("${message.identityKey}").`);
1168
+ }
1169
+ const certToVerify = new VerifiableCertificate(incomingCert.type, incomingCert.serialNumber, incomingCert.subject, incomingCert.certifier, incomingCert.revocationOutpoint, incomingCert.fields, incomingCert.signature, incomingCert.keyring);
1170
+ const isValidCert = await certToVerify.verify();
1171
+ if (!isValidCert) {
1172
+ throw new Error(`The signature for the certificate with serial number ${certToVerify.serialNumber} is invalid!`);
1173
+ }
1174
+ if (certificatesRequested) {
1175
+ const { certifiers, types } = certificatesRequested;
1176
+ if (!certifiers.includes(certToVerify.certifier)) {
1177
+ throw new Error(`Certificate with serial number ${certToVerify.serialNumber} has an unrequested certifier: ${certToVerify.certifier}`);
1178
+ }
1179
+ const requestedFields = types[certToVerify.type];
1180
+ if (!requestedFields) {
1181
+ throw new Error(`Certificate with type ${certToVerify.type} was not requested`);
1182
+ }
1183
+ }
1184
+ await certToVerify.decryptFields(verifierWallet);
1185
+ }));
1186
+ }
1187
+ ```
1188
+
1189
+ See also: [AuthMessage](#interface-authmessage), [Certificate](#class-certificate), [RequestedCertificateSet](#interface-requestedcertificateset), [VerifiableCertificate](#class-verifiablecertificate), [Wallet](#interface-wallet), [verify](#variable-verify)
1190
+
1191
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
1192
+
1193
+ ---