Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format
## Table of Contents

- [Unreleased](#unreleased)
- [1.9.10 - 2025-11-17](#1910---2025-11-17)
- [1.9.9 - 2025-11-15](#199---2025-11-15)
- [1.9.8 - 2025-11-15](#198---2025-11-15)
- [1.9.7 - 2025-11-14](#197---2025-11-14)
Expand Down Expand Up @@ -182,6 +183,14 @@ All notable changes to this project will be documented in this file. The format

---

### [1.9.10] - 2025-11-17

### Added

- Added `Certificate.fromObject` method for creating Certificate instances from plain objects.

---

### [1.9.9] - 2025-11-15

### Fixed
Expand Down
35 changes: 35 additions & 0 deletions docs/reference/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ export default class Certificate {
protocolID: WalletProtocol;
keyID: string;
}
static fromObject(obj: {
type: Base64String;
serialNumber: Base64String;
subject: PubKeyHex;
certifier: PubKeyHex;
revocationOutpoint: OutpointString;
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>;
signature?: HexString;
}): Certificate
}
```

Expand Down Expand Up @@ -330,6 +339,32 @@ Argument Details
+ **bin**
+ The binary data representing the certificate.

#### Method fromObject

Creates a Certificate instance from a plain object representation.

```ts
static fromObject(obj: {
type: Base64String;
serialNumber: Base64String;
subject: PubKeyHex;
certifier: PubKeyHex;
revocationOutpoint: OutpointString;
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>;
signature?: HexString;
}): Certificate
```
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)

Returns

A new Certificate instance.

Argument Details

+ **obj**
+ The object containing certificate data.

#### Method getCertificateFieldEncryptionDetails

Helper function which retrieves the protocol ID and key ID for certificate field encryption.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsv/sdk",
"version": "1.9.9",
"version": "1.9.10",
"type": "module",
"description": "BSV Blockchain Software Development Kit",
"main": "dist/cjs/mod.js",
Expand Down
28 changes: 28 additions & 0 deletions src/auth/certificates/Certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,32 @@ export default class Certificate {
keyID: serialNumber ? `${serialNumber} ${fieldName}` : fieldName
}
}

/**
* Creates a Certificate instance from a plain object representation.
*
* @param obj - The object containing certificate data.
* @returns A new Certificate instance.
*/
static fromObject(obj: {
type: Base64String,
serialNumber: Base64String,
subject: PubKeyHex,
certifier: PubKeyHex,
revocationOutpoint: OutpointString,
fields: Record<CertificateFieldNameUnder50Bytes, Base64String>,
signature?: HexString
}): Certificate {
const cert = new Certificate(
obj.type,
obj.serialNumber,
obj.subject,
obj.certifier,
obj.revocationOutpoint,
obj.fields,
obj.signature
);

return cert;
}
}
51 changes: 51 additions & 0 deletions src/auth/certificates/__tests/Certificate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,55 @@ describe('Certificate', () => {
expect(certificateWithMismatch.certifier).toBe(certifierPubKey)
expect(await certificateWithMismatch.verify()).toBe(true)
})

it('should create a Certificate from an object using fromObject()', () => {
const certificateObject = {
type: 'Q29tbW9uU291cmNlIGlkZW50aXR5',
subject: '028e2e075e1e57ba4c62c90125468109f9b4e2a7741da3dd76ccd0c73b2a8a37ad',
serialNumber: 'UegX3uufsqHsbEKeBSxUd9AziLSyru86TnwfhPoZJYE=',
certifier: '03c644fe2fd97673a5d86555a58587e7936390be6582ece262bc387014bcff6fe4',
revocationOutpoint: '0245242bd144a85053b4c1e4a0ed5467c79a4d172680ca77a970ebabd682d564.0',
signature: '304402202c86ef816c469fe657289ddea12d2c444f006ef5ab5851f00107c7724eb67ea602202786244c077567c8f3ec5da78bd61ce0c35bf1eeac0488e026c03b21c403b0fd',
fields: {
displayName: 'eqsSpUgTKk891y1EkyCPPg+C4YoVZJvB0EQ4iore7VofkM5TB9Ctj7x2PgBaWI0A9tfATDO9',
email: 'n6HVUvyHkIDMvB4ERxVGxmX6lgRBM+e7kbbC5DiRCKe5a60BJeXr05g4POq6OHYO9Wl/b1Xxe+JKsejl',
phoneNumber: '5yWyN9kOGaZs5G6yvXUWnWj4rm7kDAug4YIsn4BQLKGYRzDx8s1dytb43ega6BnSp0gUTnskcjiM8ekqul2a',
lat: 'lc3u6SFKQ5Mpxp5vc+6s4aXe7lOyQQLfN+CbOu4XlBYsj7Jlc78gt4sGCwDSxbzvA41eElCjlc2Our5bpLcsg1I6',
lng: 'FmY3iM/2/LDfYNEeXpcj7Epn933tRHz50WoBkBrqYv6jmZ6dXE6RRYId9TcaxIvB0D7Y14aD5vjSV6Bx48hdic5g'
}
}

const certificate = Certificate.fromObject(certificateObject)

expect(certificate.type).toEqual(certificateObject.type)
expect(certificate.serialNumber).toEqual(certificateObject.serialNumber)
expect(certificate.subject).toEqual(certificateObject.subject)
expect(certificate.certifier).toEqual(certificateObject.certifier)
expect(certificate.revocationOutpoint).toEqual(certificateObject.revocationOutpoint)
expect(certificate.signature).toEqual(certificateObject.signature)
expect(certificate.fields).toEqual(certificateObject.fields)
})

it('should create a Certificate from an object without signature using fromObject()', () => {
const certificateObject = {
type: 'Q29tbW9uU291cmNlIGlkZW50aXR5',
subject: '028e2e075e1e57ba4c62c90125468109f9b4e2a7741da3dd76ccd0c73b2a8a37ad',
serialNumber: 'UegX3uufsqHsbEKeBSxUd9AziLSyru86TnwfhPoZJYE=',
certifier: '03c644fe2fd97673a5d86555a58587e7936390be6582ece262bc387014bcff6fe4',
revocationOutpoint: '0245242bd144a85053b4c1e4a0ed5467c79a4d172680ca77a970ebabd682d564.0',
fields: {
displayName: 'eqsSpUgTKk891y1EkyCPPg+C4YoVZJvB0EQ4iore7VofkM5TB9Ctj7x2PgBaWI0A9tfATDO9'
}
}

const certificate = Certificate.fromObject(certificateObject)

expect(certificate.type).toEqual(certificateObject.type)
expect(certificate.serialNumber).toEqual(certificateObject.serialNumber)
expect(certificate.subject).toEqual(certificateObject.subject)
expect(certificate.certifier).toEqual(certificateObject.certifier)
expect(certificate.revocationOutpoint).toEqual(certificateObject.revocationOutpoint)
expect(certificate.signature).toBeUndefined()
expect(certificate.fields).toEqual(certificateObject.fields)
})
})
Loading