@helia/dag-json 0.0.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/LICENSE +4 -0
- package/README.md +60 -0
- package/dist/index.min.js +3 -0
- package/dist/src/index.d.ts +88 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +51 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +156 -0
- package/src/index.ts +120 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/ipfs/helia" title="Helia">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# @helia/dag-json <!-- omit in toc -->
|
|
8
|
+
|
|
9
|
+
[](https://ipfs.tech)
|
|
10
|
+
[](https://discuss.ipfs.tech)
|
|
11
|
+
[](https://codecov.io/gh/ipfs/helia-dag-json)
|
|
12
|
+
[](https://github.com/ipfs/helia-dag-json/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
|
|
13
|
+
|
|
14
|
+
> Add/get IPLD blocks containing json with your Helia node
|
|
15
|
+
|
|
16
|
+
## Table of contents <!-- omit in toc -->
|
|
17
|
+
|
|
18
|
+
- - [Install](#install)
|
|
19
|
+
- [Browser `<script>` tag](#browser-script-tag)
|
|
20
|
+
- [@helia/dag-json <!-- omit in toc -->](#heliadag-json----omit-in-toc---)
|
|
21
|
+
- [API Docs](#api-docs)
|
|
22
|
+
- [License](#license)
|
|
23
|
+
- [Contribute](#contribute)
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```console
|
|
28
|
+
$ npm i @helia/dag-json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Browser `<script>` tag
|
|
32
|
+
|
|
33
|
+
Loading this module through a script tag will make it's exports available as `HeliaDagJson` in the global namespace.
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<script src="https://unpkg.com/@helia/dag-json/dist/index.min.js"></script>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API Docs
|
|
40
|
+
|
|
41
|
+
- <https://ipfs.github.io/helia-dag-json/modules/_helia_dag_json.html>
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Licensed under either of
|
|
46
|
+
|
|
47
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
48
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
49
|
+
|
|
50
|
+
## Contribute
|
|
51
|
+
|
|
52
|
+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-dag-json/issues).
|
|
53
|
+
|
|
54
|
+
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
|
|
55
|
+
|
|
56
|
+
Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
57
|
+
|
|
58
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
59
|
+
|
|
60
|
+
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDagJson = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
"use strict";var HeliaDagJson=(()=>{var Be=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var Sr=Object.prototype.hasOwnProperty;var Ur=(t,e)=>{for(var r in e)Be(t,r,{get:e[r],enumerable:!0})},Ar=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of vr(e))!Sr.call(t,o)&&o!==r&&Be(t,o,{get:()=>e[o],enumerable:!(n=Er(e,o))||n.enumerable});return t};var Tr=t=>Ar(Be({},"__esModule",{value:!0}),t);var Fn={};Ur(Fn,{dagJson:()=>Vn});var Br=nt,tt=128,$r=127,_r=~$r,Ir=Math.pow(2,31);function nt(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Ir;)e[r++]=t&255|tt,t/=128;for(;t&_r;)e[r++]=t&255|tt,t>>>=7;return e[r]=t|0,nt.bytes=r-n+1,e}var Cr=$e,Nr=128,rt=127;function $e(t,n){var r=0,n=n||0,o=0,i=n,a,u=t.length;do{if(i>=u)throw $e.bytes=0,new RangeError("Could not decode varint");a=t[i++],r+=o<28?(a&rt)<<o:(a&rt)*Math.pow(2,o),o+=7}while(a>=Nr);return $e.bytes=i-n,r}var Mr=Math.pow(2,7),zr=Math.pow(2,14),Or=Math.pow(2,21),Dr=Math.pow(2,28),Vr=Math.pow(2,35),Fr=Math.pow(2,42),jr=Math.pow(2,49),Pr=Math.pow(2,56),Rr=Math.pow(2,63),Lr=function(t){return t<Mr?1:t<zr?2:t<Or?3:t<Dr?4:t<Vr?5:t<Fr?6:t<jr?7:t<Pr?8:t<Rr?9:10},qr={encode:Br,decode:Cr,encodingLength:Lr},Wr=qr,ne=Wr;var oe=(t,e=0)=>[ne.decode(t,e),ne.decode.bytes],G=(t,e,r=0)=>(ne.encode(t,e,r),e),J=t=>ne.encodingLength(t);var Ln=new Uint8Array(0);var ot=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},K=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var ie=(t,e)=>{let r=e.byteLength,n=J(t),o=n+J(r),i=new Uint8Array(o+r);return G(t,i,0),G(r,i,n),i.set(e,o),new H(t,r,e,i)},it=t=>{let e=K(t),[r,n]=oe(e),[o,i]=oe(e.subarray(n)),a=e.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new H(r,o,a,e)},st=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ot(t.bytes,r.bytes)}},H=class{constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Jr(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(r[a]!==255)throw new TypeError(i+" is ambiguous");r[a]=o}var u=t.length,h=t.charAt(0),g=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function w(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var E=0,q=0,_=0,M=m.length;_!==M&&m[_]===0;)_++,E++;for(var z=(M-_)*l+1>>>0,T=new Uint8Array(z);_!==M;){for(var O=m[_],P=0,I=z-1;(O!==0||P<q)&&I!==-1;I--,P++)O+=256*T[I]>>>0,T[I]=O%u>>>0,O=O/u>>>0;if(O!==0)throw new Error("Non-zero carry");q=P,_++}for(var D=z-q;D!==z&&T[D]===0;)D++;for(var ye=h.repeat(E);D<z;++D)ye+=t.charAt(T[D]);return ye}function me(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var q=0,_=0;m[E]===h;)q++,E++;for(var M=(m.length-E)*g+1>>>0,z=new Uint8Array(M);m[E];){var T=r[m.charCodeAt(E)];if(T===255)return;for(var O=0,P=M-1;(T!==0||O<_)&&P!==-1;P--,O++)T+=u*z[P]>>>0,z[P]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");_=O,E++}if(m[E]!==" "){for(var I=M-_;I!==M&&z[I]===0;)I++;for(var D=new Uint8Array(q+(M-I)),ye=q;I!==M;)D[ye++]=z[I++];return D}}}function kr(m){var E=me(m);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:me,decode:kr}}var Kr=Jr,Hr=Kr,at=Hr;var Ce=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ne=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ct(this,e)}},Me=class{constructor(e){this.decoders=e}or(e){return ct(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ct=(t,e)=>new Me({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),ze=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ce(e,r,n),this.decoder=new Ne(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ut=({name:t,prefix:e,encode:r,decode:n})=>new ze(t,e,r,n),Oe=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=at(r,e);return ut({prefix:t,name:e,encode:n,decode:i=>K(o(i))})},Xr=(t,e,r,n)=>{let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let i=t.length;for(;t[i-1]==="=";)--i;let a=new Uint8Array(i*r/8|0),u=0,h=0,g=0;for(let l=0;l<i;++l){let w=o[t[l]];if(w===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|w,u+=r,u>=8&&(u-=8,a[g++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return a},Qr=(t,e,r)=>{let n=e[e.length-1]==="=",o=(1<<r)-1,i="",a=0,u=0;for(let h=0;h<t.length;++h)for(u=u<<8|t[h],a+=8;a>r;)a-=r,i+=e[o&u>>a];if(a&&(i+=e[o&u<<r-a]),n)for(;i.length*r&7;)i+="=";return i},k=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>ut({prefix:e,name:t,encode(o){return Qr(o,n,r)},decode(o){return Xr(o,n,r,t)}});var V=Oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xn=Oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var se=k({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yn=k({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eo=k({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),to=k({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ro=k({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),no=k({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),oo=k({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),io=k({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),so=k({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var dt=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Yr(r,De(t),e||V.encoder);default:return en(r,De(t),e||se.encoder)}};var ft=new WeakMap,De=t=>{let e=ft.get(t);if(e==null){let r=new Map;return ft.set(t,r),r}return e},y=class{constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==tn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return y.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ie(e,r);return y.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return y.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&st(e.multihash,n.multihash)}toString(e){return dt(this,e)}toJSON(){return{"/":dt(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof y)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:a}=r;return new y(n,o,i,a||ht(n,o,i.bytes))}else if(r[rn]===!0){let{version:n,multihash:o,code:i}=r,a=it(o);return y.create(n,i,a)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==ae)throw new Error(`Version 0 CID must use dag-pb (code: ${ae}) block encoding`);return new y(e,r,n,n.bytes)}case 1:{let o=ht(e,r,n.bytes);return new y(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return y.create(0,ae,e)}static createV1(e,r){return y.create(1,e,r)}static decode(e){let[r,n]=y.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=y.inspectBytes(e),n=r.size-r.multihashSize,o=K(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),a=new H(r.multihashCode,r.digestSize,i,o);return[r.version===0?y.createV0(a):y.createV1(r.codec,a),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[w,me]=oe(e.subarray(r));return r+=me,w},o=n(),i=ae;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=r,u=n(),h=n(),g=r+h,l=g-a;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:l,size:g}}static parse(e,r){let[n,o]=Zr(e,r),i=y.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return De(i).set(n,e),i}},Zr=(t,e)=>{switch(t[0]){case"Q":{let r=e||V;return[V.prefix,r.decode(`${V.prefix}${t}`)]}case V.prefix:{let r=e||V;return[V.prefix,r.decode(t)]}case se.prefix:{let r=e||se;return[se.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},Yr=(t,e,r)=>{let{prefix:n}=r;if(n!==V.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o},en=(t,e,r)=>{let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o},ae=112,tn=18,ht=(t,e,r)=>{let n=J(t),o=n+J(e),i=new Uint8Array(o+r.byteLength);return G(t,i,0),G(e,i,n),i.set(r,o),i},rn=Symbol.for("@ipld/js-cid/CID");var Fe=({name:t,code:e,encode:r})=>new Ve(t,e,r),Ve=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?ie(this.code,r):r.then(n=>ie(this.code,n))}else throw Error("Unknown type, must be binary type")}};var je=k({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wo=k({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xo=k({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bo=k({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var on=["string","number","bigint","symbol"],sn=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function pt(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(on.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(an(t))return"Buffer";let r=cn(t);return r||"Object"}function an(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function cn(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(sn.includes(e))return e}var s=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var c=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var X=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",un=new TextDecoder,dn=new TextEncoder;function ge(t){return X&&globalThis.Buffer.isBuffer(t)}function ce(t){return t instanceof Uint8Array?ge(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var gt=X?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):mt(t,e,r):(t,e,r)=>r-e>64?un.decode(t.subarray(e,r)):mt(t,e,r),we=X?t=>t.length>64?globalThis.Buffer.from(t):lt(t):t=>t.length>64?dn.encode(t):lt(t);var Q=X?(t,e,r)=>ge(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),wt=X?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),ce(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let o of t)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},xt=X?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function bt(t,e){if(ge(t)&&ge(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function lt(t,e=1/0){let r,n=t.length,o=null,i=[];for(let a=0;a<n;++a){if(r=t.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function mt(t,e,r){let n=[];for(;e<r;){let o=t[e],i=null,a=o>239?4:o>223?3:o>191?2:1;if(e+a<=r){let u,h,g,l;switch(a){case 1:o<128&&(i=o);break;case 2:u=t[e+1],(u&192)===128&&(l=(o&31)<<6|u&63,l>127&&(i=l));break;case 3:u=t[e+1],h=t[e+2],(u&192)===128&&(h&192)===128&&(l=(o&15)<<12|(u&63)<<6|h&63,l>2047&&(l<55296||l>57343)&&(i=l));break;case 4:u=t[e+1],h=t[e+2],g=t[e+3],(u&192)===128&&(h&192)===128&&(g&192)===128&&(l=(o&15)<<18|(u&63)<<12|(h&63)<<6|g&63,l>65535&&l<1114112&&(i=l))}}i===null?(i=65533,a=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=a}return Pe(n)}var yt=4096;function Pe(t){let e=t.length;if(e<=yt)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=yt));return r}var fn=256,ue=class{constructor(e=fn){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(e,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=xt(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=Q(n,0,this.cursor)}else r=wt(this.chunks,this.cursor);return e&&this.reset(),r}};var f="CBOR decode error:",F="CBOR encode error:",de=[];de[23]=1;de[24]=2;de[25]=3;de[26]=5;de[27]=9;function j(t,e,r){if(t.length-e<r)throw new Error(`${f} not enough data for type`)}var x=[24,256,65536,4294967296,BigInt("18446744073709551616")];function v(t,e,r){j(t,e,1);let n=t[e];if(r.strict===!0&&n<x[0])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function S(t,e,r){j(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<x[1])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function U(t,e,r){j(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<x[2])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function A(t,e,r){j(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],o=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<x[3])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${f} integers outside of the safe integer range are not supported`)}function kt(t,e,r,n){return new c(s.uint,v(t,e+1,n),2)}function Et(t,e,r,n){return new c(s.uint,S(t,e+1,n),3)}function vt(t,e,r,n){return new c(s.uint,U(t,e+1,n),5)}function St(t,e,r,n){return new c(s.uint,A(t,e+1,n),9)}function B(t,e){return b(t,0,e.value)}function b(t,e,r){if(r<x[0]){let n=Number(r);t.push([e|n])}else if(r<x[1]){let n=Number(r);t.push([e|24,n])}else if(r<x[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<x[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<x[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),a=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=a&255,a=a>>8,o[3]=a&255,a=a>>8,o[2]=a&255,a=a>>8,o[1]=a&255,t.push(o)}else throw new Error(`${f} encountered BigInt larger than allowable range`)}}B.encodedSize=function(e){return b.encodedSize(e.value)};b.encodedSize=function(e){return e<x[0]?1:e<x[1]?2:e<x[2]?3:e<x[3]?5:9};B.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Ut(t,e,r,n){return new c(s.negint,-1-v(t,e+1,n),2)}function At(t,e,r,n){return new c(s.negint,-1-S(t,e+1,n),3)}function Tt(t,e,r,n){return new c(s.negint,-1-U(t,e+1,n),5)}var Re=BigInt(-1),Bt=BigInt(1);function $t(t,e,r,n){let o=A(t,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new c(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${f} integers outside of the safe integer range are not supported`);return new c(s.negint,Re-BigInt(o),9)}function xe(t,e){let r=e.value,n=typeof r=="bigint"?r*Re-Bt:r*-1-1;b(t,e.type.majorEncoded,n)}xe.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*Re-Bt:r*-1-1;return n<x[0]?1:n<x[1]?2:n<x[2]?3:n<x[3]?5:9};xe.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function fe(t,e,r,n){j(t,e,r+n);let o=Q(t,e+r,e+r+n);return new c(s.bytes,o,r+n)}function _t(t,e,r,n){return fe(t,e,1,r)}function It(t,e,r,n){return fe(t,e,2,v(t,e+1,n))}function Ct(t,e,r,n){return fe(t,e,3,S(t,e+1,n))}function Nt(t,e,r,n){return fe(t,e,5,U(t,e+1,n))}function Mt(t,e,r,n){let o=A(t,e+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer bytes lengths not supported`);return fe(t,e,9,o)}function be(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===s.string?we(t.value):t.value),t.encodedBytes}function Z(t,e){let r=be(e);b(t,e.type.majorEncoded,r.length),t.push(r)}Z.encodedSize=function(e){let r=be(e);return b.encodedSize(r.length)+r.length};Z.compareTokens=function(e,r){return pn(be(e),be(r))};function pn(t,e){return t.length<e.length?-1:t.length>e.length?1:bt(t,e)}function he(t,e,r,n,o){let i=r+n;j(t,e,i);let a=new c(s.string,gt(t,e+r,e+i),i);return o.retainStringBytes===!0&&(a.byteValue=Q(t,e+r,e+i)),a}function zt(t,e,r,n){return he(t,e,1,r,n)}function Ot(t,e,r,n){return he(t,e,2,v(t,e+1,n),n)}function Dt(t,e,r,n){return he(t,e,3,S(t,e+1,n),n)}function Vt(t,e,r,n){return he(t,e,5,U(t,e+1,n),n)}function Ft(t,e,r,n){let o=A(t,e+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer string lengths not supported`);return he(t,e,9,o,n)}var jt=Z;function Y(t,e,r,n){return new c(s.array,n,r)}function Pt(t,e,r,n){return Y(t,e,1,r)}function Rt(t,e,r,n){return Y(t,e,2,v(t,e+1,n))}function Lt(t,e,r,n){return Y(t,e,3,S(t,e+1,n))}function qt(t,e,r,n){return Y(t,e,5,U(t,e+1,n))}function Wt(t,e,r,n){let o=A(t,e+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer array lengths not supported`);return Y(t,e,9,o)}function Gt(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return Y(t,e,1,1/0)}function ke(t,e){b(t,s.array.majorEncoded,e.value)}ke.compareTokens=B.compareTokens;ke.encodedSize=function(e){return b.encodedSize(e.value)};function ee(t,e,r,n){return new c(s.map,n,r)}function Jt(t,e,r,n){return ee(t,e,1,r)}function Kt(t,e,r,n){return ee(t,e,2,v(t,e+1,n))}function Ht(t,e,r,n){return ee(t,e,3,S(t,e+1,n))}function Xt(t,e,r,n){return ee(t,e,5,U(t,e+1,n))}function Qt(t,e,r,n){let o=A(t,e+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer map lengths not supported`);return ee(t,e,9,o)}function Zt(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return ee(t,e,1,1/0)}function Ee(t,e){b(t,s.map.majorEncoded,e.value)}Ee.compareTokens=B.compareTokens;Ee.encodedSize=function(e){return b.encodedSize(e.value)};function Yt(t,e,r,n){return new c(s.tag,r,1)}function er(t,e,r,n){return new c(s.tag,v(t,e+1,n),2)}function tr(t,e,r,n){return new c(s.tag,S(t,e+1,n),3)}function rr(t,e,r,n){return new c(s.tag,U(t,e+1,n),5)}function nr(t,e,r,n){return new c(s.tag,A(t,e+1,n),9)}function ve(t,e){b(t,s.tag.majorEncoded,e.value)}ve.compareTokens=B.compareTokens;ve.encodedSize=function(e){return b.encodedSize(e.value)};var xn=20,bn=21,kn=22,En=23;function or(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${f} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new c(s.null,null,1):new c(s.undefined,void 0,1)}function ir(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return new c(s.break,void 0,1)}function Le(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${f} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${f} Infinity values are not supported`)}return new c(s.float,t,e)}function sr(t,e,r,n){return Le(qe(t,e+1),3,n)}function ar(t,e,r,n){return Le(We(t,e+1),5,n)}function cr(t,e,r,n){return Le(hr(t,e+1),9,n)}function Se(t,e,r){let n=e.value;if(n===!1)t.push([s.float.majorEncoded|xn]);else if(n===!0)t.push([s.float.majorEncoded|bn]);else if(n===null)t.push([s.float.majorEncoded|kn]);else if(n===void 0)t.push([s.float.majorEncoded|En]);else{let o,i=!1;(!r||r.float64!==!0)&&(dr(n),o=qe(C,1),n===o||Number.isNaN(n)?(C[0]=249,t.push(C.slice(0,3)),i=!0):(fr(n),o=We(C,1),n===o&&(C[0]=250,t.push(C.slice(0,5)),i=!0))),i||(vn(n),o=hr(C,1),C[0]=251,t.push(C.slice(0,9)))}}Se.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){dr(n);let o=qe(C,1);if(n===o||Number.isNaN(n))return 3;if(fr(n),o=We(C,1),n===o)return 5}return 9};var ur=new ArrayBuffer(9),$=new DataView(ur,1),C=new Uint8Array(ur,0);function dr(t){if(t===1/0)$.setUint16(0,31744,!1);else if(t===-1/0)$.setUint16(0,64512,!1);else if(Number.isNaN(t))$.setUint16(0,32256,!1);else{$.setFloat32(0,t);let e=$.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)$.setUint16(0,31744,!1);else if(r===0)$.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?$.setUint16(0,0):o<-14?$.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):$.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qe(t,e){if(t.length-e<2)throw new Error(`${f} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function fr(t){$.setFloat32(0,t,!1)}function We(t,e){if(t.length-e<4)throw new Error(`${f} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function vn(t){$.setFloat64(0,t,!1)}function hr(t,e){if(t.length-e<8)throw new Error(`${f} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}Se.compareTokens=B.compareTokens;function p(t,e,r){throw new Error(`${f} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Ue(t){return()=>{throw new Error(`${f} ${t}`)}}var d=[];for(let t=0;t<=23;t++)d[t]=p;d[24]=kt;d[25]=Et;d[26]=vt;d[27]=St;d[28]=p;d[29]=p;d[30]=p;d[31]=p;for(let t=32;t<=55;t++)d[t]=p;d[56]=Ut;d[57]=At;d[58]=Tt;d[59]=$t;d[60]=p;d[61]=p;d[62]=p;d[63]=p;for(let t=64;t<=87;t++)d[t]=_t;d[88]=It;d[89]=Ct;d[90]=Nt;d[91]=Mt;d[92]=p;d[93]=p;d[94]=p;d[95]=Ue("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)d[t]=zt;d[120]=Ot;d[121]=Dt;d[122]=Vt;d[123]=Ft;d[124]=p;d[125]=p;d[126]=p;d[127]=Ue("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)d[t]=Pt;d[152]=Rt;d[153]=Lt;d[154]=qt;d[155]=Wt;d[156]=p;d[157]=p;d[158]=p;d[159]=Gt;for(let t=160;t<=183;t++)d[t]=Jt;d[184]=Kt;d[185]=Ht;d[186]=Xt;d[187]=Qt;d[188]=p;d[189]=p;d[190]=p;d[191]=Zt;for(let t=192;t<=215;t++)d[t]=Yt;d[216]=er;d[217]=tr;d[218]=rr;d[219]=nr;d[220]=p;d[221]=p;d[222]=p;d[223]=p;for(let t=224;t<=243;t++)d[t]=Ue("simple values are not supported");d[244]=p;d[245]=p;d[246]=p;d[247]=or;d[248]=Ue("simple values are not supported");d[249]=sr;d[250]=ar;d[251]=cr;d[252]=p;d[253]=p;d[254]=p;d[255]=ir;var N=[];for(let t=0;t<24;t++)N[t]=new c(s.uint,t,1);for(let t=-1;t>=-24;t--)N[31-t]=new c(s.negint,t,1);N[64]=new c(s.bytes,new Uint8Array(0),1);N[96]=new c(s.string,"",1);N[128]=new c(s.array,0,1);N[160]=new c(s.map,0,1);N[244]=new c(s.false,!1,1);N[245]=new c(s.true,!0,1);N[246]=new c(s.null,null,1);function Un(){let t=[];return t[s.uint.major]=B,t[s.negint.major]=xe,t[s.bytes.major]=Z,t[s.string.major]=jt,t[s.array.major]=ke,t[s.map.major]=Ee,t[s.tag.major]=ve,t[s.float.major]=Se,t}var pi=Un(),Ge=new ue,te=class{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${F} object contains circular references`);return new te(r,e)}},R={null:new c(s.null,null),undefined:new c(s.undefined,void 0),true:new c(s.true,!0),false:new c(s.false,!1),emptyArray:new c(s.array,0),emptyMap:new c(s.map,0)},L={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new c(s.float,t):t>=0?new c(s.uint,t):new c(s.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new c(s.uint,t):new c(s.negint,t)},Uint8Array(t,e,r,n){return new c(s.bytes,t)},string(t,e,r,n){return new c(s.string,t)},boolean(t,e,r,n){return t?R.true:R.false},null(t,e,r,n){return R.null},undefined(t,e,r,n){return R.undefined},ArrayBuffer(t,e,r,n){return new c(s.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new c(s.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[R.emptyArray,new c(s.break)]:R.emptyArray;n=te.createCheck(n,t);let o=[],i=0;for(let a of t)o[i++]=Ae(a,r,n);return r.addBreakTokens?[new c(s.array,t.length),o,new c(s.break)]:[new c(s.array,t.length),o]},Object(t,e,r,n){let o=e!=="Object",i=o?t.keys():Object.keys(t),a=o?t.size:i.length;if(!a)return r.addBreakTokens===!0?[R.emptyMap,new c(s.break)]:R.emptyMap;n=te.createCheck(n,t);let u=[],h=0;for(let g of i)u[h++]=[Ae(g,r,n),Ae(o?t.get(g):t[g],r,n)];return An(u,r),r.addBreakTokens?[new c(s.map,a),u,new c(s.break)]:[new c(s.map,a),u]}};L.Map=L.Object;L.Buffer=L.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))L[`${t}Array`]=L.DataView;function Ae(t,e={},r){let n=pt(t),o=e&&e.typeEncoders&&e.typeEncoders[n]||L[n];if(typeof o=="function"){let a=o(t,n,e,r);if(a!=null)return a}let i=L[n];if(!i)throw new Error(`${F} unsupported type: ${n}`);return i(t,n,e,r)}function An(t,e){e.mapSorter&&t.sort(e.mapSorter)}function pr(t,e,r,n){if(Array.isArray(e))for(let o of e)pr(t,o,r,n);else r[e.type.major](t,e,n)}function lr(t,e,r){let n=Ae(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=e[n.type.major];if(i.encodedSize){let a=i.encodedSize(n,r),u=new ue(a);if(i(u,n,r),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return ce(u.chunks[0])}}return Ge.reset(),pr(Ge,n,e,r),Ge.toBytes(!0)}var Tn={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Je=class{constructor(e,r={}){this.pos=0,this.data=e,this.options=r}done(){return this.pos>=this.data.length}next(){let e=this.data[this.pos],r=N[e];if(r===void 0){let n=d[e];if(!n)throw new Error(`${f} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;r=n(this.data,this.pos,o,this.options)}return this.pos+=r.encodedLength,r}},pe=Symbol.for("DONE"),Te=Symbol.for("BREAK");function Bn(t,e,r){let n=[];for(let o=0;o<t.value;o++){let i=le(e,r);if(i===Te){if(t.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed array`)}if(i===pe)throw new Error(`${f} found array but not enough entries (got ${o}, expected ${t.value})`);n[o]=i}return n}function $n(t,e,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let a=0;a<t.value;a++){let u=le(e,r);if(u===Te){if(t.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(u===pe)throw new Error(`${f} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${f} non-string keys not supported (got ${typeof u})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${f} found repeat map key "${u}"`);let h=le(e,r);if(h===pe)throw new Error(`${f} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?i.set(u,h):o[u]=h}return n?i:o}function le(t,e){if(t.done())return pe;let r=t.next();if(r.type===s.break)return Te;if(r.type.terminal)return r.value;if(r.type===s.array)return Bn(r,t,e);if(r.type===s.map)return $n(r,t,e);if(r.type===s.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=le(t,e);return e.tags[r.value](n)}throw new Error(`${f} tag not supported (${r.value})`)}throw new Error("unsupported")}function Ke(t,e){if(!(t instanceof Uint8Array))throw new Error(`${f} data to decode must be a Uint8Array`);e=Object.assign({},Tn,e);let r=e.tokenizer||new Je(t,e),n=le(r,e);if(n===pe)throw new Error(`${f} did not find any content to decode`);if(n===Te)throw new Error(`${f} got unexpected break`);if(!r.done())throw new Error(`${f} too many terminals, data makes no sense`);return n}var He=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(r.type===s.array&&(r.elements++,r.elements!==1&&e.push([44])),r.type===s.map&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[s.uint.major](e,r){this.prefix(e);let n=String(r.value),o=[];for(let i=0;i<n.length;i++)o[i]=n.charCodeAt(i);e.push(o)}[s.negint.major](e,r){this[s.uint.major](e,r)}[s.bytes.major](e,r){throw new Error(`${F} unsupported type: Uint8Array`)}[s.string.major](e,r){this.prefix(e);let n=we(JSON.stringify(r.value));e.push(n.length>32?ce(n):n)}[s.array.major](e,r){this.prefix(e),this.inRecursive.push({type:s.array,elements:0}),e.push([91])}[s.map.major](e,r){this.prefix(e),this.inRecursive.push({type:s.map,elements:0}),e.push([123])}[s.tag.major](e,r){}[s.float.major](e,r){if(r.type.name==="break"){let a=this.inRecursive.pop();if(a){if(a.type===s.array)e.push([93]);else if(a.type===s.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${F} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),o=[],i=!1;for(let a=0;a<n.length;a++)o[a]=n.charCodeAt(a),!i&&(o[a]===46||o[a]===101||o[a]===69)&&(i=!0);i||(o.push(46),o.push(48)),e.push(o)}};function _n(t,e){if(Array.isArray(t[0])||Array.isArray(e[0]))throw new Error(`${F} complex map keys are not supported`);let r=t[0],n=e[0];if(r.type!==s.string||n.type!==s.string)throw new Error(`${F} non-string map keys are not supported`);if(r<n)return-1;if(r>n)return 1;throw new Error(`${F} unexpected duplicate map keys, this is not supported`)}var In={addBreakTokens:!0,mapSorter:_n};function Xe(t,e){return e=Object.assign({},In,e),lr(t,new He,e)}var re=class{constructor(e,r={}){this.pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}done(){return this.pos>=this.data.length}ch(){return this.data[this.pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this.pos]}expect(e){if(this.data.length-this.pos<e.length)throw new Error(`${f} unexpected end of input at position ${this.pos}`);for(let r=0;r<e.length;r++)if(this.data[this.pos++]!==e[r])throw new Error(`${f} unexpected token at position ${this.pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this.pos,r=!1,n=!1,o=u=>{for(;!this.done();){let h=this.ch();if(u.includes(h))this.pos++;else break}};if(this.ch()===45&&(r=!0,this.pos++),this.ch()===48)if(this.pos++,this.ch()===46)this.pos++,n=!0;else return new c(s.uint,0,this.pos-e);if(o([48,49,50,51,52,53,54,55,56,57]),r&&this.pos===e+1)throw new Error(`${f} unexpected token at position ${this.pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${f} unexpected token at position ${this.pos}`);n=!0,this.pos++,o([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this.pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this.pos++,o([48,49,50,51,52,53,54,55,56,57]));let i=String.fromCharCode.apply(null,this.data.subarray(e,this.pos)),a=parseFloat(i);return n?new c(s.float,a,this.pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(a)?new c(a>=0?s.uint:s.negint,a,this.pos-e):new c(a>=0?s.uint:s.negint,BigInt(i),this.pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${f} unexpected character at position ${this.pos}; this shouldn't happen`);this.pos++;for(let i=this.pos,a=0;i<this.data.length&&a<65536;i++,a++){let u=this.data[i];if(u===92||u<32||u>=128)break;if(u===34){let h=String.fromCharCode.apply(null,this.data.subarray(this.pos,i));return this.pos=i+1,new c(s.string,h,a)}}let e=this.pos,r=[],n=()=>{if(this.pos+4>=this.data.length)throw new Error(`${f} unexpected end of unicode escape sequence at position ${this.pos}`);let i=0;for(let a=0;a<4;a++){let u=this.ch();if(u>=48&&u<=57)u-=48;else if(u>=97&&u<=102)u=u-97+10;else if(u>=65&&u<=70)u=u-65+10;else throw new Error(`${f} unexpected unicode escape character at position ${this.pos}`);i=i*16+u,this.pos++}return i},o=()=>{let i=this.ch(),a=null,u=i>239?4:i>223?3:i>191?2:1;if(this.pos+u>this.data.length)throw new Error(`${f} unexpected unicode sequence at position ${this.pos}`);let h,g,l,w;switch(u){case 1:i<128&&(a=i);break;case 2:h=this.data[this.pos+1],(h&192)===128&&(w=(i&31)<<6|h&63,w>127&&(a=w));break;case 3:h=this.data[this.pos+1],g=this.data[this.pos+2],(h&192)===128&&(g&192)===128&&(w=(i&15)<<12|(h&63)<<6|g&63,w>2047&&(w<55296||w>57343)&&(a=w));break;case 4:h=this.data[this.pos+1],g=this.data[this.pos+2],l=this.data[this.pos+3],(h&192)===128&&(g&192)===128&&(l&192)===128&&(w=(i&15)<<18|(h&63)<<12|(g&63)<<6|l&63,w>65535&&w<1114112&&(a=w))}a===null?(a=65533,u=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023),r.push(a),this.pos+=u};for(;!this.done();){let i=this.ch(),a;switch(i){case 92:if(this.pos++,this.done())throw new Error(`${f} unexpected string termination at position ${this.pos}`);switch(a=this.ch(),this.pos++,a){case 34:case 39:case 92:case 47:r.push(a);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${f} unexpected string escape character at position ${this.pos}`)}break;case 34:return this.pos++,new c(s.string,Pe(r),this.pos-e);default:if(i<32)throw new Error(`${f} invalid control character at position ${this.pos}`);i<128?(r.push(i),this.pos++):o()}}throw new Error(`${f} unexpected end of string at position ${this.pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this.pos++,new c(s.map,1/0,1);case 91:return this.modeStack.push("array-start"),this.pos++,new c(s.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new c(s.null,null,4);case 102:return this.expect([102,97,108,115,101]),new c(s.false,!1,5);case 116:return this.expect([116,114,117,101]),new c(s.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${f} unexpected character at position ${this.pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this.pos++,this.skipWhitespace(),new c(s.break,void 0,1);if(this.ch()!==44)throw new Error(`${f} unexpected character at position ${this.pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this.pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this.pos++,this.skipWhitespace(),new c(s.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this.pos++,this.skipWhitespace(),new c(s.break,void 0,1);if(this.ch()!==44)throw new Error(`${f} unexpected character at position ${this.pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this.pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this.pos++,this.skipWhitespace(),new c(s.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${f} unexpected character at position ${this.pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this.pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${f} unexpected parse state at position ${this.pos}; this shouldn't happen`)}}};function Qe(t,e){return e=Object.assign({tokenizer:new re(t,e)},e),Ke(t,e)}function Nn(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=y.asCID(t);if(!e)return null;let r=e.toString();return[new c(s.map,1/0,1),new c(s.string,"/",1),new c(s.string,r,r.length),new c(s.break,void 0,1)]}function mr(t){let e=je.encode(t).slice(1);return[new c(s.map,1/0,1),new c(s.string,"/",1),new c(s.map,1/0,1),new c(s.string,"bytes",5),new c(s.string,e,e.length),new c(s.break,void 0,1),new c(s.break,void 0,1)]}function Mn(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function zn(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var On={typeEncoders:{Object:Nn,Uint8Array:mr,Buffer:mr,undefined:Mn,number:zn}},Ze=class extends re{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===s.map){let r=this._next();if(r.type===s.string&&r.value==="/"){let n=this._next();if(n.type===s.string){if(this._next().type!==s.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new c(s.tag,42,0)}if(n.type===s.map){let o=this._next();if(o.type===s.string&&o.value==="bytes"){let i=this._next();if(i.type===s.string){for(let u=0;u<2;u++)if(this._next().type!==s.break)throw new Error("Invalid encoded Bytes form");let a=je.decode(`m${i.value}`);return new c(s.bytes,a,i.value.length)}this.tokenBuffer.push(i)}this.tokenBuffer.push(o)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},Ye={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Ye.tags[42]=y.parse;var yr=297,gr=t=>Xe(t,On),wr=t=>{let e=Object.assign(Ye,{tokenizer:new Ze(t,Ye)});return Qe(t,e)};var Fi=new TextDecoder;var ji=new TextEncoder;var xr=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),br=Fe({name:"sha2-256",code:18,encode:xr("SHA-256")}),Ri=Fe({name:"sha2-512",code:19,encode:xr("SHA-512")});var et=class{components;constructor(e){this.components=e}async add(e,r={}){let n=gr(e),o=await(r.hasher??br).digest(n),i=y.createV1(yr,o);return await this.components.blockstore.put(i,n,r),i}async get(e,r={}){let n=await this.components.blockstore.get(e,r);return wr(n)}};function Vn(t){return new et(t)}return Tr(Fn);})();
|
|
3
|
+
return HeliaDagJson}));
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* `@helia/dag-json` makes working with DAG-JSON {@link https://github.com/ipfs/helia Helia} simple & straightforward.
|
|
5
|
+
*
|
|
6
|
+
* See the {@link Strings Strings interface} for all available operations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createHelia } from 'helia'
|
|
12
|
+
* import { json } from '@helia/dag-json'
|
|
13
|
+
* import { CID } from 'multiformats/cid'
|
|
14
|
+
*
|
|
15
|
+
* const j = json(helia)
|
|
16
|
+
* const cid = await j.put({
|
|
17
|
+
* hello: 'world'
|
|
18
|
+
* })
|
|
19
|
+
* const obj = await j.get(cid)
|
|
20
|
+
*
|
|
21
|
+
* console.info(obj)
|
|
22
|
+
* // { hello: 'world' }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { CID } from 'multiformats/cid';
|
|
26
|
+
import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks';
|
|
27
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
28
|
+
import type { BlockCodec } from 'multiformats/codecs/interface';
|
|
29
|
+
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
30
|
+
import type { ProgressOptions } from 'progress-events';
|
|
31
|
+
export interface DAGJSONComponents {
|
|
32
|
+
blockstore: Blocks;
|
|
33
|
+
}
|
|
34
|
+
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
|
|
35
|
+
hasher: MultihashHasher;
|
|
36
|
+
}
|
|
37
|
+
export interface GetOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
|
|
38
|
+
codec: BlockCodec<any, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The JSON interface provides a simple and intuitive way to add/get objects
|
|
42
|
+
* with your Helia node and is a great place to start learning about IPFS.
|
|
43
|
+
*/
|
|
44
|
+
export interface DAGJSON {
|
|
45
|
+
/**
|
|
46
|
+
* Add an object to your Helia node and get a CID that refers to the block the
|
|
47
|
+
* object has been stored as.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
*
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { json } from '@helia/dag-json'
|
|
53
|
+
*
|
|
54
|
+
* const j = json(helia)
|
|
55
|
+
* const cid = await str.add({ hello: 'world' })
|
|
56
|
+
*
|
|
57
|
+
* console.info(cid)
|
|
58
|
+
* // CID(baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
add: (str: unknown, options?: Partial<AddOptions>) => Promise<CID>;
|
|
62
|
+
/**
|
|
63
|
+
* Get an object from your Helia node, either previously added to it or to
|
|
64
|
+
* another node on the network.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { json } from '@helia/dag-json'
|
|
70
|
+
* import { CID } from 'multiformats/cid'
|
|
71
|
+
*
|
|
72
|
+
* const j = json(helia)
|
|
73
|
+
* const cid = CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
|
|
74
|
+
* const obj = await j.get(cid)
|
|
75
|
+
*
|
|
76
|
+
* console.info(obj)
|
|
77
|
+
* // { hello: 'world' }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
get: <T>(cid: CID, options?: Partial<GetOptions>) => Promise<T>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a {@link DAGJSON} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
84
|
+
*/
|
|
85
|
+
export declare function dagJson(helia: {
|
|
86
|
+
blockstore: Blocks;
|
|
87
|
+
}): DAGJSON;
|
|
88
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC;IACvF,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC;IACvF,KAAK,EAAE,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;;;;;;;;;;OAeG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAElE;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,EAAE,CAAC,CAAC,EAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACjE;AA0BD;;GAEG;AACH,wBAAgB,OAAO,CAAE,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE/D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* `@helia/dag-json` makes working with DAG-JSON {@link https://github.com/ipfs/helia Helia} simple & straightforward.
|
|
5
|
+
*
|
|
6
|
+
* See the {@link Strings Strings interface} for all available operations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createHelia } from 'helia'
|
|
12
|
+
* import { json } from '@helia/dag-json'
|
|
13
|
+
* import { CID } from 'multiformats/cid'
|
|
14
|
+
*
|
|
15
|
+
* const j = json(helia)
|
|
16
|
+
* const cid = await j.put({
|
|
17
|
+
* hello: 'world'
|
|
18
|
+
* })
|
|
19
|
+
* const obj = await j.get(cid)
|
|
20
|
+
*
|
|
21
|
+
* console.info(obj)
|
|
22
|
+
* // { hello: 'world' }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { CID } from 'multiformats/cid';
|
|
26
|
+
import * as codec from '@ipld/dag-json';
|
|
27
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
28
|
+
class DefaultDAGJSON {
|
|
29
|
+
components;
|
|
30
|
+
constructor(components) {
|
|
31
|
+
this.components = components;
|
|
32
|
+
}
|
|
33
|
+
async add(obj, options = {}) {
|
|
34
|
+
const buf = codec.encode(obj);
|
|
35
|
+
const hash = await (options.hasher ?? sha256).digest(buf);
|
|
36
|
+
const cid = CID.createV1(codec.code, hash);
|
|
37
|
+
await this.components.blockstore.put(cid, buf, options);
|
|
38
|
+
return cid;
|
|
39
|
+
}
|
|
40
|
+
async get(cid, options = {}) {
|
|
41
|
+
const buf = await this.components.blockstore.get(cid, options);
|
|
42
|
+
return codec.decode(buf);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a {@link DAGJSON} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
47
|
+
*/
|
|
48
|
+
export function dagJson(helia) {
|
|
49
|
+
return new DefaultDAGJSON(helia);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AA+DjD,MAAM,cAAc;IACD,UAAU,CAAmB;IAE9C,YAAa,UAA6B;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAQ,EAAE,UAA+B,EAAE;QACpD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACzD,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE1C,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;QAEvD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,GAAG,CAAM,GAAQ,EAAE,UAA+B,EAAE;QACxD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAE9D,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAE,KAA6B;IACpD,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@helia/dag-json",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Add/get IPLD blocks containing json with your Helia node",
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/ipfs/helia-dag-json/tree/master/packages/dag-json#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ipfs/helia-dag-json.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ipfs/helia-dag-json/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"IPFS"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16.0.0",
|
|
19
|
+
"npm": ">=7.0.0"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"dist",
|
|
26
|
+
"!dist/test",
|
|
27
|
+
"!**/*.tsbuildinfo"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/src/index.d.ts",
|
|
32
|
+
"import": "./dist/src/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"eslintConfig": {
|
|
36
|
+
"extends": "ipfs",
|
|
37
|
+
"parserOptions": {
|
|
38
|
+
"sourceType": "module"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"release": {
|
|
42
|
+
"branches": [
|
|
43
|
+
"main"
|
|
44
|
+
],
|
|
45
|
+
"plugins": [
|
|
46
|
+
[
|
|
47
|
+
"@semantic-release/commit-analyzer",
|
|
48
|
+
{
|
|
49
|
+
"preset": "conventionalcommits",
|
|
50
|
+
"releaseRules": [
|
|
51
|
+
{
|
|
52
|
+
"breaking": true,
|
|
53
|
+
"release": "major"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"revert": true,
|
|
57
|
+
"release": "patch"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "feat",
|
|
61
|
+
"release": "minor"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"type": "fix",
|
|
65
|
+
"release": "patch"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"type": "docs",
|
|
69
|
+
"release": "patch"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"type": "test",
|
|
73
|
+
"release": "patch"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"type": "deps",
|
|
77
|
+
"release": "patch"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"scope": "no-release",
|
|
81
|
+
"release": false
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
"@semantic-release/release-notes-generator",
|
|
88
|
+
{
|
|
89
|
+
"preset": "conventionalcommits",
|
|
90
|
+
"presetConfig": {
|
|
91
|
+
"types": [
|
|
92
|
+
{
|
|
93
|
+
"type": "feat",
|
|
94
|
+
"section": "Features"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "fix",
|
|
98
|
+
"section": "Bug Fixes"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"type": "chore",
|
|
102
|
+
"section": "Trivial Changes"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"type": "docs",
|
|
106
|
+
"section": "Documentation"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"type": "deps",
|
|
110
|
+
"section": "Dependencies"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"type": "test",
|
|
114
|
+
"section": "Tests"
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"@semantic-release/changelog",
|
|
121
|
+
"@semantic-release/npm",
|
|
122
|
+
"@semantic-release/github",
|
|
123
|
+
"@semantic-release/git"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"scripts": {
|
|
127
|
+
"clean": "aegir clean",
|
|
128
|
+
"lint": "aegir lint",
|
|
129
|
+
"dep-check": "aegir dep-check",
|
|
130
|
+
"build": "aegir build",
|
|
131
|
+
"docs": "aegir docs",
|
|
132
|
+
"test": "aegir test",
|
|
133
|
+
"test:chrome": "aegir test -t browser --cov",
|
|
134
|
+
"test:chrome-webworker": "aegir test -t webworker",
|
|
135
|
+
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
136
|
+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
137
|
+
"test:node": "aegir test -t node --cov",
|
|
138
|
+
"test:electron-main": "aegir test -t electron-main",
|
|
139
|
+
"release": "aegir release"
|
|
140
|
+
},
|
|
141
|
+
"dependencies": {
|
|
142
|
+
"@helia/interface": "^1.0.0",
|
|
143
|
+
"@ipld/dag-json": "^10.0.1",
|
|
144
|
+
"@libp2p/interfaces": "^3.3.1",
|
|
145
|
+
"interface-blockstore": "^5.0.0",
|
|
146
|
+
"multiformats": "^11.0.1",
|
|
147
|
+
"progress-events": "^1.0.0"
|
|
148
|
+
},
|
|
149
|
+
"devDependencies": {
|
|
150
|
+
"aegir": "^39.0.3",
|
|
151
|
+
"blockstore-core": "^4.0.1"
|
|
152
|
+
},
|
|
153
|
+
"typedoc": {
|
|
154
|
+
"entryPoint": "./src/index.ts"
|
|
155
|
+
}
|
|
156
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* `@helia/dag-json` makes working with DAG-JSON {@link https://github.com/ipfs/helia Helia} simple & straightforward.
|
|
5
|
+
*
|
|
6
|
+
* See the {@link Strings Strings interface} for all available operations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createHelia } from 'helia'
|
|
12
|
+
* import { json } from '@helia/dag-json'
|
|
13
|
+
* import { CID } from 'multiformats/cid'
|
|
14
|
+
*
|
|
15
|
+
* const j = json(helia)
|
|
16
|
+
* const cid = await j.put({
|
|
17
|
+
* hello: 'world'
|
|
18
|
+
* })
|
|
19
|
+
* const obj = await j.get(cid)
|
|
20
|
+
*
|
|
21
|
+
* console.info(obj)
|
|
22
|
+
* // { hello: 'world' }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { CID } from 'multiformats/cid'
|
|
27
|
+
import * as codec from '@ipld/dag-json'
|
|
28
|
+
import { sha256 } from 'multiformats/hashes/sha2'
|
|
29
|
+
import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
|
|
30
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
31
|
+
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
32
|
+
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
33
|
+
import type { ProgressOptions } from 'progress-events'
|
|
34
|
+
|
|
35
|
+
export interface DAGJSONComponents {
|
|
36
|
+
blockstore: Blocks
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
|
|
40
|
+
hasher: MultihashHasher
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface GetOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
|
|
44
|
+
codec: BlockCodec<any, unknown>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The JSON interface provides a simple and intuitive way to add/get objects
|
|
49
|
+
* with your Helia node and is a great place to start learning about IPFS.
|
|
50
|
+
*/
|
|
51
|
+
export interface DAGJSON {
|
|
52
|
+
/**
|
|
53
|
+
* Add an object to your Helia node and get a CID that refers to the block the
|
|
54
|
+
* object has been stored as.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { json } from '@helia/dag-json'
|
|
60
|
+
*
|
|
61
|
+
* const j = json(helia)
|
|
62
|
+
* const cid = await str.add({ hello: 'world' })
|
|
63
|
+
*
|
|
64
|
+
* console.info(cid)
|
|
65
|
+
* // CID(baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
add: (str: unknown, options?: Partial<AddOptions>) => Promise<CID>
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get an object from your Helia node, either previously added to it or to
|
|
72
|
+
* another node on the network.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
*
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { json } from '@helia/dag-json'
|
|
78
|
+
* import { CID } from 'multiformats/cid'
|
|
79
|
+
*
|
|
80
|
+
* const j = json(helia)
|
|
81
|
+
* const cid = CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
|
|
82
|
+
* const obj = await j.get(cid)
|
|
83
|
+
*
|
|
84
|
+
* console.info(obj)
|
|
85
|
+
* // { hello: 'world' }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
get: <T> (cid: CID, options?: Partial<GetOptions>) => Promise<T>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
class DefaultDAGJSON implements DAGJSON {
|
|
92
|
+
private readonly components: DAGJSONComponents
|
|
93
|
+
|
|
94
|
+
constructor (components: DAGJSONComponents) {
|
|
95
|
+
this.components = components
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async add (obj: any, options: Partial<AddOptions> = {}): Promise<CID> {
|
|
99
|
+
const buf = codec.encode(obj)
|
|
100
|
+
const hash = await (options.hasher ?? sha256).digest(buf)
|
|
101
|
+
const cid = CID.createV1(codec.code, hash)
|
|
102
|
+
|
|
103
|
+
await this.components.blockstore.put(cid, buf, options)
|
|
104
|
+
|
|
105
|
+
return cid
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async get <T> (cid: CID, options: Partial<GetOptions> = {}): Promise<T> {
|
|
109
|
+
const buf = await this.components.blockstore.get(cid, options)
|
|
110
|
+
|
|
111
|
+
return codec.decode(buf)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create a {@link DAGJSON} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
117
|
+
*/
|
|
118
|
+
export function dagJson (helia: { blockstore: Blocks }): DAGJSON {
|
|
119
|
+
return new DefaultDAGJSON(helia)
|
|
120
|
+
}
|