@bsv/sdk 1.9.9 → 1.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js +10 -0
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +10 -0
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +15 -0
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/dist/umd/bundle.js.map +1 -1
- package/docs/reference/auth.md +35 -0
- package/package.json +1 -1
- package/src/auth/certificates/Certificate.ts +28 -0
- package/src/auth/certificates/__tests/Certificate.test.ts +51 -0
package/docs/reference/auth.md
CHANGED
|
@@ -218,6 +218,15 @@ export default class Certificate {
|
|
|
218
218
|
protocolID: WalletProtocol;
|
|
219
219
|
keyID: string;
|
|
220
220
|
}
|
|
221
|
+
static fromObject(obj: {
|
|
222
|
+
type: Base64String;
|
|
223
|
+
serialNumber: Base64String;
|
|
224
|
+
subject: PubKeyHex;
|
|
225
|
+
certifier: PubKeyHex;
|
|
226
|
+
revocationOutpoint: OutpointString;
|
|
227
|
+
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
228
|
+
signature?: HexString;
|
|
229
|
+
}): Certificate
|
|
221
230
|
}
|
|
222
231
|
```
|
|
223
232
|
|
|
@@ -330,6 +339,32 @@ Argument Details
|
|
|
330
339
|
+ **bin**
|
|
331
340
|
+ The binary data representing the certificate.
|
|
332
341
|
|
|
342
|
+
#### Method fromObject
|
|
343
|
+
|
|
344
|
+
Creates a Certificate instance from a plain object representation.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
static fromObject(obj: {
|
|
348
|
+
type: Base64String;
|
|
349
|
+
serialNumber: Base64String;
|
|
350
|
+
subject: PubKeyHex;
|
|
351
|
+
certifier: PubKeyHex;
|
|
352
|
+
revocationOutpoint: OutpointString;
|
|
353
|
+
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>;
|
|
354
|
+
signature?: HexString;
|
|
355
|
+
}): Certificate
|
|
356
|
+
```
|
|
357
|
+
See also: [Base64String](./wallet.md#type-base64string), [Certificate](./auth.md#class-certificate), [CertificateFieldNameUnder50Bytes](./wallet.md#type-certificatefieldnameunder50bytes), [HexString](./wallet.md#type-hexstring), [OutpointString](./wallet.md#type-outpointstring), [PubKeyHex](./wallet.md#type-pubkeyhex)
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
|
|
361
|
+
A new Certificate instance.
|
|
362
|
+
|
|
363
|
+
Argument Details
|
|
364
|
+
|
|
365
|
+
+ **obj**
|
|
366
|
+
+ The object containing certificate data.
|
|
367
|
+
|
|
333
368
|
#### Method getCertificateFieldEncryptionDetails
|
|
334
369
|
|
|
335
370
|
Helper function which retrieves the protocol ID and key ID for certificate field encryption.
|
package/package.json
CHANGED
|
@@ -280,4 +280,32 @@ export default class Certificate {
|
|
|
280
280
|
keyID: serialNumber ? `${serialNumber} ${fieldName}` : fieldName
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Creates a Certificate instance from a plain object representation.
|
|
286
|
+
*
|
|
287
|
+
* @param obj - The object containing certificate data.
|
|
288
|
+
* @returns A new Certificate instance.
|
|
289
|
+
*/
|
|
290
|
+
static fromObject(obj: {
|
|
291
|
+
type: Base64String,
|
|
292
|
+
serialNumber: Base64String,
|
|
293
|
+
subject: PubKeyHex,
|
|
294
|
+
certifier: PubKeyHex,
|
|
295
|
+
revocationOutpoint: OutpointString,
|
|
296
|
+
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
297
|
+
signature?: HexString
|
|
298
|
+
}): Certificate {
|
|
299
|
+
const cert = new Certificate(
|
|
300
|
+
obj.type,
|
|
301
|
+
obj.serialNumber,
|
|
302
|
+
obj.subject,
|
|
303
|
+
obj.certifier,
|
|
304
|
+
obj.revocationOutpoint,
|
|
305
|
+
obj.fields,
|
|
306
|
+
obj.signature
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
return cert;
|
|
310
|
+
}
|
|
283
311
|
}
|
|
@@ -332,4 +332,55 @@ describe('Certificate', () => {
|
|
|
332
332
|
expect(certificateWithMismatch.certifier).toBe(certifierPubKey)
|
|
333
333
|
expect(await certificateWithMismatch.verify()).toBe(true)
|
|
334
334
|
})
|
|
335
|
+
|
|
336
|
+
it('should create a Certificate from an object using fromObject()', () => {
|
|
337
|
+
const certificateObject = {
|
|
338
|
+
type: 'Q29tbW9uU291cmNlIGlkZW50aXR5',
|
|
339
|
+
subject: '028e2e075e1e57ba4c62c90125468109f9b4e2a7741da3dd76ccd0c73b2a8a37ad',
|
|
340
|
+
serialNumber: 'UegX3uufsqHsbEKeBSxUd9AziLSyru86TnwfhPoZJYE=',
|
|
341
|
+
certifier: '03c644fe2fd97673a5d86555a58587e7936390be6582ece262bc387014bcff6fe4',
|
|
342
|
+
revocationOutpoint: '0245242bd144a85053b4c1e4a0ed5467c79a4d172680ca77a970ebabd682d564.0',
|
|
343
|
+
signature: '304402202c86ef816c469fe657289ddea12d2c444f006ef5ab5851f00107c7724eb67ea602202786244c077567c8f3ec5da78bd61ce0c35bf1eeac0488e026c03b21c403b0fd',
|
|
344
|
+
fields: {
|
|
345
|
+
displayName: 'eqsSpUgTKk891y1EkyCPPg+C4YoVZJvB0EQ4iore7VofkM5TB9Ctj7x2PgBaWI0A9tfATDO9',
|
|
346
|
+
email: 'n6HVUvyHkIDMvB4ERxVGxmX6lgRBM+e7kbbC5DiRCKe5a60BJeXr05g4POq6OHYO9Wl/b1Xxe+JKsejl',
|
|
347
|
+
phoneNumber: '5yWyN9kOGaZs5G6yvXUWnWj4rm7kDAug4YIsn4BQLKGYRzDx8s1dytb43ega6BnSp0gUTnskcjiM8ekqul2a',
|
|
348
|
+
lat: 'lc3u6SFKQ5Mpxp5vc+6s4aXe7lOyQQLfN+CbOu4XlBYsj7Jlc78gt4sGCwDSxbzvA41eElCjlc2Our5bpLcsg1I6',
|
|
349
|
+
lng: 'FmY3iM/2/LDfYNEeXpcj7Epn933tRHz50WoBkBrqYv6jmZ6dXE6RRYId9TcaxIvB0D7Y14aD5vjSV6Bx48hdic5g'
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const certificate = Certificate.fromObject(certificateObject)
|
|
354
|
+
|
|
355
|
+
expect(certificate.type).toEqual(certificateObject.type)
|
|
356
|
+
expect(certificate.serialNumber).toEqual(certificateObject.serialNumber)
|
|
357
|
+
expect(certificate.subject).toEqual(certificateObject.subject)
|
|
358
|
+
expect(certificate.certifier).toEqual(certificateObject.certifier)
|
|
359
|
+
expect(certificate.revocationOutpoint).toEqual(certificateObject.revocationOutpoint)
|
|
360
|
+
expect(certificate.signature).toEqual(certificateObject.signature)
|
|
361
|
+
expect(certificate.fields).toEqual(certificateObject.fields)
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('should create a Certificate from an object without signature using fromObject()', () => {
|
|
365
|
+
const certificateObject = {
|
|
366
|
+
type: 'Q29tbW9uU291cmNlIGlkZW50aXR5',
|
|
367
|
+
subject: '028e2e075e1e57ba4c62c90125468109f9b4e2a7741da3dd76ccd0c73b2a8a37ad',
|
|
368
|
+
serialNumber: 'UegX3uufsqHsbEKeBSxUd9AziLSyru86TnwfhPoZJYE=',
|
|
369
|
+
certifier: '03c644fe2fd97673a5d86555a58587e7936390be6582ece262bc387014bcff6fe4',
|
|
370
|
+
revocationOutpoint: '0245242bd144a85053b4c1e4a0ed5467c79a4d172680ca77a970ebabd682d564.0',
|
|
371
|
+
fields: {
|
|
372
|
+
displayName: 'eqsSpUgTKk891y1EkyCPPg+C4YoVZJvB0EQ4iore7VofkM5TB9Ctj7x2PgBaWI0A9tfATDO9'
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const certificate = Certificate.fromObject(certificateObject)
|
|
377
|
+
|
|
378
|
+
expect(certificate.type).toEqual(certificateObject.type)
|
|
379
|
+
expect(certificate.serialNumber).toEqual(certificateObject.serialNumber)
|
|
380
|
+
expect(certificate.subject).toEqual(certificateObject.subject)
|
|
381
|
+
expect(certificate.certifier).toEqual(certificateObject.certifier)
|
|
382
|
+
expect(certificate.revocationOutpoint).toEqual(certificateObject.revocationOutpoint)
|
|
383
|
+
expect(certificate.signature).toBeUndefined()
|
|
384
|
+
expect(certificate.fields).toEqual(certificateObject.fields)
|
|
385
|
+
})
|
|
335
386
|
})
|