Skip to content

Commit 7f1e3c5

Browse files
committed
Merge branch 'master' of github.com:bsv-blockchain/ts-sdk into r1
2 parents b0043a3 + 73b6ae6 commit 7f1e3c5

File tree

7 files changed

+134
-32
lines changed

7 files changed

+134
-32
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format
55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8+
- [1.9.11 - 2025-11-24](#1911---2025-11-24)
9+
- [1.9.10 - 2025-11-17](#1910---2025-11-17)
810
- [1.9.9 - 2025-11-15](#199---2025-11-15)
911
- [1.9.8 - 2025-11-15](#198---2025-11-15)
1012
- [1.9.7 - 2025-11-14](#197---2025-11-14)
@@ -180,6 +182,21 @@ All notable changes to this project will be documented in this file. The format
180182

181183
### Security
182184

185+
---
186+
### [1.9.11] - 2025-11-24
187+
188+
### Removed
189+
190+
- Removed dependency on react-native-get-random-values polyfill from Random.ts
191+
192+
193+
---
194+
### [1.9.10] - 2025-11-17
195+
196+
### Added
197+
198+
- Added `Certificate.fromObject` method for creating Certificate instances from plain objects.
199+
183200
---
184201

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

docs/reference/auth.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ export default class Certificate {
218218
protocolID: WalletProtocol;
219219
keyID: string;
220220
}
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
221230
}
222231
```
223232

@@ -330,6 +339,32 @@ Argument Details
330339
+ **bin**
331340
+ The binary data representing the certificate.
332341

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+
333368
#### Method getCertificateFieldEncryptionDetails
334369

335370
Helper function which retrieves the protocol ID and key ID for certificate field encryption.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bsv/sdk",
3-
"version": "1.9.9",
3+
"version": "1.9.11",
44
"type": "module",
55
"description": "BSV Blockchain Software Development Kit",
66
"main": "dist/cjs/mod.js",

src/auth/certificates/Certificate.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,32 @@ export default class Certificate {
280280
keyID: serialNumber ? `${serialNumber} ${fieldName}` : fieldName
281281
}
282282
}
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+
}
283311
}

src/auth/certificates/__tests/Certificate.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,55 @@ describe('Certificate', () => {
332332
expect(certificateWithMismatch.certifier).toBe(certifierPubKey)
333333
expect(await certificateWithMismatch.verify()).toBe(true)
334334
})
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+
})
335386
})

src/primitives/Random.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* - Modern browsers via globalThis.crypto, self.crypto, or window.crypto
88
* - Web Workers and Service Workers via self.crypto
99
* - Deno and Bun via globalThis.crypto
10-
* - React Native (requires react-native-get-random-values polyfill)
1110
*
1211
* @throws {Error} If no secure random number generator is available
1312
*/
@@ -72,34 +71,6 @@ class Rand {
7271
return
7372
}
7473

75-
// React Native support - try to load polyfill
76-
if (typeof navigator !== 'undefined' && (navigator as any).product === 'ReactNative') {
77-
try {
78-
// Try to require the polyfill - this will populate globalThis.crypto
79-
// eslint-disable-next-line @typescript-eslint/no-var-requires
80-
require('react-native-get-random-values')
81-
82-
if (typeof (globalThis as any).crypto?.getRandomValues === 'function') {
83-
this._rand = (n) => {
84-
/* eslint-disable-next-line */
85-
return this.getRandomValues(globalThis as any, n)
86-
}
87-
return
88-
}
89-
} catch (e) {
90-
// Polyfill not available - provide helpful error
91-
this._rand = (): never => {
92-
throw new Error(
93-
'React Native detected but crypto is not available. ' +
94-
'Please install and import "react-native-get-random-values" at the top of your entry file:\n' +
95-
'npm install react-native-get-random-values\n' +
96-
'Then add: import "react-native-get-random-values" to your index.js/App.js'
97-
)
98-
}
99-
return
100-
}
101-
}
102-
10374
// No crypto available
10475
this._rand = noRand
10576
}

0 commit comments

Comments
 (0)