@peerbit/crypto 2.3.13-d375893 → 2.4.0
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/LICENSE +202 -0
- package/dist/benchmark/hash.js +68 -27
- package/dist/benchmark/hash.js.map +1 -1
- package/dist/src/bytes.d.ts.map +1 -1
- package/dist/src/bytes.js +4 -2
- package/dist/src/bytes.js.map +1 -1
- package/dist/src/ed25519.js +209 -144
- package/dist/src/ed25519.js.map +1 -1
- package/dist/src/encryption.d.ts.map +1 -1
- package/dist/src/encryption.js +417 -295
- package/dist/src/encryption.js.map +1 -1
- package/dist/src/key.js +60 -25
- package/dist/src/key.js.map +1 -1
- package/dist/src/random.d.ts +1 -1
- package/dist/src/random.d.ts.map +1 -1
- package/dist/src/sepc256k1.js +202 -136
- package/dist/src/sepc256k1.js.map +1 -1
- package/dist/src/signature.js +139 -86
- package/dist/src/signature.js.map +1 -1
- package/dist/src/x25519.js +208 -141
- package/dist/src/x25519.js.map +1 -1
- package/package.json +12 -12
- package/src/bytes.ts +6 -2
- package/src/encryption.ts +3 -1
package/dist/src/x25519.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
6
27
|
};
|
|
7
|
-
var
|
|
8
|
-
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
9
34
|
};
|
|
10
|
-
var X25519PublicKey_1, X25519SecretKey_1, X25519Keypair_1;
|
|
11
35
|
import { field, fixedArray, variant } from "@dao-xyz/borsh";
|
|
12
36
|
import {} from "@libp2p/interface";
|
|
13
37
|
import sodium from "libsodium-wrappers";
|
|
@@ -16,143 +40,186 @@ import { Ed25519Keypair, Ed25519PublicKey } from "./ed25519.js";
|
|
|
16
40
|
import { Keypair, PrivateEncryptionKey, PublicKeyEncryptionKey, } from "./key.js";
|
|
17
41
|
import { toHexString } from "./utils.js";
|
|
18
42
|
export * from "./errors.js";
|
|
19
|
-
let X25519PublicKey =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
let X25519PublicKey = (() => {
|
|
44
|
+
let _classDecorators = [variant(0)];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
let _classSuper = PublicKeyEncryptionKey;
|
|
49
|
+
let _publicKey_decorators;
|
|
50
|
+
let _publicKey_initializers = [];
|
|
51
|
+
let _publicKey_extraInitializers = [];
|
|
52
|
+
var X25519PublicKey = class extends _classSuper {
|
|
53
|
+
static { _classThis = this; }
|
|
54
|
+
static {
|
|
55
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
56
|
+
_publicKey_decorators = [field({ type: fixedArray("u8", 32) })];
|
|
57
|
+
__esDecorate(null, null, _publicKey_decorators, { kind: "field", name: "publicKey", static: false, private: false, access: { has: obj => "publicKey" in obj, get: obj => obj.publicKey, set: (obj, value) => { obj.publicKey = value; } }, metadata: _metadata }, _publicKey_initializers, _publicKey_extraInitializers);
|
|
58
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
59
|
+
X25519PublicKey = _classThis = _classDescriptor.value;
|
|
60
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
61
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
31
62
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
X25519PublicKey
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
publicKey = __runInitializers(this, _publicKey_initializers, void 0);
|
|
64
|
+
constructor(properties) {
|
|
65
|
+
super();
|
|
66
|
+
__runInitializers(this, _publicKey_extraInitializers);
|
|
67
|
+
if (properties.publicKey.length !== 32) {
|
|
68
|
+
throw new Error("Expecting key to have length 32");
|
|
69
|
+
}
|
|
70
|
+
this.publicKey = properties.publicKey;
|
|
71
|
+
}
|
|
72
|
+
equals(other) {
|
|
73
|
+
if (other instanceof X25519PublicKey) {
|
|
74
|
+
return compare(this.publicKey, other.publicKey) === 0;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
return "x25519p/" + toHexString(this.publicKey);
|
|
80
|
+
}
|
|
81
|
+
static async from(ed25119PublicKey) {
|
|
82
|
+
await sodium.ready;
|
|
83
|
+
return new X25519PublicKey({
|
|
84
|
+
publicKey: sodium.crypto_sign_ed25519_pk_to_curve25519(ed25119PublicKey.publicKey),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static async fromPeerId(peerId) {
|
|
88
|
+
await sodium.ready;
|
|
89
|
+
const ed = Ed25519PublicKey.fromPeerId(peerId);
|
|
90
|
+
return X25519PublicKey.from(ed);
|
|
91
|
+
}
|
|
92
|
+
static async create() {
|
|
93
|
+
await sodium.ready;
|
|
94
|
+
return new X25519PublicKey({
|
|
95
|
+
publicKey: sodium.crypto_box_keypair().publicKey,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return X25519PublicKey = _classThis;
|
|
100
|
+
})();
|
|
63
101
|
export { X25519PublicKey };
|
|
64
|
-
let X25519SecretKey =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
102
|
+
let X25519SecretKey = (() => {
|
|
103
|
+
let _classDecorators = [variant(0)];
|
|
104
|
+
let _classDescriptor;
|
|
105
|
+
let _classExtraInitializers = [];
|
|
106
|
+
let _classThis;
|
|
107
|
+
let _classSuper = PrivateEncryptionKey;
|
|
108
|
+
let _secretKey_decorators;
|
|
109
|
+
let _secretKey_initializers = [];
|
|
110
|
+
let _secretKey_extraInitializers = [];
|
|
111
|
+
var X25519SecretKey = class extends _classSuper {
|
|
112
|
+
static { _classThis = this; }
|
|
113
|
+
static {
|
|
114
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
115
|
+
_secretKey_decorators = [field({ type: fixedArray("u8", 32) })];
|
|
116
|
+
__esDecorate(null, null, _secretKey_decorators, { kind: "field", name: "secretKey", static: false, private: false, access: { has: obj => "secretKey" in obj, get: obj => obj.secretKey, set: (obj, value) => { obj.secretKey = value; } }, metadata: _metadata }, _secretKey_initializers, _secretKey_extraInitializers);
|
|
117
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
118
|
+
X25519SecretKey = _classThis = _classDescriptor.value;
|
|
119
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
120
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
76
121
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
secretKey = __runInitializers(this, _secretKey_initializers, void 0);
|
|
123
|
+
constructor(properties) {
|
|
124
|
+
super();
|
|
125
|
+
__runInitializers(this, _secretKey_extraInitializers);
|
|
126
|
+
if (properties.secretKey.length !== 32) {
|
|
127
|
+
throw new Error("Expecting key to have length 32");
|
|
128
|
+
}
|
|
129
|
+
this.secretKey = properties.secretKey;
|
|
130
|
+
}
|
|
131
|
+
equals(other) {
|
|
132
|
+
if (other instanceof X25519SecretKey) {
|
|
133
|
+
return compare(this.secretKey, other.secretKey) === 0;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
toString() {
|
|
138
|
+
return "x25519s" + toHexString(this.secretKey);
|
|
139
|
+
}
|
|
140
|
+
async publicKey() {
|
|
141
|
+
return new X25519PublicKey({
|
|
142
|
+
publicKey: sodium.crypto_scalarmult_base(this.secretKey),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
static async from(ed25119Keypair) {
|
|
146
|
+
await sodium.ready;
|
|
147
|
+
return new X25519SecretKey({
|
|
148
|
+
secretKey: sodium.crypto_sign_ed25519_sk_to_curve25519(ed25119Keypair.privateKeyPublicKey),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
static async create() {
|
|
152
|
+
await sodium.ready;
|
|
153
|
+
return new X25519SecretKey({
|
|
154
|
+
secretKey: sodium.crypto_box_keypair().privateKey,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return X25519SecretKey = _classThis;
|
|
159
|
+
})();
|
|
108
160
|
export { X25519SecretKey };
|
|
109
|
-
let X25519Keypair =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
secretKey: await X25519SecretKey.from(ed25119Keypair),
|
|
134
|
-
});
|
|
135
|
-
return kp;
|
|
136
|
-
}
|
|
137
|
-
equals(other) {
|
|
138
|
-
if (other instanceof X25519Keypair_1) {
|
|
139
|
-
return (this.publicKey.equals(other.publicKey) &&
|
|
140
|
-
this.secretKey.equals(other.secretKey));
|
|
161
|
+
let X25519Keypair = (() => {
|
|
162
|
+
let _classDecorators = [variant(1)];
|
|
163
|
+
let _classDescriptor;
|
|
164
|
+
let _classExtraInitializers = [];
|
|
165
|
+
let _classThis;
|
|
166
|
+
let _classSuper = Keypair;
|
|
167
|
+
let _publicKey_decorators;
|
|
168
|
+
let _publicKey_initializers = [];
|
|
169
|
+
let _publicKey_extraInitializers = [];
|
|
170
|
+
let _secretKey_decorators;
|
|
171
|
+
let _secretKey_initializers = [];
|
|
172
|
+
let _secretKey_extraInitializers = [];
|
|
173
|
+
var X25519Keypair = class extends _classSuper {
|
|
174
|
+
static { _classThis = this; }
|
|
175
|
+
static {
|
|
176
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
177
|
+
_publicKey_decorators = [field({ type: X25519PublicKey })];
|
|
178
|
+
_secretKey_decorators = [field({ type: X25519SecretKey })];
|
|
179
|
+
__esDecorate(null, null, _publicKey_decorators, { kind: "field", name: "publicKey", static: false, private: false, access: { has: obj => "publicKey" in obj, get: obj => obj.publicKey, set: (obj, value) => { obj.publicKey = value; } }, metadata: _metadata }, _publicKey_initializers, _publicKey_extraInitializers);
|
|
180
|
+
__esDecorate(null, null, _secretKey_decorators, { kind: "field", name: "secretKey", static: false, private: false, access: { has: obj => "secretKey" in obj, get: obj => obj.secretKey, set: (obj, value) => { obj.secretKey = value; } }, metadata: _metadata }, _secretKey_initializers, _secretKey_extraInitializers);
|
|
181
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
182
|
+
X25519Keypair = _classThis = _classDescriptor.value;
|
|
183
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
184
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
141
185
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
186
|
+
publicKey = __runInitializers(this, _publicKey_initializers, void 0);
|
|
187
|
+
secretKey = (__runInitializers(this, _publicKey_extraInitializers), __runInitializers(this, _secretKey_initializers, void 0));
|
|
188
|
+
constructor(properties) {
|
|
189
|
+
super();
|
|
190
|
+
__runInitializers(this, _secretKey_extraInitializers);
|
|
191
|
+
this.publicKey = properties.publicKey;
|
|
192
|
+
this.secretKey = properties.secretKey;
|
|
193
|
+
}
|
|
194
|
+
static async create() {
|
|
195
|
+
await sodium.ready;
|
|
196
|
+
const generated = sodium.crypto_box_keypair();
|
|
197
|
+
const kp = new X25519Keypair({
|
|
198
|
+
publicKey: new X25519PublicKey({
|
|
199
|
+
publicKey: generated.publicKey,
|
|
200
|
+
}),
|
|
201
|
+
secretKey: new X25519SecretKey({
|
|
202
|
+
secretKey: generated.privateKey,
|
|
203
|
+
}),
|
|
204
|
+
});
|
|
205
|
+
return kp;
|
|
206
|
+
}
|
|
207
|
+
static async from(ed25119Keypair) {
|
|
208
|
+
const kp = new X25519Keypair({
|
|
209
|
+
publicKey: await X25519PublicKey.from(ed25119Keypair.publicKey),
|
|
210
|
+
secretKey: await X25519SecretKey.from(ed25119Keypair),
|
|
211
|
+
});
|
|
212
|
+
return kp;
|
|
213
|
+
}
|
|
214
|
+
equals(other) {
|
|
215
|
+
if (other instanceof X25519Keypair) {
|
|
216
|
+
return (this.publicKey.equals(other.publicKey) &&
|
|
217
|
+
this.secretKey.equals(other.secretKey));
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
return X25519Keypair = _classThis;
|
|
223
|
+
})();
|
|
157
224
|
export { X25519Keypair };
|
|
158
225
|
//# sourceMappingURL=x25519.js.map
|
package/dist/src/x25519.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x25519.js","sourceRoot":"","sources":["../../src/x25519.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"x25519.js","sourceRoot":"","sources":["../../src/x25519.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACN,OAAO,EACP,oBAAoB,EACpB,sBAAsB,GACtB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,cAAc,aAAa,CAAC;IAGf,eAAe;4BAD3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;YAEH,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,cAA8B;YAC/C,MAAM,EAAE,GAAG,IAAI,aAAa,CAAC;gBAC5B,SAAS,EAAE,MAAM,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;gBAC/D,SAAS,EAAE,MAAM,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC;aACrD,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,CAAC,KAAc;YACpB,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;gBACpC,OAAO,CACN,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;oBACtC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CACtC,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;;;;SA/CW,aAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/crypto",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Crypto fn",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -53,12 +53,6 @@
|
|
|
53
53
|
"./dist/src/random.js": "./dist/src/random.browser.js",
|
|
54
54
|
"./dist/src/ed25519-sign.js": "./dist/src/ed25519-sign.browser.js"
|
|
55
55
|
},
|
|
56
|
-
"scripts": {
|
|
57
|
-
"clean": "aegir clean",
|
|
58
|
-
"build": "aegir build --no-bundle",
|
|
59
|
-
"test": "aegir test",
|
|
60
|
-
"lint": "aegir lint"
|
|
61
|
-
},
|
|
62
56
|
"author": "dao.xyz",
|
|
63
57
|
"license": "MIT",
|
|
64
58
|
"devDependencies": {
|
|
@@ -68,18 +62,24 @@
|
|
|
68
62
|
"multiformats": "^13.4.1"
|
|
69
63
|
},
|
|
70
64
|
"dependencies": {
|
|
71
|
-
"@
|
|
72
|
-
"@dao-xyz/borsh": "^5.2.3",
|
|
65
|
+
"@dao-xyz/borsh": "^6.0.0",
|
|
73
66
|
"@stablelib/sha256": "^2.0.1",
|
|
74
67
|
"@ethersproject/wallet": "^5.8.0",
|
|
75
68
|
"@ethersproject/strings": "^5.7.0",
|
|
76
69
|
"@ethersproject/bytes": "^5.7.0",
|
|
77
70
|
"@libp2p/crypto": "^5.1.10",
|
|
78
|
-
"@libp2p/interface": "^3.
|
|
71
|
+
"@libp2p/interface": "^3.1.0",
|
|
79
72
|
"@libp2p/peer-id": "^6.0.1",
|
|
80
73
|
"@protobufjs/utf8": "^1.1.0",
|
|
81
74
|
"js-sha3": "^0.9.3",
|
|
82
75
|
"elliptic": "^6.6.1",
|
|
83
|
-
"libsodium-wrappers": "^0.7.15"
|
|
76
|
+
"libsodium-wrappers": "^0.7.15",
|
|
77
|
+
"@peerbit/cache": "2.2.0"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"clean": "aegir clean",
|
|
81
|
+
"build": "aegir build --no-bundle",
|
|
82
|
+
"test": "aegir test",
|
|
83
|
+
"lint": "aegir lint"
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|
package/src/bytes.ts
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
* @returns {Uint8Array}
|
|
4
4
|
*/
|
|
5
5
|
export const coerce = (o: any) => {
|
|
6
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
7
|
-
|
|
6
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
7
|
+
return o;
|
|
8
|
+
}
|
|
9
|
+
if (o instanceof ArrayBuffer) {
|
|
10
|
+
return new Uint8Array(o);
|
|
11
|
+
}
|
|
8
12
|
if (ArrayBuffer.isView(o)) {
|
|
9
13
|
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
10
14
|
}
|
package/src/encryption.ts
CHANGED
|
@@ -18,7 +18,9 @@ import { X25519Keypair, X25519PublicKey, X25519SecretKey } from "./x25519.js";
|
|
|
18
18
|
export * from "./errors.js";
|
|
19
19
|
|
|
20
20
|
export const equals = (array1?: Uint8Array, array2?: Uint8Array) => {
|
|
21
|
-
if (!!array1 !== !!array2)
|
|
21
|
+
if (!!array1 !== !!array2) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
22
24
|
if (!array1 || !array2) {
|
|
23
25
|
return false;
|
|
24
26
|
}
|