openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
8 lines • 6.29 kB
JavaScript
import{t as sha256}from"./sha2-C8jrWuvU.mjs";import{Buffer}from"node:buffer";
//!node_modules/.pnpm/@noble+ciphers@2.4.0/node_modules/@noble/ciphers/utils.js
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
function isBytes(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const atitle=e=>e?`"${e}" `:``;function abool(e,t=``){if(typeof e!==`boolean`)throw new TypeError(atitle(t)+`expected boolean, got type=`+typeof e);return e}function anumber(e,t=``){if(typeof e!==`number`)throw new TypeError(atitle(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(atitle(t)+`expected integer >= 0, got `+e);return e}function abytes(e,t,n=``){if(isBytes(e)&&(t===void 0||e.length===t))return e;if(t!==void 0)anumber(t,`length`);const r=isBytes(e);const i=t!==void 0?` of length ${t}`:``;const a=r?`length=${e.length}`:`type=${typeof e}`;const o=atitle(n)+`expected Uint8Array`+i+`, got `+a;if(!r)throw new TypeError(o);throw new RangeError(o)}function aexists(e,t=true){if(e.destroyed)throw new Error(`hash was destroyed`);if(t&&e.finished)throw new Error(`digest() was already called`)}function aoutput(e,t){abytes(e,void 0,`output`);const n=t.outputLen;if(!(e.length>=n))throw new RangeError(`"output" expected length >= `+n)}function aoutput32(e,t){aoutput(e,t);if(!isAligned32(e))throw new Error(`invalid output, must be aligned`)}function u8(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function u32(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function clean(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function createView(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}const isLE=/* @__PURE__ */ (()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function byteSwap(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const swap8IfBE=isLE?e=>e:e=>byteSwap(e)>>>0;function byteSwap32(e){for(let t=0;t<e.length;t++)e[t]=byteSwap(e[t]);return e}const swap32IfBE=isLE?e=>e:byteSwap32;const hasHexBuiltin=/* @__PURE__ */ (()=>typeof Uint8Array.from([]).toHex===`function`&&typeof Uint8Array.fromHex===`function`)();const hexes=/* @__PURE__ */ Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function bytesToHex(e){abytes(e);if(hasHexBuiltin)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=hexes[e[n]];return t}function utf8ToBytes(e){if(typeof e!==`string`)throw new TypeError(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function equalBytes(e,t){e=abytes(e);t=abytes(t);if(e.length!==t.length)return false;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function wrapMacConstructor(e,t,n){const r=t;const i=n||(()=>[]);const macC=(e,t)=>r(t,...i(e)).update(e).digest();const a=r(new Uint8Array(e),...i(/* @__PURE__ */ new Uint8Array(0)));macC.outputLen=a.outputLen;macC.blockLen=a.blockLen;macC.create=(e,...t)=>r(e,...t);return macC}const wrapCipher=(e,t)=>{function wrappedCipher(n,...r){abytes(n,void 0,`key`);if(e.nonceLength!==void 0){const t=r[0];abytes(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}const i=e.tagLength;const a=e.nonceLength!==void 0?1:0;if(!e.withAAD){for(let e=a;e<r.length;e++)if(isBytes(r[e]))throw new Error(`AAD not supported`)}if(e.withAAD&&r[a]!==void 0)abytes(r[a],void 0,`AAD`);const o=t(n,...r);const checkOutput=(e,t)=>{if(t!==void 0){if(e!==2)throw new Error(`cipher output not supported`);abytes(t,void 0,`output`)}};let s=false;return{encrypt(e,t){if(s)throw new Error(`cannot encrypt() twice with same key + nonce`);s=true;abytes(e,void 0,`data`);checkOutput(o.encrypt.length,t);return o.encrypt(e,t)},decrypt(e,t){abytes(e,void 0,`data`);if(i&&e.length<i)throw new Error(`"ciphertext" expected length >= tagLength=`+i);checkOutput(o.decrypt.length,t);return o.decrypt(e,t)}}}Object.assign(wrappedCipher,e);return wrappedCipher};function getOutput(e,t,n=true){if(t===void 0)return new Uint8Array(e);abytes(t,e,`output`);if(n&&!isAligned32(t))throw new Error(`invalid output, must be aligned`);return t}function u64Lengths(e,t,n){anumber(e);anumber(t);abool(n);const r=/* @__PURE__ */ new Uint8Array(16);const i=createView(r);i.setBigUint64(0,BigInt(t),n);i.setBigUint64(8,BigInt(e),n);return r}function isAligned32(e){return e.byteOffset%4===0}function copyBytes(e){return Uint8Array.from(abytes(e))}
//!extensions/reef/protocol/encoding.ts
const decoder=new TextDecoder(`utf-8`,{fatal:true});function decodeUtf8(e){return decoder.decode(e)}function base64url(e){return Buffer.from(e).toString(`base64url`)}function fromBase64url(e){if(!/^[A-Za-z0-9_-]*$/.test(e)||e.length%4===1)throw new Error(`invalid base64url`);const t=Buffer.from(e,`base64url`);if(t.toString(`base64url`)!==e)throw new Error(`invalid base64url padding`);return Uint8Array.from(t)}function base64(e){return Buffer.from(e).toString(`base64`)}function fromBase64(e){if(e.length%4!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e))throw new Error(`invalid base64`);const t=Buffer.from(e,`base64`);if(t.toString(`base64`)!==e)throw new Error(`non-canonical base64`);return Uint8Array.from(t)}
//!extensions/reef/protocol/canonical.ts
function canonicalJson(e){if(e===null||typeof e===`boolean`||typeof e===`string`)return JSON.stringify(e);if(typeof e===`number`){if(!Number.isFinite(e))throw new TypeError(`canonical JSON requires finite numbers`);return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map(canonicalJson).join(`,`)}]`;if(typeof e===`object`){const t=e;return`{${Object.keys(t).filter(e=>t[e]!==void 0).toSorted().map(e=>`${JSON.stringify(e)}:${canonicalJson(t[e])}`).join(`,`)}}`}throw new TypeError(`unsupported canonical JSON value`)}function canonicalBytes(e){return utf8ToBytes(canonicalJson(e))}function sha256Hex(e){return bytesToHex(sha256(e))}export{utf8ToBytes as C,u8 as S,wrapMacConstructor as T,isLE as _,decodeUtf8 as a,u32 as b,abytes as c,clean as d,copyBytes as f,isAligned32 as g,getOutput as h,base64url as i,aexists as l,equalBytes as m,sha256Hex as n,fromBase64 as o,createView as p,base64 as r,fromBase64url as s,canonicalBytes as t,aoutput32 as u,swap32IfBE as v,wrapCipher as w,u64Lengths as x,swap8IfBE as y};