@dxos/keys 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850
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/lib/browser/index.mjs +88 -9
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +83 -9
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +87 -9
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/dxn.d.ts +7 -5
- package/dist/types/src/dxn.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/object-id.d.ts +16 -0
- package/dist/types/src/object-id.d.ts.map +1 -0
- package/dist/types/src/public-key.d.ts.map +1 -1
- package/dist/types/src/space-id.d.ts +1 -0
- package/dist/types/src/space-id.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/dxn.ts +62 -13
- package/src/index.ts +1 -0
- package/src/object-id.ts +42 -0
- package/src/public-key.ts +8 -8
- package/src/space-id.ts +2 -0
package/src/public-key.ts
CHANGED
|
@@ -90,7 +90,7 @@ export class PublicKey implements Equatable {
|
|
|
90
90
|
/**
|
|
91
91
|
* Creates new instance of PublicKey from hex string.
|
|
92
92
|
*/
|
|
93
|
-
static fromHex(hex: string) {
|
|
93
|
+
static fromHex(hex: string): PublicKey {
|
|
94
94
|
if (hex.startsWith('0x')) {
|
|
95
95
|
hex = hex.slice(2);
|
|
96
96
|
}
|
|
@@ -139,7 +139,7 @@ export class PublicKey implements Equatable {
|
|
|
139
139
|
/**
|
|
140
140
|
* Tests two keys for equality.
|
|
141
141
|
*/
|
|
142
|
-
static equals(left: PublicKeyLike, right: PublicKeyLike) {
|
|
142
|
+
static equals(left: PublicKeyLike, right: PublicKeyLike): boolean {
|
|
143
143
|
return PublicKey.from(left).equals(right);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -196,7 +196,7 @@ export class PublicKey implements Equatable {
|
|
|
196
196
|
return this.toHex();
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
toJSON() {
|
|
199
|
+
toJSON(): string {
|
|
200
200
|
return this.toHex();
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -216,7 +216,7 @@ export class PublicKey implements Equatable {
|
|
|
216
216
|
return 'B' + base32Encode(this._value, 'RFC4648');
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
truncate(length = undefined) {
|
|
219
|
+
truncate(length = undefined): string {
|
|
220
220
|
return truncateKey(this, length);
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -228,14 +228,14 @@ export class PublicKey implements Equatable {
|
|
|
228
228
|
return this._value;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
getInsecureHash(modulo: number) {
|
|
231
|
+
getInsecureHash(modulo: number): number {
|
|
232
232
|
return Math.abs(this._value.reduce((acc, val) => (acc ^ val) | 0, 0)) % modulo;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
236
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
237
237
|
*/
|
|
238
|
-
[inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect) {
|
|
238
|
+
[inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {
|
|
239
239
|
if (!options.colors || typeof process.stdout.hasColors !== 'function' || !process.stdout.hasColors()) {
|
|
240
240
|
return `<PublicKey ${this.truncate()}>`;
|
|
241
241
|
}
|
|
@@ -302,7 +302,7 @@ export class PublicKey implements Equatable {
|
|
|
302
302
|
/**
|
|
303
303
|
* Test this key for equality with some other key.
|
|
304
304
|
*/
|
|
305
|
-
equals(other: PublicKeyLike) {
|
|
305
|
+
equals(other: PublicKeyLike): boolean {
|
|
306
306
|
const otherConverted = PublicKey.from(other);
|
|
307
307
|
if (this._value.length !== otherConverted._value.length) {
|
|
308
308
|
return false;
|
|
@@ -316,7 +316,7 @@ export class PublicKey implements Equatable {
|
|
|
316
316
|
return equal;
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
[equalsSymbol](other: any) {
|
|
319
|
+
[equalsSymbol](other: any): boolean {
|
|
320
320
|
if (!PublicKey.isPublicKey(other)) {
|
|
321
321
|
return false;
|
|
322
322
|
}
|
package/src/space-id.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const SpaceId: Schema.Schema<SpaceId, string> & {
|
|
|
34
34
|
encode: (value: Uint8Array) => SpaceId;
|
|
35
35
|
decode: (value: SpaceId) => Uint8Array;
|
|
36
36
|
isValid: (value: string) => value is SpaceId;
|
|
37
|
+
make: (value: string) => SpaceId;
|
|
37
38
|
random: () => SpaceId;
|
|
38
39
|
} = class extends Schema.String.pipe(Schema.filter(isValid)) {
|
|
39
40
|
static byteLength = 20;
|
|
@@ -50,6 +51,7 @@ export const SpaceId: Schema.Schema<SpaceId, string> & {
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
static isValid = isValid;
|
|
54
|
+
|
|
53
55
|
static random = (): SpaceId => {
|
|
54
56
|
return SpaceId.encode(randomBytes(SpaceId.byteLength));
|
|
55
57
|
};
|