@sudoplatform/sudo-common 7.0.0 → 7.1.2

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.
@@ -178,40 +178,20 @@ describe('DefaultSudoKeyManager', () => {
178
178
  })
179
179
 
180
180
  describe('doesSymmetricKeyExist', () => {
181
- it('should call crypto provider doesSymmetricKeyExists', async () => {
181
+ it('should call crypto provider doesSymmetricKeyExist', async () => {
182
182
  when(
183
- sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
183
+ sudoCryptoProviderMock.doesSymmetricKeyExist(anything()),
184
184
  ).thenResolve(true)
185
185
 
186
186
  await expect(
187
187
  sudoKeyManager.doesSymmetricKeyExist('VpnKey'),
188
188
  ).resolves.toEqual(true)
189
189
  const [actualKey] = capture(
190
- sudoCryptoProviderMock.doesSymmetricKeyExists,
190
+ sudoCryptoProviderMock.doesSymmetricKeyExist,
191
191
  ).first()
192
192
  expect(actualKey).toStrictEqual('VpnKey')
193
193
 
194
- verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
195
- verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).never()
196
- })
197
- })
198
-
199
- describe('doesSymmetricKeyExists', () => {
200
- it('should call crypto provider doesSymmetricKeyExists', async () => {
201
- when(
202
- sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
203
- ).thenResolve(true)
204
-
205
- await expect(
206
- sudoKeyManager.doesSymmetricKeyExists('VpnKey'),
207
- ).resolves.toEqual(true)
208
- const [actualKey] = capture(
209
- sudoCryptoProviderMock.doesSymmetricKeyExists,
210
- ).first()
211
- expect(actualKey).toStrictEqual('VpnKey')
212
-
213
- verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
214
- verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).never()
194
+ verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).once()
215
195
  })
216
196
  })
217
197
 
@@ -302,8 +282,8 @@ describe('DefaultSudoKeyManager', () => {
302
282
  })
303
283
 
304
284
  describe('doesPrivateKeyExist', () => {
305
- it('should call crypto provider doesPrivateKeyExists', async () => {
306
- when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
285
+ it('should call crypto provider doesPrivateKeyExist', async () => {
286
+ when(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).thenResolve(
307
287
  true,
308
288
  )
309
289
 
@@ -312,32 +292,11 @@ describe('DefaultSudoKeyManager', () => {
312
292
  ).resolves.toBeTruthy()
313
293
 
314
294
  const [actualKeyName] = capture(
315
- sudoCryptoProviderMock.doesPrivateKeyExists,
316
- ).first()
317
- expect(actualKeyName).toStrictEqual('VpnKeyPair')
318
-
319
- verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
320
- verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).never()
321
- })
322
- })
323
-
324
- describe('doesPrivateKeyExists', () => {
325
- it('should call crypto provider doesPrivateKeyExists', async () => {
326
- when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
327
- true,
328
- )
329
-
330
- await expect(
331
- sudoKeyManager.doesPrivateKeyExists('VpnKeyPair'),
332
- ).resolves.toBeTruthy()
333
-
334
- const [actualKeyName] = capture(
335
- sudoCryptoProviderMock.doesPrivateKeyExists,
295
+ sudoCryptoProviderMock.doesPrivateKeyExist,
336
296
  ).first()
337
297
  expect(actualKeyName).toStrictEqual('VpnKeyPair')
338
298
 
339
- verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
340
- verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).never()
299
+ verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).once()
341
300
  })
342
301
  })
343
302
 
@@ -21,6 +21,21 @@ describe('Base64', () => {
21
21
  )
22
22
  })
23
23
 
24
+ it('Base 64 URL safe encodes an ArrayBuffer, and decodes to an ArrayBuffer', () => {
25
+ const result = 'http://localhost:3000/search?q=url+test&unit=jest+test'
26
+ const encoded = Base64.urlSafeEncode({ input: Buffer.from(result, 'utf8') })
27
+ expect(Base64.UrlSafeValidate(encoded)).toStrictEqual(true)
28
+ const decoded = Base64.urlSafeDecode({ encoded })
29
+ expect(Buffer.from(decoded).toString('utf8')).toStrictEqual(result)
30
+ })
31
+ it('Base 64 URL safe encodes a string, validates, and decodes to a string', () => {
32
+ const result = 'http://localhost:3000/search?q=url+test&unit=jest+test'
33
+ const encoded = Base64.urlSafeEncodeString({ input: result })
34
+ expect(Base64.UrlSafeValidate(encoded)).toStrictEqual(true)
35
+ const decoded = Base64.urlSafeDecodeString({ encoded })
36
+ expect(decoded).toStrictEqual(result)
37
+ })
38
+
24
39
  const encodedPK =
25
40
  'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt88ya9gRqtqPA75DyRMY13SkDIHveCqCpngTnMUmLpRvd7HigAIkVEfKWqxG7+QdUPUUr2heBkG3WoGgljGXkMRNdcZek4LZ3+W7o2vCrp6h/19bmPxgQDRSasT1Br7zFk2yKmV/WBwI+9SoIqNU/oxO9ucdK6D0jL/Po32UfCFs+zsNE7Hg3gXNR/fihqnlE+oZETlFmF7QkxXtTaPv+acTQCrWT1V4f+hMQ4JBFKDORZ2Agb0L3Fn45R0rsXofkyvUNMxRztffbZm1m6pqysRRgOgHEQGULCGxlO6VgkhJFhxfQd1iLyK0cYRyg53t5dr9aO1tRAM2S2Bn65sKewIDAQAB'
26
41
  const decodedPKBuffer = Buffer.from(encodedPK, 'base64')
package/github/yarn.lock CHANGED
@@ -5568,10 +5568,10 @@ typedarray-to-buffer@^3.1.5:
5568
5568
  dependencies:
5569
5569
  is-typedarray "^1.0.0"
5570
5570
 
5571
- typedoc@^0.23.8:
5572
- version "0.23.8"
5573
- resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.23.8.tgz#6837fb2732f73e7aa61b46a4fbe77a301473998d"
5574
- integrity sha512-NLRTY/7XSrhiowR3xnH/nlfTnHk+dkzhHWAMT8guoZ6RHCQZIu3pJREMCqzdkWVCC5+dr9We7TtNeprR3Qy6Ag==
5571
+ typedoc@^0.23.9:
5572
+ version "0.23.9"
5573
+ resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.23.9.tgz#fd94451abd039513ab4fda58208fa0e5631e080b"
5574
+ integrity sha512-rvWci2KHwteVUufZjjtIy/4PIHiE66t4VW4Ob6pezV//GHZ9Px0CHE5iq032GZzKONJWnNb+EJsrQv32INRvxA==
5575
5575
  dependencies:
5576
5576
  lunr "^2.3.9"
5577
5577
  marked "^4.0.16"
@@ -76,14 +76,6 @@ export interface SudoCryptoProvider {
76
76
  * @param name The name of the symmetric key.
77
77
  */
78
78
  doesSymmetricKeyExist(name: string): Promise<boolean>;
79
- /**
80
- * Checks to see if the specified symmetric key exists.
81
- *
82
- * @param name The name of the symmetric key.
83
- *
84
- * @deprecated Use doesSymmetricKeyExist
85
- */
86
- doesSymmetricKeyExists(name: string): Promise<boolean>;
87
79
  /**
88
80
  * Deletes a symmetric key from the secure store.
89
81
  *
@@ -164,14 +156,6 @@ export interface SudoCryptoProvider {
164
156
  * @param name The name of the private key.
165
157
  */
166
158
  doesPrivateKeyExist(name: string): Promise<boolean>;
167
- /**
168
- * Checks to see if the specified private key exists.
169
- *
170
- * @param name The name of the private key.
171
- *
172
- * @deprecated Use doesPrivateKeyExist
173
- */
174
- doesPrivateKeyExists(name: string): Promise<boolean>;
175
159
  /**
176
160
  * Adds a public key to the secure store.
177
161
  *
@@ -57,14 +57,6 @@ export interface SudoKeyManager {
57
57
  * @param name The name of the symmetric key.
58
58
  */
59
59
  doesSymmetricKeyExist(name: string): Promise<boolean>;
60
- /**
61
- * Checks to see if the specified symmetric key exists.
62
- *
63
- * @param name The name of the symmetric key.
64
- *
65
- * @deprecated Use doesSymmetricKeyExist
66
- */
67
- doesSymmetricKeyExists(name: string): Promise<boolean>;
68
60
  /**
69
61
  * Deletes a symmetric key from the secure store.
70
62
  *
@@ -92,14 +84,6 @@ export interface SudoKeyManager {
92
84
  * @param name The name of the private key.
93
85
  */
94
86
  doesPrivateKeyExist(name: string): Promise<boolean>;
95
- /**
96
- * Checks to see if the specified private key exists.
97
- *
98
- * @param name The name of the private key.
99
- *
100
- * @deprecated Use doesPrivateKeyExist
101
- */
102
- doesPrivateKeyExists(name: string): Promise<boolean>;
103
87
  /**
104
88
  * Adds a public key to the secure store.
105
89
  *
@@ -332,13 +316,11 @@ export declare class DefaultSudoKeyManager implements SudoKeyManager {
332
316
  addSymmetricKey(key: ArrayBuffer, name: string): Promise<void>;
333
317
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>;
334
318
  doesSymmetricKeyExist(name: string): Promise<boolean>;
335
- doesSymmetricKeyExists(name: string): Promise<boolean>;
336
319
  deleteSymmetricKey(name: string): Promise<void>;
337
320
  generateKeyPair(name: string): Promise<void>;
338
321
  addPrivateKey(key: ArrayBuffer, name: string): Promise<void>;
339
322
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>;
340
323
  doesPrivateKeyExist(name: string): Promise<boolean>;
341
- doesPrivateKeyExists(name: string): Promise<boolean>;
342
324
  addPublicKey(key: ArrayBuffer, name: string): Promise<void>;
343
325
  deletePublicKey(name: string): Promise<void>;
344
326
  getPublicKey(name: string): Promise<PublicKey | undefined>;
@@ -50,11 +50,7 @@ class DefaultSudoKeyManager {
50
50
  }
51
51
 
52
52
  doesSymmetricKeyExist(name) {
53
- return this.sudoCryptoProvider.doesSymmetricKeyExists(name);
54
- }
55
-
56
- doesSymmetricKeyExists(name) {
57
- return this.sudoCryptoProvider.doesSymmetricKeyExists(name);
53
+ return this.sudoCryptoProvider.doesSymmetricKeyExist(name);
58
54
  }
59
55
 
60
56
  deleteSymmetricKey(name) {
@@ -74,11 +70,7 @@ class DefaultSudoKeyManager {
74
70
  }
75
71
 
76
72
  doesPrivateKeyExist(name) {
77
- return this.sudoCryptoProvider.doesPrivateKeyExists(name);
78
- }
79
-
80
- doesPrivateKeyExists(name) {
81
- return this.sudoCryptoProvider.doesPrivateKeyExists(name);
73
+ return this.sudoCryptoProvider.doesPrivateKeyExist(name);
82
74
  }
83
75
 
84
76
  addPublicKey(key, name) {
@@ -2,8 +2,43 @@
2
2
  * Utility class for Base64 encoding and decoding.
3
3
  */
4
4
  export declare class Base64 {
5
+ private static URLSafeEncodeTransform;
6
+ private static URLSafeDecodeTransform;
5
7
  static decode(encoded: string): ArrayBuffer;
6
8
  static encode(buffer: ArrayBuffer): string;
7
9
  static decodeString(encoded: string): string;
8
10
  static encodeString(string: string): string;
11
+ /**
12
+ * Encode a URL safe ArrayBuffer
13
+ * @param {ArrayBuffer} input buffer to be encoded
14
+ * @returns {string} encoded string
15
+ */
16
+ static urlSafeEncode({ input }: {
17
+ input: ArrayBuffer;
18
+ }): string;
19
+ /**
20
+ * Decode into a URL safe ArrayBuffer
21
+ * @param {string} input string to be decoded
22
+ * @returns {ArrayBuffer} decoded ArrayBuffer
23
+ */
24
+ static urlSafeDecode({ encoded }: {
25
+ encoded: string;
26
+ }): ArrayBuffer;
27
+ /**
28
+ * Encode a URL safe string
29
+ * @param {string} input string to be encoded
30
+ * @returns {string} encoded string
31
+ */
32
+ static urlSafeEncodeString({ input }: {
33
+ input: string;
34
+ }): string;
35
+ /**
36
+ * Decode a URL safe string
37
+ * @param {string} input string to be decoded
38
+ * @returns {string} decoded string
39
+ */
40
+ static urlSafeDecodeString({ encoded }: {
41
+ encoded: string;
42
+ }): string;
43
+ static UrlSafeValidate(encoded: string): boolean;
9
44
  }
@@ -11,6 +11,17 @@ var _buffer = require("./buffer");
11
11
  * Utility class for Base64 encoding and decoding.
12
12
  */
13
13
  class Base64 {
14
+ static URLSafeEncodeTransform(input) {
15
+ return input.replace(/\+/g, '-') // Convert '+' to '-'
16
+ .replace(/\//g, '_') // Convert '/' to '_'
17
+ .replace(/=+$/, ''); // Remove ending '='
18
+ }
19
+
20
+ static URLSafeDecodeTransform(input) {
21
+ return input.replace(/\-/g, '+') // Convert '-' to '+'
22
+ .replace(/\_/g, '/'); // Convert '_' to '/'
23
+ }
24
+
14
25
  static decode(encoded) {
15
26
  return _buffer.Buffer.fromString(atob(encoded));
16
27
  }
@@ -26,6 +37,60 @@ class Base64 {
26
37
  static encodeString(string) {
27
38
  return btoa(string);
28
39
  }
40
+ /**
41
+ * Encode a URL safe ArrayBuffer
42
+ * @param {ArrayBuffer} input buffer to be encoded
43
+ * @returns {string} encoded string
44
+ */
45
+
46
+
47
+ static urlSafeEncode({
48
+ input
49
+ }) {
50
+ return this.URLSafeEncodeTransform(this.encode(input));
51
+ }
52
+ /**
53
+ * Decode into a URL safe ArrayBuffer
54
+ * @param {string} input string to be decoded
55
+ * @returns {ArrayBuffer} decoded ArrayBuffer
56
+ */
57
+
58
+
59
+ static urlSafeDecode({
60
+ encoded
61
+ }) {
62
+ encoded = this.URLSafeDecodeTransform(encoded);
63
+ return this.decode(encoded);
64
+ }
65
+ /**
66
+ * Encode a URL safe string
67
+ * @param {string} input string to be encoded
68
+ * @returns {string} encoded string
69
+ */
70
+
71
+
72
+ static urlSafeEncodeString({
73
+ input
74
+ }) {
75
+ return this.URLSafeEncodeTransform(this.encodeString(input));
76
+ }
77
+ /**
78
+ * Decode a URL safe string
79
+ * @param {string} input string to be decoded
80
+ * @returns {string} decoded string
81
+ */
82
+
83
+
84
+ static urlSafeDecodeString({
85
+ encoded
86
+ }) {
87
+ encoded = this.URLSafeDecodeTransform(encoded);
88
+ return Buffer.from(this.decode(encoded)).toString('utf8');
89
+ }
90
+
91
+ static UrlSafeValidate(encoded) {
92
+ return /^[A-Za-z0-9\-_]+$/.test(encoded);
93
+ }
29
94
 
30
95
  }
31
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudoplatform/sudo-common",
3
- "version": "7.0.0",
3
+ "version": "7.1.2",
4
4
  "author": "Anonyome Labs, Inc.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -77,7 +77,7 @@
77
77
  "prettier": "^2.7.1",
78
78
  "rimraf": "^3.0.2",
79
79
  "ts-mockito": "^2.6.1",
80
- "typedoc": "^0.23.8",
80
+ "typedoc": "^0.23.9",
81
81
  "typescript": "^4.7.4"
82
82
  },
83
83
  "outdatedSuppressions": {
@@ -93,15 +93,6 @@ export interface SudoCryptoProvider {
93
93
  */
94
94
  doesSymmetricKeyExist(name: string): Promise<boolean>
95
95
 
96
- /**
97
- * Checks to see if the specified symmetric key exists.
98
- *
99
- * @param name The name of the symmetric key.
100
- *
101
- * @deprecated Use doesSymmetricKeyExist
102
- */
103
- doesSymmetricKeyExists(name: string): Promise<boolean>
104
-
105
96
  /**
106
97
  * Deletes a symmetric key from the secure store.
107
98
  *
@@ -201,15 +192,6 @@ export interface SudoCryptoProvider {
201
192
  */
202
193
  doesPrivateKeyExist(name: string): Promise<boolean>
203
194
 
204
- /**
205
- * Checks to see if the specified private key exists.
206
- *
207
- * @param name The name of the private key.
208
- *
209
- * @deprecated Use doesPrivateKeyExist
210
- */
211
- doesPrivateKeyExists(name: string): Promise<boolean>
212
-
213
195
  /**
214
196
  * Adds a public key to the secure store.
215
197
  *
@@ -70,15 +70,6 @@ export interface SudoKeyManager {
70
70
  */
71
71
  doesSymmetricKeyExist(name: string): Promise<boolean>
72
72
 
73
- /**
74
- * Checks to see if the specified symmetric key exists.
75
- *
76
- * @param name The name of the symmetric key.
77
- *
78
- * @deprecated Use doesSymmetricKeyExist
79
- */
80
- doesSymmetricKeyExists(name: string): Promise<boolean>
81
-
82
73
  /**
83
74
  * Deletes a symmetric key from the secure store.
84
75
  *
@@ -110,15 +101,6 @@ export interface SudoKeyManager {
110
101
  */
111
102
  doesPrivateKeyExist(name: string): Promise<boolean>
112
103
 
113
- /**
114
- * Checks to see if the specified private key exists.
115
- *
116
- * @param name The name of the private key.
117
- *
118
- * @deprecated Use doesPrivateKeyExist
119
- */
120
- doesPrivateKeyExists(name: string): Promise<boolean>
121
-
122
104
  /**
123
105
  * Adds a public key to the secure store.
124
106
  *
@@ -447,11 +429,7 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
447
429
  }
448
430
 
449
431
  public doesSymmetricKeyExist(name: string): Promise<boolean> {
450
- return this.sudoCryptoProvider.doesSymmetricKeyExists(name)
451
- }
452
-
453
- public doesSymmetricKeyExists(name: string): Promise<boolean> {
454
- return this.sudoCryptoProvider.doesSymmetricKeyExists(name)
432
+ return this.sudoCryptoProvider.doesSymmetricKeyExist(name)
455
433
  }
456
434
 
457
435
  public deleteSymmetricKey(name: string): Promise<void> {
@@ -471,11 +449,7 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
471
449
  }
472
450
 
473
451
  public doesPrivateKeyExist(name: string): Promise<boolean> {
474
- return this.sudoCryptoProvider.doesPrivateKeyExists(name)
475
- }
476
-
477
- public doesPrivateKeyExists(name: string): Promise<boolean> {
478
- return this.sudoCryptoProvider.doesPrivateKeyExists(name)
452
+ return this.sudoCryptoProvider.doesPrivateKeyExist(name)
479
453
  }
480
454
 
481
455
  public addPublicKey(key: ArrayBuffer, name: string): Promise<void> {
@@ -3,6 +3,18 @@ import { Buffer as BufferUtil } from './buffer'
3
3
  * Utility class for Base64 encoding and decoding.
4
4
  */
5
5
  export class Base64 {
6
+ private static URLSafeEncodeTransform(input: string): string {
7
+ return input
8
+ .replace(/\+/g, '-') // Convert '+' to '-'
9
+ .replace(/\//g, '_') // Convert '/' to '_'
10
+ .replace(/=+$/, '') // Remove ending '='
11
+ }
12
+ private static URLSafeDecodeTransform(input: string): string {
13
+ return input
14
+ .replace(/\-/g, '+') // Convert '-' to '+'
15
+ .replace(/\_/g, '/') // Convert '_' to '/'
16
+ }
17
+
6
18
  static decode(encoded: string): ArrayBuffer {
7
19
  return BufferUtil.fromString(atob(encoded))
8
20
  }
@@ -18,4 +30,46 @@ export class Base64 {
18
30
  static encodeString(string: string): string {
19
31
  return btoa(string)
20
32
  }
33
+
34
+ /**
35
+ * Encode a URL safe ArrayBuffer
36
+ * @param {ArrayBuffer} input buffer to be encoded
37
+ * @returns {string} encoded string
38
+ */
39
+ static urlSafeEncode({ input }: { input: ArrayBuffer }): string {
40
+ return this.URLSafeEncodeTransform(this.encode(input))
41
+ }
42
+
43
+ /**
44
+ * Decode into a URL safe ArrayBuffer
45
+ * @param {string} input string to be decoded
46
+ * @returns {ArrayBuffer} decoded ArrayBuffer
47
+ */
48
+ static urlSafeDecode({ encoded }: { encoded: string }): ArrayBuffer {
49
+ encoded = this.URLSafeDecodeTransform(encoded)
50
+ return this.decode(encoded)
51
+ }
52
+
53
+ /**
54
+ * Encode a URL safe string
55
+ * @param {string} input string to be encoded
56
+ * @returns {string} encoded string
57
+ */
58
+ static urlSafeEncodeString({ input }: { input: string }): string {
59
+ return this.URLSafeEncodeTransform(this.encodeString(input))
60
+ }
61
+
62
+ /**
63
+ * Decode a URL safe string
64
+ * @param {string} input string to be decoded
65
+ * @returns {string} decoded string
66
+ */
67
+ static urlSafeDecodeString({ encoded }: { encoded: string }): string {
68
+ encoded = this.URLSafeDecodeTransform(encoded)
69
+ return Buffer.from(this.decode(encoded)).toString('utf8')
70
+ }
71
+
72
+ static UrlSafeValidate(encoded: string): boolean {
73
+ return /^[A-Za-z0-9\-_]+$/.test(encoded)
74
+ }
21
75
  }
@@ -178,40 +178,20 @@ describe('DefaultSudoKeyManager', () => {
178
178
  })
179
179
 
180
180
  describe('doesSymmetricKeyExist', () => {
181
- it('should call crypto provider doesSymmetricKeyExists', async () => {
181
+ it('should call crypto provider doesSymmetricKeyExist', async () => {
182
182
  when(
183
- sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
183
+ sudoCryptoProviderMock.doesSymmetricKeyExist(anything()),
184
184
  ).thenResolve(true)
185
185
 
186
186
  await expect(
187
187
  sudoKeyManager.doesSymmetricKeyExist('VpnKey'),
188
188
  ).resolves.toEqual(true)
189
189
  const [actualKey] = capture(
190
- sudoCryptoProviderMock.doesSymmetricKeyExists,
190
+ sudoCryptoProviderMock.doesSymmetricKeyExist,
191
191
  ).first()
192
192
  expect(actualKey).toStrictEqual('VpnKey')
193
193
 
194
- verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
195
- verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).never()
196
- })
197
- })
198
-
199
- describe('doesSymmetricKeyExists', () => {
200
- it('should call crypto provider doesSymmetricKeyExists', async () => {
201
- when(
202
- sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
203
- ).thenResolve(true)
204
-
205
- await expect(
206
- sudoKeyManager.doesSymmetricKeyExists('VpnKey'),
207
- ).resolves.toEqual(true)
208
- const [actualKey] = capture(
209
- sudoCryptoProviderMock.doesSymmetricKeyExists,
210
- ).first()
211
- expect(actualKey).toStrictEqual('VpnKey')
212
-
213
- verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
214
- verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).never()
194
+ verify(sudoCryptoProviderMock.doesSymmetricKeyExist(anything())).once()
215
195
  })
216
196
  })
217
197
 
@@ -302,8 +282,8 @@ describe('DefaultSudoKeyManager', () => {
302
282
  })
303
283
 
304
284
  describe('doesPrivateKeyExist', () => {
305
- it('should call crypto provider doesPrivateKeyExists', async () => {
306
- when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
285
+ it('should call crypto provider doesPrivateKeyExist', async () => {
286
+ when(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).thenResolve(
307
287
  true,
308
288
  )
309
289
 
@@ -312,32 +292,11 @@ describe('DefaultSudoKeyManager', () => {
312
292
  ).resolves.toBeTruthy()
313
293
 
314
294
  const [actualKeyName] = capture(
315
- sudoCryptoProviderMock.doesPrivateKeyExists,
316
- ).first()
317
- expect(actualKeyName).toStrictEqual('VpnKeyPair')
318
-
319
- verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
320
- verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).never()
321
- })
322
- })
323
-
324
- describe('doesPrivateKeyExists', () => {
325
- it('should call crypto provider doesPrivateKeyExists', async () => {
326
- when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
327
- true,
328
- )
329
-
330
- await expect(
331
- sudoKeyManager.doesPrivateKeyExists('VpnKeyPair'),
332
- ).resolves.toBeTruthy()
333
-
334
- const [actualKeyName] = capture(
335
- sudoCryptoProviderMock.doesPrivateKeyExists,
295
+ sudoCryptoProviderMock.doesPrivateKeyExist,
336
296
  ).first()
337
297
  expect(actualKeyName).toStrictEqual('VpnKeyPair')
338
298
 
339
- verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
340
- verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).never()
299
+ verify(sudoCryptoProviderMock.doesPrivateKeyExist(anything())).once()
341
300
  })
342
301
  })
343
302
 
@@ -21,6 +21,21 @@ describe('Base64', () => {
21
21
  )
22
22
  })
23
23
 
24
+ it('Base 64 URL safe encodes an ArrayBuffer, and decodes to an ArrayBuffer', () => {
25
+ const result = 'http://localhost:3000/search?q=url+test&unit=jest+test'
26
+ const encoded = Base64.urlSafeEncode({ input: Buffer.from(result, 'utf8') })
27
+ expect(Base64.UrlSafeValidate(encoded)).toStrictEqual(true)
28
+ const decoded = Base64.urlSafeDecode({ encoded })
29
+ expect(Buffer.from(decoded).toString('utf8')).toStrictEqual(result)
30
+ })
31
+ it('Base 64 URL safe encodes a string, validates, and decodes to a string', () => {
32
+ const result = 'http://localhost:3000/search?q=url+test&unit=jest+test'
33
+ const encoded = Base64.urlSafeEncodeString({ input: result })
34
+ expect(Base64.UrlSafeValidate(encoded)).toStrictEqual(true)
35
+ const decoded = Base64.urlSafeDecodeString({ encoded })
36
+ expect(decoded).toStrictEqual(result)
37
+ })
38
+
24
39
  const encodedPK =
25
40
  'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt88ya9gRqtqPA75DyRMY13SkDIHveCqCpngTnMUmLpRvd7HigAIkVEfKWqxG7+QdUPUUr2heBkG3WoGgljGXkMRNdcZek4LZ3+W7o2vCrp6h/19bmPxgQDRSasT1Br7zFk2yKmV/WBwI+9SoIqNU/oxO9ucdK6D0jL/Po32UfCFs+zsNE7Hg3gXNR/fihqnlE+oZETlFmF7QkxXtTaPv+acTQCrWT1V4f+hMQ4JBFKDORZ2Agb0L3Fn45R0rsXofkyvUNMxRztffbZm1m6pqysRRgOgHEQGULCGxlO6VgkhJFhxfQd1iLyK0cYRyg53t5dr9aO1tRAM2S2Bn65sKewIDAQAB'
26
41
  const decodedPKBuffer = Buffer.from(encodedPK, 'base64')
package/yarn.lock CHANGED
@@ -5568,10 +5568,10 @@ typedarray-to-buffer@^3.1.5:
5568
5568
  dependencies:
5569
5569
  is-typedarray "^1.0.0"
5570
5570
 
5571
- typedoc@^0.23.8:
5572
- version "0.23.8"
5573
- resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.23.8.tgz#6837fb2732f73e7aa61b46a4fbe77a301473998d"
5574
- integrity sha512-NLRTY/7XSrhiowR3xnH/nlfTnHk+dkzhHWAMT8guoZ6RHCQZIu3pJREMCqzdkWVCC5+dr9We7TtNeprR3Qy6Ag==
5571
+ typedoc@^0.23.9:
5572
+ version "0.23.9"
5573
+ resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.23.9.tgz#fd94451abd039513ab4fda58208fa0e5631e080b"
5574
+ integrity sha512-rvWci2KHwteVUufZjjtIy/4PIHiE66t4VW4Ob6pezV//GHZ9Px0CHE5iq032GZzKONJWnNb+EJsrQv32INRvxA==
5575
5575
  dependencies:
5576
5576
  lunr "^2.3.9"
5577
5577
  marked "^4.0.16"