@peerbit/crypto 2.0.0 → 2.1.1

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.
@@ -2,3 +2,5 @@ export declare const fromHexString: (hexString: string) => Uint8Array;
2
2
  export declare const toHexString: (bytes: Uint8Array) => string;
3
3
  export declare const toBase64: (arr: Uint8Array) => string;
4
4
  export declare const fromBase64: (base64: string) => Uint8Array;
5
+ export declare const toBase64URL: (arr: Uint8Array) => string;
6
+ export declare const fromBase64URL: (base64: string) => Uint8Array;
package/lib/esm/utils.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import sodium from "libsodium-wrappers";
2
- export const fromHexString = (hexString) => Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
3
- export const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
2
+ export const fromHexString = (hexString) => sodium.from_hex(hexString);
3
+ export const toHexString = (bytes) => sodium.to_hex(bytes);
4
4
  export const toBase64 = (arr) => {
5
5
  return sodium.to_base64(arr, sodium.base64_variants.ORIGINAL);
6
6
  };
7
7
  export const fromBase64 = (base64) => {
8
8
  return sodium.from_base64(base64, sodium.base64_variants.ORIGINAL);
9
9
  };
10
+ export const toBase64URL = (arr) => {
11
+ return sodium.to_base64(arr, sodium.base64_variants.URLSAFE);
12
+ };
13
+ export const fromBase64URL = (base64) => {
14
+ return sodium.from_base64(base64, sodium.base64_variants.URLSAFE);
15
+ };
10
16
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAClD,UAAU,CAAC,IAAI,CACd,SAAS,CAAC,KAAK,CAAC,SAAS,CAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE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OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAe,EAAE,EAAE;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE;IAC/C,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AACnE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/crypto",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Crypto fn",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,10 +47,10 @@
47
47
  "@ethersproject/wallet": "^5.7.0",
48
48
  "@libp2p/crypto": "^3.0.3",
49
49
  "@libp2p/peer-id": "^4.0.3",
50
- "@peerbit/cache": "^2.0.0",
50
+ "@peerbit/cache": "^2.0.1",
51
51
  "@peerbit/uint8arrays": "3.0.1",
52
52
  "@stablelib/sha256": "^1.0.1",
53
53
  "libsodium-wrappers": "^0.7.13"
54
54
  },
55
- "gitHead": "c48cb37d237a25b0bcc849482b43f6941d53e3d5"
55
+ "gitHead": "f4cb6a526d26e98360c32fd28dcdf9eb7ea10551"
56
56
  }
package/src/utils.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import sodium from "libsodium-wrappers";
2
- export const fromHexString = (hexString: string) =>
3
- Uint8Array.from(
4
- hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))
5
- );
2
+ export const fromHexString = (hexString: string) => sodium.from_hex(hexString);
6
3
 
7
- export const toHexString = (bytes: Uint8Array) =>
8
- bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
4
+ export const toHexString = (bytes: Uint8Array) => sodium.to_hex(bytes);
9
5
 
10
6
  export const toBase64 = (arr: Uint8Array) => {
11
7
  return sodium.to_base64(arr, sodium.base64_variants.ORIGINAL);
@@ -13,3 +9,10 @@ export const toBase64 = (arr: Uint8Array) => {
13
9
  export const fromBase64 = (base64: string) => {
14
10
  return sodium.from_base64(base64, sodium.base64_variants.ORIGINAL);
15
11
  };
12
+
13
+ export const toBase64URL = (arr: Uint8Array) => {
14
+ return sodium.to_base64(arr, sodium.base64_variants.URLSAFE);
15
+ };
16
+ export const fromBase64URL = (base64: string) => {
17
+ return sodium.from_base64(base64, sodium.base64_variants.URLSAFE);
18
+ };