working rss feed to nostr publish

This commit is contained in:
2023-11-24 00:43:28 -05:00
parent 06edcb57ae
commit 88d2f9cfec
8396 changed files with 783105 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
export const SHA_256_HASH: { name: "SHA-256" } = { name: "SHA-256" };
export const SHA_256_HMAC_ALGO: { name: "HMAC"; hash: { name: "SHA-256" } } = {
name: "HMAC",
hash: SHA_256_HASH
};
export const EMPTY_DATA_SHA_256 = new Uint8Array([
227,
176,
196,
66,
152,
252,
28,
20,
154,
251,
244,
200,
153,
111,
185,
36,
39,
174,
65,
228,
100,
155,
147,
76,
164,
149,
153,
27,
120,
82,
184,
85
]);
+34
View File
@@ -0,0 +1,34 @@
import { Sha256 as Ie11Sha256 } from "./ie11Sha256";
import { Sha256 as WebCryptoSha256 } from "./webCryptoSha256";
import { Sha256 as JsSha256 } from "@aws-crypto/sha256-js";
import { Checksum, SourceData } from "@aws-sdk/types";
import { supportsWebCrypto } from "@aws-crypto/supports-web-crypto";
import { isMsWindow } from "@aws-crypto/ie11-detection";
import { locateWindow } from "@aws-sdk/util-locate-window";
import { convertToBuffer } from "@aws-crypto/util";
export class Sha256 implements Checksum {
private hash: Checksum;
constructor(secret?: SourceData) {
if (supportsWebCrypto(locateWindow())) {
this.hash = new WebCryptoSha256(secret);
} else if (isMsWindow(locateWindow())) {
this.hash = new Ie11Sha256(secret);
} else {
this.hash = new JsSha256(secret);
}
}
update(data: SourceData, encoding?: "utf8" | "ascii" | "latin1"): void {
this.hash.update(convertToBuffer(data));
}
digest(): Promise<Uint8Array> {
return this.hash.digest();
}
reset(): void {
this.hash.reset();
}
}
+108
View File
@@ -0,0 +1,108 @@
import { isEmptyData } from "./isEmptyData";
import { SHA_256_HMAC_ALGO } from "./constants";
import { Checksum, SourceData } from "@aws-sdk/types";
import { fromUtf8 } from "@aws-sdk/util-utf8-browser";
import { CryptoOperation, Key, MsWindow } from "@aws-crypto/ie11-detection";
import { locateWindow } from "@aws-sdk/util-locate-window";
export class Sha256 implements Checksum {
private readonly secret?: SourceData;
private operation!: Promise<CryptoOperation>;
constructor(secret?: SourceData) {
this.secret = secret;
this.reset();
}
update(toHash: SourceData): void {
if (isEmptyData(toHash)) {
return;
}
this.operation = this.operation.then(operation => {
operation.onerror = () => {
this.operation = Promise.reject(
new Error("Error encountered updating hash")
);
};
operation.process(toArrayBufferView(toHash));
return operation;
});
this.operation.catch(() => {});
}
digest(): Promise<Uint8Array> {
return this.operation.then<Uint8Array>(
operation =>
new Promise((resolve, reject) => {
operation.onerror = () => {
reject(new Error("Error encountered finalizing hash"));
};
operation.oncomplete = () => {
if (operation.result) {
resolve(new Uint8Array(operation.result));
}
reject(new Error("Error encountered finalizing hash"));
};
operation.finish();
})
);
}
reset(): void {
if (this.secret) {
this.operation = getKeyPromise(this.secret).then(keyData =>
(locateWindow() as MsWindow).msCrypto.subtle.sign(
SHA_256_HMAC_ALGO,
keyData
)
);
this.operation.catch(() => {});
} else {
this.operation = Promise.resolve(
(locateWindow() as MsWindow).msCrypto.subtle.digest("SHA-256")
);
}
}
}
function getKeyPromise(secret: SourceData): Promise<Key> {
return new Promise((resolve, reject) => {
const keyOperation = (locateWindow() as MsWindow).msCrypto.subtle.importKey(
"raw",
toArrayBufferView(secret),
SHA_256_HMAC_ALGO,
false,
["sign"]
);
keyOperation.oncomplete = () => {
if (keyOperation.result) {
resolve(keyOperation.result);
}
reject(new Error("ImportKey completed without importing key."));
};
keyOperation.onerror = () => {
reject(new Error("ImportKey failed to import key."));
};
});
}
function toArrayBufferView(data: SourceData): Uint8Array {
if (typeof data === "string") {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(
data.buffer,
data.byteOffset,
data.byteLength / Uint8Array.BYTES_PER_ELEMENT
);
}
return new Uint8Array(data);
}
+3
View File
@@ -0,0 +1,3 @@
export * from "./crossPlatformSha256";
export { Sha256 as Ie11Sha256 } from "./ie11Sha256";
export { Sha256 as WebCryptoSha256 } from "./webCryptoSha256";
+9
View File
@@ -0,0 +1,9 @@
import { SourceData } from "@aws-sdk/types";
export function isEmptyData(data: SourceData): boolean {
if (typeof data === "string") {
return data.length === 0;
}
return data.byteLength === 0;
}
+71
View File
@@ -0,0 +1,71 @@
import { Checksum, SourceData } from "@aws-sdk/types";
import { isEmptyData, convertToBuffer } from "@aws-crypto/util";
import {
EMPTY_DATA_SHA_256,
SHA_256_HASH,
SHA_256_HMAC_ALGO,
} from "./constants";
import { locateWindow } from "@aws-sdk/util-locate-window";
export class Sha256 implements Checksum {
private readonly secret?: SourceData;
private key: Promise<CryptoKey> | undefined;
private toHash: Uint8Array = new Uint8Array(0);
constructor(secret?: SourceData) {
this.secret = secret;
this.reset();
}
update(data: SourceData): void {
if (isEmptyData(data)) {
return;
}
const update = convertToBuffer(data);
const typedArray = new Uint8Array(
this.toHash.byteLength + update.byteLength
);
typedArray.set(this.toHash, 0);
typedArray.set(update, this.toHash.byteLength);
this.toHash = typedArray;
}
digest(): Promise<Uint8Array> {
if (this.key) {
return this.key.then((key) =>
locateWindow()
.crypto.subtle.sign(SHA_256_HMAC_ALGO, key, this.toHash)
.then((data) => new Uint8Array(data))
);
}
if (isEmptyData(this.toHash)) {
return Promise.resolve(EMPTY_DATA_SHA_256);
}
return Promise.resolve()
.then(() =>
locateWindow().crypto.subtle.digest(SHA_256_HASH, this.toHash)
)
.then((data) => Promise.resolve(new Uint8Array(data)));
}
reset(): void {
this.toHash = new Uint8Array(0);
if (this.secret && this.secret !== void 0) {
this.key = new Promise((resolve, reject) => {
locateWindow()
.crypto.subtle.importKey(
"raw",
convertToBuffer(this.secret as SourceData),
SHA_256_HMAC_ALGO,
false,
["sign"]
)
.then(resolve, reject);
});
this.key.catch(() => {});
}
}
}