@peerbit/crypto 3.0.1 → 3.1.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/dist/src/hash.browser.d.ts +5 -0
- package/dist/src/hash.browser.d.ts.map +1 -1
- package/dist/src/hash.browser.js +11 -0
- package/dist/src/hash.browser.js.map +1 -1
- package/dist/src/hash.d.ts +5 -0
- package/dist/src/hash.d.ts.map +1 -1
- package/dist/src/hash.js +11 -0
- package/dist/src/hash.js.map +1 -1
- package/package.json +1 -1
- package/src/hash.browser.ts +21 -0
- package/src/hash.ts +21 -0
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export interface IncrementalSHA256 {
|
|
2
|
+
update(bytes: Uint8Array): IncrementalSHA256;
|
|
3
|
+
digest(): Uint8Array;
|
|
4
|
+
}
|
|
5
|
+
export declare const createSHA256: () => IncrementalSHA256;
|
|
1
6
|
export declare const sha256Base64: (bytes: Uint8Array) => Promise<string>;
|
|
2
7
|
export declare const sha256Base64Sync: (bytes: Uint8Array) => string;
|
|
3
8
|
export declare const sha256: (bytes: Uint8Array) => Promise<Uint8Array>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.browser.d.ts","sourceRoot":"","sources":["../../src/hash.browser.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,MAAM,CACvC,CAAC;AAC/B,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,KAAG,MACP,CAAC;AAC/C,eAAO,MAAM,MAAM,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,UAAU,CAGjE,CAAC;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,UAAU,KAAG,UACX,CAAC"}
|
|
1
|
+
{"version":3,"file":"hash.browser.d.ts","sourceRoot":"","sources":["../../src/hash.browser.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CAAC;IAC7C,MAAM,IAAI,UAAU,CAAC;CACrB;AAeD,eAAO,MAAM,YAAY,QAAO,iBACC,CAAC;AAElC,eAAO,MAAM,YAAY,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,MAAM,CACvC,CAAC;AAC/B,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,KAAG,MACP,CAAC;AAC/C,eAAO,MAAM,MAAM,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,UAAU,CAGjE,CAAC;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,UAAU,KAAG,UACX,CAAC"}
|
package/dist/src/hash.browser.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { SHA256 } from "@stablelib/sha256";
|
|
2
2
|
import { toBase64 } from "./utils.js";
|
|
3
|
+
class StableLibIncrementalSHA256 {
|
|
4
|
+
hash = new SHA256();
|
|
5
|
+
update(bytes) {
|
|
6
|
+
this.hash.update(bytes);
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
digest() {
|
|
10
|
+
return this.hash.digest();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const createSHA256 = () => new StableLibIncrementalSHA256();
|
|
3
14
|
export const sha256Base64 = async (bytes) => toBase64(await sha256(bytes));
|
|
4
15
|
export const sha256Base64Sync = (bytes) => toBase64(new SHA256().update(bytes).digest());
|
|
5
16
|
export const sha256 = async (bytes) => new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.browser.js","sourceRoot":"","sources":["../../src/hash.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"hash.browser.js","sourceRoot":"","sources":["../../src/hash.browser.ts"],"names":[],"mappings":"AAAA,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
+
export declare const createSHA256: () => IncrementalSHA256;
|
|
1
6
|
export declare const sha256Base64Sync: (bytes: Uint8Array) => string;
|
|
2
7
|
export declare const sha256Base64: (bytes: Uint8Array) => Promise<string>;
|
|
3
8
|
export declare const sha256: (bytes: Uint8Array) => Promise<Uint8Array>;
|
package/dist/src/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,KAAG,MACM,CAAC;AAC5D,eAAO,MAAM,YAAY,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,MAAM,CACV,CAAC;AAC5D,eAAO,MAAM,MAAM,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,UAAU,CAChB,CAAC;AACpD,eAAO,MAAM,UAAU,GAAI,OAAO,UAAU,KAAG,UACI,CAAC"}
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CAAC;IAC7C,MAAM,IAAI,UAAU,CAAC;CACrB;AAeD,eAAO,MAAM,YAAY,QAAO,iBACJ,CAAC;AAE7B,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,KAAG,MACM,CAAC;AAC5D,eAAO,MAAM,YAAY,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,MAAM,CACV,CAAC;AAC5D,eAAO,MAAM,MAAM,GAAU,OAAO,UAAU,KAAG,OAAO,CAAC,UAAU,CAChB,CAAC;AACpD,eAAO,MAAM,UAAU,GAAI,OAAO,UAAU,KAAG,UACI,CAAC"}
|
package/dist/src/hash.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import crypto from "crypto";
|
|
2
|
+
class NodeIncrementalSHA256 {
|
|
3
|
+
hash = crypto.createHash("sha256");
|
|
4
|
+
update(bytes) {
|
|
5
|
+
this.hash.update(bytes);
|
|
6
|
+
return this;
|
|
7
|
+
}
|
|
8
|
+
digest() {
|
|
9
|
+
return this.hash.digest();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const createSHA256 = () => new NodeIncrementalSHA256();
|
|
2
13
|
export const sha256Base64Sync = (bytes) => crypto.createHash("sha256").update(bytes).digest("base64");
|
|
3
14
|
export const sha256Base64 = async (bytes) => crypto.createHash("sha256").update(bytes).digest("base64");
|
|
4
15
|
export const sha256 = async (bytes) => crypto.createHash("sha256").update(bytes).digest();
|
package/dist/src/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,MAAM,qBAAqB;IACT,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpD,MAAM,CAAC,KAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC3B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,GAAsB,EAAE,CACnD,IAAI,qBAAqB,EAAE,CAAC;AAE7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAiB,EAAU,EAAE,CAC7D,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,KAAiB,EAAmB,EAAE,CACxE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,KAAiB,EAAuB,EAAE,CACtE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AACpD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAiB,EAAc,EAAE,CAC3D,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/hash.browser.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { SHA256 } from "@stablelib/sha256";
|
|
2
2
|
import { toBase64 } from "./utils.js";
|
|
3
3
|
|
|
4
|
+
export interface IncrementalSHA256 {
|
|
5
|
+
update(bytes: Uint8Array): IncrementalSHA256;
|
|
6
|
+
digest(): Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class StableLibIncrementalSHA256 implements IncrementalSHA256 {
|
|
10
|
+
private readonly hash = new SHA256();
|
|
11
|
+
|
|
12
|
+
update(bytes: Uint8Array): IncrementalSHA256 {
|
|
13
|
+
this.hash.update(bytes);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
digest(): Uint8Array {
|
|
18
|
+
return this.hash.digest();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const createSHA256 = (): IncrementalSHA256 =>
|
|
23
|
+
new StableLibIncrementalSHA256();
|
|
24
|
+
|
|
4
25
|
export const sha256Base64 = async (bytes: Uint8Array): Promise<string> =>
|
|
5
26
|
toBase64(await sha256(bytes));
|
|
6
27
|
export const sha256Base64Sync = (bytes: Uint8Array): string =>
|
package/src/hash.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import crypto from "crypto";
|
|
2
2
|
|
|
3
|
+
export interface IncrementalSHA256 {
|
|
4
|
+
update(bytes: Uint8Array): IncrementalSHA256;
|
|
5
|
+
digest(): Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class NodeIncrementalSHA256 implements IncrementalSHA256 {
|
|
9
|
+
private readonly hash = crypto.createHash("sha256");
|
|
10
|
+
|
|
11
|
+
update(bytes: Uint8Array): IncrementalSHA256 {
|
|
12
|
+
this.hash.update(bytes);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
digest(): Uint8Array {
|
|
17
|
+
return this.hash.digest();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const createSHA256 = (): IncrementalSHA256 =>
|
|
22
|
+
new NodeIncrementalSHA256();
|
|
23
|
+
|
|
3
24
|
export const sha256Base64Sync = (bytes: Uint8Array): string =>
|
|
4
25
|
crypto.createHash("sha256").update(bytes).digest("base64");
|
|
5
26
|
export const sha256Base64 = async (bytes: Uint8Array): Promise<string> =>
|