mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Bundle crypto helpers for zap validator
This commit is contained in:
1 parent
51be9342be
commit
931fa1398f
4 files changed
+36
-3
No files matched your search
@@ -3,9 +3,7 @@
|
|||||||
import { nostrToolsReady } from "../nostrToolsBootstrap.js";
|
import { nostrToolsReady } from "../nostrToolsBootstrap.js";
|
||||||
import { normalizeToolkitCandidate, readToolkitFromScope } from "../nostr/toolkit.js";
|
import { normalizeToolkitCandidate, readToolkitFromScope } from "../nostr/toolkit.js";
|
||||||
import { userLogger } from "../utils/logger.js";
|
import { userLogger } from "../utils/logger.js";
|
||||||
import { bech32 } from "@scure/base";
|
import { bech32, bytesToHex, sha256 } from "../../vendor/crypto-helpers.bundle.min.js";
|
||||||
import { sha256 } from "@noble/hashes/sha256";
|
|
||||||
import { bytesToHex } from "@noble/hashes/utils";
|
|
||||||
|
|
||||||
const ZAP_RECEIPT_KIND = 9735;
|
const ZAP_RECEIPT_KIND = 9735;
|
||||||
const BOLT11_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
const BOLT11_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
||||||
|
|||||||
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
This bundle includes code from the following MIT-licensed projects:
|
||||||
|
|
||||||
|
- @scure/base (c) 2022 Paul Miller (https://paulmillr.com)
|
||||||
|
- @noble/hashes (c) 2022 Paul Miller (https://paulmillr.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/* Bundled bech32 and noble hashes helpers for bitvid (MIT Licensed). Source modules: @scure/base, @noble/hashes. */
|
||||||
|
function m(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function w(...e){let t=(o,s)=>i=>o(s(i)),r=Array.from(e).reverse().reduce((o,s)=>o?t(o,s.encode):s.encode,void 0),n=e.reduce((o,s)=>o?t(o,s.decode):s.decode,void 0);return{encode:r,decode:n}}function x(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(r=>{if(m(r),r<0||r>=e.length)throw new Error(`Digit index outside alphabet: ${r} (alphabet: ${e.length})`);return e[r]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(r=>{if(typeof r!="string")throw new Error(`alphabet.decode: not string element=${r}`);let n=e.indexOf(r);if(n===-1)throw new Error(`Unknown letter: "${r}". Allowed: ${e}`);return n})}}}function y(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let r of t)if(typeof r!="string")throw new Error(`join.encode: non-string input=${r}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function k(e,t="="){if(m(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(r){if(!Array.isArray(r)||r.length&&typeof r[0]!="string")throw new Error("padding.encode input should be array of strings");for(let n of r)if(typeof n!="string")throw new Error(`padding.encode: non-string input=${n}`);for(;r.length*e%8;)r.push(t);return r},decode(r){if(!Array.isArray(r)||r.length&&typeof r[0]!="string")throw new Error("padding.encode input should be array of strings");for(let o of r)if(typeof o!="string")throw new Error(`padding.decode: non-string input=${o}`);let n=r.length;if(n*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if(!((n-1)*e%8))throw new Error("Invalid padding: string has too much padding");return r.slice(0,n)}}}function z(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function G(e,t,r){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: wrong to=${r}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let n=0,o=[],s=Array.from(e);for(s.forEach(i=>{if(m(i),i<0||i>=t)throw new Error(`Wrong integer: ${i}`)});;){let i=0,h=!0;for(let a=n;a<s.length;a++){let d=s[a],c=t*i+d;if(!Number.isSafeInteger(c)||t*i/t!==i||c-d!==t*i)throw new Error("convertRadix: carry overflow");if(i=c%r,s[a]=Math.floor(c/r),!Number.isSafeInteger(s[a])||s[a]*r+i!==c)throw new Error("convertRadix: carry overflow");if(h)s[a]?h=!1:n=a;else continue}if(o.push(i),h)break}for(let i=0;i<e.length-1&&e[i]===0;i++)o.push(0);return o.reverse()}var X=(e,t)=>t?X(t,e%t):e,$=(e,t)=>e+(t-X(e,t));function I(e,t,r,n){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if($(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${$(t,r)}`);let o=0,s=0,i=2**r-1,h=[];for(let a of e){if(m(a),a>=2**t)throw new Error(`convertRadix2: invalid data word=${a} from=${t}`);if(o=o<<t|a,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=r;s-=r)h.push((o>>s-r&i)>>>0);o&=2**s-1}if(o=o<<r-s&i,!n&&s>=t)throw new Error("Excess padding");if(!n&&o)throw new Error(`Non-zero padding: ${o}`);return n&&s>0&&h.push(o>>>0),h}function q(e){return m(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return G(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(G(t,e,2**8))}}}function g(e,t=!1){if(m(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if($(8,e)>32||$(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!(r instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return I(Array.from(r),8,e,!t)},decode:r=>{if(!Array.isArray(r)||r.length&&typeof r[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(I(r,e,8,t))}}}function V(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}var Z=w(g(4),x("0123456789ABCDEF"),y("")),ee=w(g(5),x("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),k(5),y("")),Ue=w(g(5),x("0123456789ABCDEFGHIJKLMNOPQRSTUV"),k(5),y("")),Le=w(g(5),x("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),y("Line truncated
|
||||||
|
/*! Bundled license information:
|
||||||
|
|
||||||
|
@scure/base/lib/esm/index.js:
|
||||||
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
||||||
|
|
||||||
|
@noble/hashes/esm/utils.js:
|
||||||
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
||||||
|
*/
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
export { bech32 } from "@scure/base";
|
||||||
|
export { sha256 } from "@noble/hashes/sha256";
|
||||||
|
export { bytesToHex } from "@noble/hashes/utils";
|
||||||
Reference in new issue
Block a user