mirror of
https://github.com/dergigi/boris.git
synced 2025-12-27 11:34:50 +01:00
- Add project structure with TypeScript, React, and Vite - Implement nostr authentication using browser extension (NIP-07) - Add NIP-51 compliant bookmark fetching and display - Create minimal UI with login and bookmark components - Integrate applesauce-core and applesauce-react libraries - Add responsive styling with dark/light mode support - Include comprehensive README with setup instructions This is a minimal MVP for a nostr bookmark client that allows users to view their bookmarks according to NIP-51 specification.
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
function number(n: number) {
|
|
if (!Number.isSafeInteger(n) || n < 0) throw new Error(`positive integer expected, not ${n}`);
|
|
}
|
|
|
|
function bool(b: boolean) {
|
|
if (typeof b !== 'boolean') throw new Error(`boolean expected, not ${b}`);
|
|
}
|
|
|
|
export function isBytes(a: unknown): a is Uint8Array {
|
|
return (
|
|
a instanceof Uint8Array ||
|
|
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
|
|
);
|
|
}
|
|
|
|
function bytes(b: Uint8Array | undefined, ...lengths: number[]) {
|
|
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
}
|
|
|
|
export type Hash = {
|
|
(data: Uint8Array): Uint8Array;
|
|
blockLen: number;
|
|
outputLen: number;
|
|
create: any;
|
|
};
|
|
function hash(hash: Hash) {
|
|
if (typeof hash !== 'function' || typeof hash.create !== 'function')
|
|
throw new Error('hash must be wrapped by utils.wrapConstructor');
|
|
number(hash.outputLen);
|
|
number(hash.blockLen);
|
|
}
|
|
|
|
function exists(instance: any, checkFinished = true) {
|
|
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
|
|
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
|
|
}
|
|
|
|
function output(out: any, instance: any) {
|
|
bytes(out);
|
|
const min = instance.outputLen;
|
|
if (out.length < min) {
|
|
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
}
|
|
}
|
|
|
|
export { number, bool, bytes, hash, exists, output };
|
|
const assert = { number, bool, bytes, hash, exists, output };
|
|
export default assert;
|