@peerbit/crypto 1.0.4 → 1.0.5

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.
@@ -24,7 +24,7 @@ export declare class DecryptedThing<T> extends MaybeEncrypted<T> {
24
24
  });
25
25
  _value?: T;
26
26
  getValue(clazz: AbstractType<T>): T;
27
- encrypt(x25519Keypair: X25519Keypair, ...recieverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]): Promise<EncryptedThing<T>>;
27
+ encrypt(x25519Keypair: X25519Keypair, ...receiverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]): Promise<EncryptedThing<T>>;
28
28
  get decrypted(): DecryptedThing<T>;
29
29
  decrypt(): DecryptedThing<T>;
30
30
  equals(other: MaybeEncrypted<T>): boolean;
@@ -42,10 +42,10 @@ export declare class CipherWithNonce {
42
42
  }
43
43
  export declare class K {
44
44
  _encryptedKey: CipherWithNonce;
45
- _recieverPublicKey: X25519PublicKey;
45
+ _receiverPublicKey: X25519PublicKey;
46
46
  constructor(props?: {
47
47
  encryptedKey: CipherWithNonce;
48
- recieverPublicKey: X25519PublicKey;
48
+ receiverPublicKey: X25519PublicKey;
49
49
  });
50
50
  equals(other: K): boolean;
51
51
  }
@@ -59,25 +59,25 @@ export let DecryptedThing = DecryptedThing_1 = class DecryptedThing extends Mayb
59
59
  }
60
60
  return deserialize(this._data, clazz);
61
61
  }
62
- async encrypt(x25519Keypair, ...recieverPublicKeys) {
62
+ async encrypt(x25519Keypair, ...receiverPublicKeys) {
63
63
  const bytes = serialize(this);
64
64
  const epheremalKey = sodium.crypto_secretbox_keygen();
65
65
  const nonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodim random
66
66
  const cipher = sodium.crypto_secretbox_easy(bytes, nonce, epheremalKey);
67
- const recieverX25519PublicKeys = await Promise.all(recieverPublicKeys.map((key) => {
67
+ const receiverX25519PublicKeys = await Promise.all(receiverPublicKeys.map((key) => {
68
68
  if (key instanceof Ed25519PublicKey) {
69
69
  return X25519PublicKey.from(key);
70
70
  }
71
71
  return key;
72
72
  }));
73
- const ks = recieverX25519PublicKeys.map((recieverPublicKey) => {
73
+ const ks = receiverX25519PublicKeys.map((receiverPublicKey) => {
74
74
  const kNonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodium random
75
75
  return new K({
76
76
  encryptedKey: new CipherWithNonce({
77
- cipher: sodium.crypto_box_easy(epheremalKey, kNonce, recieverPublicKey.publicKey, x25519Keypair.secretKey.secretKey),
77
+ cipher: sodium.crypto_box_easy(epheremalKey, kNonce, receiverPublicKey.publicKey, x25519Keypair.secretKey.secretKey),
78
78
  nonce: kNonce,
79
79
  }),
80
- recieverPublicKey,
80
+ receiverPublicKey,
81
81
  });
82
82
  });
83
83
  const enc = new EncryptedThing({
@@ -152,17 +152,17 @@ CipherWithNonce = CipherWithNonce_1 = __decorate([
152
152
  ], CipherWithNonce);
153
153
  export let K = K_1 = class K {
154
154
  _encryptedKey;
155
- _recieverPublicKey;
155
+ _receiverPublicKey;
156
156
  constructor(props) {
157
157
  if (props) {
158
158
  this._encryptedKey = props.encryptedKey;
159
- this._recieverPublicKey = props.recieverPublicKey;
159
+ this._receiverPublicKey = props.receiverPublicKey;
160
160
  }
161
161
  }
162
162
  equals(other) {
163
163
  if (other instanceof K_1) {
164
164
  return (this._encryptedKey.equals(other._encryptedKey) &&
165
- this._recieverPublicKey.equals(other._recieverPublicKey));
165
+ this._receiverPublicKey.equals(other._receiverPublicKey));
166
166
  }
167
167
  else {
168
168
  return false;
@@ -176,7 +176,7 @@ __decorate([
176
176
  __decorate([
177
177
  field({ type: X25519PublicKey }),
178
178
  __metadata("design:type", X25519PublicKey)
179
- ], K.prototype, "_recieverPublicKey", void 0);
179
+ ], K.prototype, "_receiverPublicKey", void 0);
180
180
  K = K_1 = __decorate([
181
181
  variant(0),
182
182
  __metadata("design:paramtypes", [Object])
@@ -252,7 +252,7 @@ export let EncryptedThing = EncryptedThing_1 = class EncryptedThing extends Mayb
252
252
  let key;
253
253
  if (keyResolver instanceof X25519Keypair) {
254
254
  for (const [i, k] of this._envelope._ks.entries()) {
255
- if (k._recieverPublicKey.equals(keyResolver.publicKey)) {
255
+ if (k._receiverPublicKey.equals(keyResolver.publicKey)) {
256
256
  key = {
257
257
  index: i,
258
258
  keypair: keyResolver,
@@ -262,7 +262,7 @@ export let EncryptedThing = EncryptedThing_1 = class EncryptedThing extends Mayb
262
262
  }
263
263
  else {
264
264
  for (const [i, k] of this._envelope._ks.entries()) {
265
- const exported = await keyResolver.exportByKey(k._recieverPublicKey);
265
+ const exported = await keyResolver.exportByKey(k._receiverPublicKey);
266
266
  if (exported) {
267
267
  key = {
268
268
  index: i,
@@ -112,7 +112,7 @@ export class Libp2pKeychain {
112
112
  this.cacheKey(keypair, id);
113
113
  // import as ed
114
114
  await this.keychain.importPeer(base58btc.encode(id), receiverKeyPeerId);
115
- // import as x so we can decrypt messages with this public key (if recieved any)
115
+ // import as x so we can decrypt messages with this public key (if received any)
116
116
  const xKeypair = await X25519Keypair.from(keypair);
117
117
  this.cacheKey(xKeypair);
118
118
  await this.keychain.importPeer(base58btc.encode(xKeypair.publicKey.bytes), receiverKeyPeerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/crypto",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Crypto fn",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -51,5 +51,5 @@
51
51
  "@peerbit/uint8arrays": "3.0.1",
52
52
  "libsodium-wrappers": "^0.7.11"
53
53
  },
54
- "gitHead": "32f61ad9f3d5906e13d46f2a80f61c1826a3e817"
54
+ "gitHead": "464e807d679e24b897b7811ac99d6f85fbd756f9"
55
55
  }
package/src/encryption.ts CHANGED
@@ -71,15 +71,15 @@ export class DecryptedThing<T> extends MaybeEncrypted<T> {
71
71
 
72
72
  async encrypt(
73
73
  x25519Keypair: X25519Keypair,
74
- ...recieverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]
74
+ ...receiverPublicKeys: (X25519PublicKey | Ed25519PublicKey)[]
75
75
  ): Promise<EncryptedThing<T>> {
76
76
  const bytes = serialize(this);
77
77
  const epheremalKey = sodium.crypto_secretbox_keygen();
78
78
  const nonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodim random
79
79
  const cipher = sodium.crypto_secretbox_easy(bytes, nonce, epheremalKey);
80
80
 
81
- const recieverX25519PublicKeys = await Promise.all(
82
- recieverPublicKeys.map((key) => {
81
+ const receiverX25519PublicKeys = await Promise.all(
82
+ receiverPublicKeys.map((key) => {
83
83
  if (key instanceof Ed25519PublicKey) {
84
84
  return X25519PublicKey.from(key);
85
85
  }
@@ -87,19 +87,19 @@ export class DecryptedThing<T> extends MaybeEncrypted<T> {
87
87
  })
88
88
  );
89
89
 
90
- const ks = recieverX25519PublicKeys.map((recieverPublicKey) => {
90
+ const ks = receiverX25519PublicKeys.map((receiverPublicKey) => {
91
91
  const kNonce = randomBytes(NONCE_LENGTH); // crypto random is faster than sodium random
92
92
  return new K({
93
93
  encryptedKey: new CipherWithNonce({
94
94
  cipher: sodium.crypto_box_easy(
95
95
  epheremalKey,
96
96
  kNonce,
97
- recieverPublicKey.publicKey,
97
+ receiverPublicKey.publicKey,
98
98
  x25519Keypair.secretKey.secretKey
99
99
  ),
100
100
  nonce: kNonce,
101
101
  }),
102
- recieverPublicKey,
102
+ receiverPublicKey,
103
103
  });
104
104
  });
105
105
 
@@ -172,15 +172,15 @@ export class K {
172
172
  _encryptedKey: CipherWithNonce;
173
173
 
174
174
  @field({ type: X25519PublicKey })
175
- _recieverPublicKey: X25519PublicKey;
175
+ _receiverPublicKey: X25519PublicKey;
176
176
 
177
177
  constructor(props?: {
178
178
  encryptedKey: CipherWithNonce;
179
- recieverPublicKey: X25519PublicKey;
179
+ receiverPublicKey: X25519PublicKey;
180
180
  }) {
181
181
  if (props) {
182
182
  this._encryptedKey = props.encryptedKey;
183
- this._recieverPublicKey = props.recieverPublicKey;
183
+ this._receiverPublicKey = props.receiverPublicKey;
184
184
  }
185
185
  }
186
186
 
@@ -188,7 +188,7 @@ export class K {
188
188
  if (other instanceof K) {
189
189
  return (
190
190
  this._encryptedKey.equals(other._encryptedKey) &&
191
- this._recieverPublicKey.equals(other._recieverPublicKey)
191
+ this._receiverPublicKey.equals(other._receiverPublicKey)
192
192
  );
193
193
  } else {
194
194
  return false;
@@ -281,7 +281,7 @@ export class EncryptedThing<T> extends MaybeEncrypted<T> {
281
281
  let key: { index: number; keypair: X25519Keypair } | undefined;
282
282
  if (keyResolver instanceof X25519Keypair) {
283
283
  for (const [i, k] of this._envelope._ks.entries()) {
284
- if (k._recieverPublicKey.equals(keyResolver.publicKey)) {
284
+ if (k._receiverPublicKey.equals(keyResolver.publicKey)) {
285
285
  key = {
286
286
  index: i,
287
287
  keypair: keyResolver,
@@ -290,7 +290,7 @@ export class EncryptedThing<T> extends MaybeEncrypted<T> {
290
290
  }
291
291
  } else {
292
292
  for (const [i, k] of this._envelope._ks.entries()) {
293
- const exported = await keyResolver.exportByKey(k._recieverPublicKey);
293
+ const exported = await keyResolver.exportByKey(k._receiverPublicKey);
294
294
  if (exported) {
295
295
  key = {
296
296
  index: i,
package/src/keychain.ts CHANGED
@@ -165,7 +165,7 @@ export class Libp2pKeychain implements Keychain {
165
165
  // import as ed
166
166
  await this.keychain.importPeer(base58btc.encode(id), receiverKeyPeerId);
167
167
 
168
- // import as x so we can decrypt messages with this public key (if recieved any)
168
+ // import as x so we can decrypt messages with this public key (if received any)
169
169
  const xKeypair = await X25519Keypair.from(keypair);
170
170
  this.cacheKey(xKeypair);
171
171
  await this.keychain.importPeer(