@dfinity/nns 0.1.8 → 0.1.9

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.
Files changed (37) hide show
  1. package/dist/cjs/index.cjs.js +869 -0
  2. package/dist/cjs/index.cjs.js.map +7 -0
  3. package/dist/esm/account_identifier.js +2 -0
  4. package/dist/esm/account_identifier.js.map +7 -0
  5. package/dist/esm/chunk-AAXRCEPL.js +2 -0
  6. package/dist/esm/chunk-AAXRCEPL.js.map +7 -0
  7. package/dist/esm/chunk-AV2V5I5D.js +10 -0
  8. package/dist/esm/chunk-AV2V5I5D.js.map +7 -0
  9. package/dist/esm/chunk-NR65YN67.js +14 -0
  10. package/dist/esm/chunk-NR65YN67.js.map +7 -0
  11. package/dist/esm/chunk-QXLTRMTU.js +832 -0
  12. package/dist/esm/chunk-QXLTRMTU.js.map +7 -0
  13. package/dist/esm/chunk-RKZCM7KO.js +4 -0
  14. package/dist/esm/chunk-RKZCM7KO.js.map +7 -0
  15. package/dist/esm/chunk-UJYSTOZE.js +2 -0
  16. package/dist/esm/chunk-UJYSTOZE.js.map +7 -0
  17. package/dist/esm/chunk-XN3QHASA.js +4 -0
  18. package/dist/esm/chunk-XN3QHASA.js.map +7 -0
  19. package/dist/esm/chunk-YXM7FYC5.js +2 -0
  20. package/dist/esm/chunk-YXM7FYC5.js.map +7 -0
  21. package/dist/esm/governance.js +2 -0
  22. package/dist/esm/governance.js.map +7 -0
  23. package/dist/esm/icp.js +2 -0
  24. package/dist/esm/icp.js.map +7 -0
  25. package/dist/esm/index.js +2 -0
  26. package/dist/esm/index.js.map +7 -0
  27. package/dist/esm/ledger.js +2 -0
  28. package/dist/esm/ledger.js.map +7 -0
  29. package/dist/index.cjs.js +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/types/account_identifier.d.ts +21 -0
  32. package/dist/types/governance.d.ts +30 -0
  33. package/dist/types/icp.d.ts +20 -0
  34. package/dist/types/index.d.ts +5 -0
  35. package/dist/types/ledger.d.ts +54 -0
  36. package/dist/types/utils/proto.d.ts +12 -0
  37. package/package.json +1 -1
@@ -0,0 +1,4 @@
1
+ import{a as f,b as m,c as g,d as u}from"./chunk-QXLTRMTU.js";import{a as l}from"./chunk-YXM7FYC5.js";import{a as B}from"./chunk-NR65YN67.js";import{c as C}from"./chunk-UJYSTOZE.js";var n=C(B());var y=async(i,e,s,c)=>{let t=await i.call(e,{methodName:s,arg:c,effectiveCanisterId:e});if(!t.response.ok)return Error(["Call failed:",` Method: ${s}`,` Canister ID: ${e}`,` Request ID: ${t.requestId}`,` HTTP status code: ${t.response.status}`,` HTTP status text: ${t.response.statusText}`].join(`
2
+ `));try{let a=await u.pollForResponse(i,e,t.requestId,u.defaultStrategy());return new Uint8Array(a)}catch(a){if(a instanceof Error)return a;throw a}},h=async(i,e,s,c)=>{let t=await i.query(e,{methodName:s,arg:c});return t.status=="rejected"?new Error(["Call failed:",` Method: ${s}`,` Canister ID: ${e}`,` HTTP status code: ${t.reject_code}`,` HTTP status text: ${t.reject_message}`].join(`
3
+ `)):new Uint8Array(t.reply.arg)};var T=f.fromText("ryjl3-tyaaa-aaaaa-aaaba-cai"),w=class{},x=class{},A=class{constructor(e){this.balance=e}},I=class{constructor(e){this.allowed_window_secs=e}},P=class{},b=class{constructor(e){this.duplicateOf=e}},p=class{constructor(e,s,c,t){this.agent=e;this.canisterId=s;this.updateFetcher=c;this.queryFetcher=t}static create(e={}){return new p(e.agent??E(),e.canisterId??T,e.updateCallOverride??y,e.queryCallOverride??h)}accountBalance=async(e,s=!0)=>{let c=s?this.updateFetcher:this.queryFetcher,t=new n.AccountBalanceRequest;t.setAccount(e.toProto());let a=await c(this.agent,this.canisterId,"account_balance_pb",t.serializeBinary());if(a instanceof Error)throw Error;return l.fromE8s(BigInt(n.ICPTs.deserializeBinary(new Uint8Array(a)).getE8s()))};transfer=async(e,s,c)=>{let t=new n.SendRequest;t.setTo(e.toProto());let a=new n.Payment;if(a.setReceiverGets(s.toProto()),t.setPayment(a),c){let r=new n.Memo;r.setMemo(r.toString()),t.setMemo(r)}let o=await this.updateFetcher(this.agent,this.canisterId,"send_pb",t.serializeBinary());if(o instanceof Error){if(o.message.includes("Reject code: 5")){if(o.message.match(/Sending from (.*) is not allowed/))return new w;{let r=o.message.match(/transaction.*duplicate.* in block (\d+)/);if(r&&r.length>1)return new b(BigInt(r[1]))}{let r=o.message.match(/debit account.*, current balance: (\d*(\.\d*)?)/);if(r&&r.length>1){let d=l.fromString(r[1]);if(d instanceof l)return new A(d)}}if(o.message.includes("is in future"))return new P;{let r=o.message.match(/older than (\d+)/);if(r&&r.length>1)return new I(Number.parseInt(r[1]))}}throw o}return BigInt(n.BlockHeight.deserializeBinary(o).getHeight())}};function E(){return new g({host:"https://ic0.app",identity:new m})}export{w as a,x as b,A as c,I as d,P as e,b as f,p as g};
4
+ //# sourceMappingURL=chunk-RKZCM7KO.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ledger.ts", "../../src/utils/proto.ts"],
4
+ "sourcesContent": ["import { Agent, AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\nimport { Principal } from \"@dfinity/principal\";\nimport {\n AccountBalanceRequest,\n BlockHeight as PbBlockHeight,\n ICPTs,\n Memo,\n Payment,\n SendRequest,\n} from \"../proto/ledger_pb\";\nimport { AccountIdentifier } from \"./account_identifier\";\nimport { ICP } from \"./icp\";\nimport { updateCall, queryCall } from \"./utils/proto\";\n\nconst MAINNET_LEDGER_CANISTER_ID = Principal.fromText(\n \"ryjl3-tyaaa-aaaaa-aaaba-cai\"\n);\n\ntype BlockHeight = bigint;\n\nexport type TransferError =\n | InvalidSender\n | InsufficientFunds\n | TxTooOld\n | TxCreatedInFuture\n | TxDuplicate\n | BadFee;\n\nexport class InvalidSender {}\nexport class BadFee {}\nexport class InsufficientFunds {\n constructor(public readonly balance: ICP) {}\n}\nexport class TxTooOld {\n constructor(public readonly allowed_window_secs: number) {}\n}\nexport class TxCreatedInFuture {}\nexport class TxDuplicate {\n constructor(public readonly duplicateOf: BlockHeight) {}\n}\n\ntype Fetcher = (\n agent: Agent,\n canisterId: Principal,\n methodName: string,\n arg: ArrayBuffer\n) => Promise<Uint8Array | Error>;\n\n// HttpAgent options that can be used at construction.\nexport interface LedgerCanisterOptions {\n // The agent to use when communicating with the ledger canister.\n agent?: Agent;\n // The ledger canister's ID.\n canisterId?: Principal;\n // The method to use for performing an update call. Primarily overridden\n // in test for mocking.\n updateCallOverride?: Fetcher;\n // The method to use for performing a query call. Primarily overridden\n // in test for mocking.\n queryCallOverride?: Fetcher;\n}\n\nexport class LedgerCanister {\n private constructor(\n private readonly agent: Agent,\n private readonly canisterId: Principal,\n private readonly updateFetcher: Fetcher,\n private readonly queryFetcher: Fetcher\n ) {}\n\n public static create(options: LedgerCanisterOptions = {}) {\n return new LedgerCanister(\n options.agent ?? defaultAgent(),\n options.canisterId ?? MAINNET_LEDGER_CANISTER_ID,\n options.updateCallOverride ?? updateCall,\n options.queryCallOverride ?? queryCall\n );\n }\n\n /**\n * Returns the balance of the specified account identifier.\n *\n * If `certified` is true, the request is fetched as an update call, otherwise\n * it is fetched using a query call.\n */\n public accountBalance = async (\n accountIdentifier: AccountIdentifier,\n certified = true\n ): Promise<ICP> => {\n const callMethod = certified ? this.updateFetcher : this.queryFetcher;\n\n const request = new AccountBalanceRequest();\n request.setAccount(accountIdentifier.toProto());\n const responseBytes = await callMethod(\n this.agent,\n this.canisterId,\n \"account_balance_pb\",\n request.serializeBinary()\n );\n\n if (responseBytes instanceof Error) {\n // An error is never expected from this endpoint.\n throw Error;\n }\n\n return ICP.fromE8s(\n BigInt(ICPTs.deserializeBinary(new Uint8Array(responseBytes)).getE8s())\n );\n };\n\n /**\n * Transfer ICP from the caller to the destination `accountIdentifier`.\n * Returns the index of the block containing the tx if it was successful.\n *\n * TODO: support remaining options (subaccounts, memos, etc.)\n */\n public transfer = async (\n to: AccountIdentifier,\n amount: ICP,\n memo?: bigint\n ): Promise<BlockHeight | TransferError> => {\n const request = new SendRequest();\n request.setTo(to.toProto());\n\n const payment = new Payment();\n payment.setReceiverGets(amount.toProto());\n request.setPayment(payment);\n\n if (memo) {\n const memo = new Memo();\n memo.setMemo(memo.toString());\n request.setMemo(memo);\n }\n\n const responseBytes = await this.updateFetcher(\n this.agent,\n this.canisterId,\n \"send_pb\",\n request.serializeBinary()\n );\n\n if (responseBytes instanceof Error) {\n if (responseBytes.message.includes(\"Reject code: 5\")) {\n // Match against the different error types.\n // This string matching is fragile. It's a stop-gap solution until\n // we migrate to the candid interface.\n\n if (responseBytes.message.match(/Sending from (.*) is not allowed/)) {\n return new InvalidSender();\n }\n\n {\n const m = responseBytes.message.match(\n /transaction.*duplicate.* in block (\\d+)/\n );\n if (m && m.length > 1) {\n return new TxDuplicate(BigInt(m[1]));\n }\n }\n\n {\n const m = responseBytes.message.match(\n /debit account.*, current balance: (\\d*(\\.\\d*)?)/\n );\n if (m && m.length > 1) {\n const balance = ICP.fromString(m[1]);\n if (balance instanceof ICP) {\n return new InsufficientFunds(balance);\n }\n }\n }\n\n if (responseBytes.message.includes(\"is in future\")) {\n return new TxCreatedInFuture();\n }\n\n {\n const m = responseBytes.message.match(/older than (\\d+)/);\n if (m && m.length > 1) {\n return new TxTooOld(Number.parseInt(m[1]));\n }\n }\n }\n\n // Unknown error. Throw as-is.\n throw responseBytes;\n }\n\n // Successful tx. Return the block height.\n return BigInt(PbBlockHeight.deserializeBinary(responseBytes).getHeight());\n };\n}\n\n/**\n * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.\n */\nfunction defaultAgent(): Agent {\n return new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n}\n", "import { Agent } from \"@dfinity/agent\";\nimport { Principal } from \"@dfinity/principal\";\nimport { polling } from \"@dfinity/agent\";\n\n/**\n * Submits an update call to the IC.\n * @returns The (binary) response if the request succeeded, an error otherwise.\n */\nexport const updateCall = async (\n agent: Agent,\n canisterId: Principal,\n methodName: string,\n arg: ArrayBuffer\n): Promise<Uint8Array | Error> => {\n const submitResponse = await agent.call(canisterId, {\n methodName,\n arg,\n effectiveCanisterId: canisterId,\n });\n\n if (!submitResponse.response.ok) {\n return Error(\n [\n \"Call failed:\",\n ` Method: ${methodName}`,\n ` Canister ID: ${canisterId}`,\n ` Request ID: ${submitResponse.requestId}`,\n ` HTTP status code: ${submitResponse.response.status}`,\n ` HTTP status text: ${submitResponse.response.statusText}`,\n ].join(\"\\n\")\n );\n }\n\n try {\n const blob = await polling.pollForResponse(\n agent,\n canisterId,\n submitResponse.requestId,\n polling.defaultStrategy()\n );\n return new Uint8Array(blob);\n } catch (err) {\n if (err instanceof Error) {\n // Return errors rather than throw them so that callers are forced to handle them.\n return err;\n }\n\n // Something very wrong happened, and we don't know how to deal with it. Throw as-is.\n throw err;\n }\n};\n\n/**\n * Submits a query call to the IC.\n * @returns The (binary) response if the request succeeded, an error otherwise.\n */\nexport const queryCall = async (\n agent: Agent,\n canisterId: Principal,\n methodName: string,\n arg: ArrayBuffer\n): Promise<Uint8Array | Error> => {\n const queryResponse = await agent.query(canisterId, {\n methodName,\n arg,\n });\n\n if (queryResponse.status == \"rejected\") {\n return new Error(\n [\n \"Call failed:\",\n ` Method: ${methodName}`,\n ` Canister ID: ${canisterId}`,\n ` HTTP status code: ${queryResponse.reject_code}`,\n ` HTTP status text: ${queryResponse.reject_message}`,\n ].join(\"\\n\")\n );\n }\n\n return new Uint8Array(queryResponse.reply.arg);\n};\n"],
5
+ "mappings": "qLAEA,MAOO,OCDA,GAAM,GAAa,MACxB,EACA,EACA,EACA,IACgC,CAChC,GAAM,GAAiB,KAAM,GAAM,KAAK,EAAY,CAClD,aACA,MACA,oBAAqB,IAGvB,GAAI,CAAC,EAAe,SAAS,GAC3B,MAAO,OACL,CACE,eACA,aAAa,IACb,kBAAkB,IAClB,iBAAiB,EAAe,YAChC,uBAAuB,EAAe,SAAS,SAC/C,uBAAuB,EAAe,SAAS,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GAHA,EAAQ,gBAAgB,EAAO,WAC/B,EAAQ,WAAW,GAEf,EAAM,CACR,GAAM,GAAO,GAAI,QACjB,EAAK,QAAQ,EAAK,YAClB,EAAQ,QAAQ,GAGlB,GAAM,GAAgB,KAAM,MAAK,cAC/B,KAAK,MACL,KAAK,WACL,UACA,EAAQ,mBAGV,GAAI,YAAyB,OAAO,CAClC,GAAI,EAAc,QAAQ,SAAS,kBAAmB,CAKpD,GAAI,EAAc,QAAQ,MAAM,oCAC9B,MAAO,IAAI,GAGb,CACE,GAAM,GAAI,EAAc,QAAQ,MAC9B,2CAEF,GAAI,GAAK,EAAE,OAAS,EAClB,MAAO,IAAI,GAAY,OAAO,EAAE,KAIpC,CACE,GAAM,GAAI,EAAc,QAAQ,MAC9B,mDAEF,GAAI,GAAK,EAAE,OAAS,EAAG,CACrB,GAAM,GAAU,EAAI,WAAW,EAAE,IACjC,GAAI,YAAmB,GACrB,MAAO,IAAI,GAAkB,IAKnC,GAAI,EAAc,QAAQ,SAAS,gBACjC,MAAO,IAAI,GAGb,CACE,GAAM,GAAI,EAAc,QAAQ,MAAM,oBACtC,GAAI,GAAK,EAAE,OAAS,EAClB,MAAO,IAAI,GAAS,OAAO,SAAS,EAAE,MAM5C,KAAM,GAIR,MAAO,QAAO,cAAc,kBAAkB,GAAe,eAOjE,YAA+B,CAC7B,MAAO,IAAI,GAAU,CACnB,KAAM,kBACN,SAAU,GAAI",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ var g=Object.create;var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var l=(b,a,c)=>a in b?e(b,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):b[a]=c;var m=b=>e(b,"__esModule",{value:!0});var o=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports),p=(b,a)=>{for(var c in a)e(b,c,{get:a[c],enumerable:!0})},n=(b,a,c,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&(c||d!=="default")&&e(b,d,{get:()=>a[d],enumerable:!(f=h(a,d))||f.enumerable});return b},q=(b,a)=>n(m(e(b!=null?g(j(b)):{},"default",!a&&b&&b.__esModule?{get:()=>b.default,enumerable:!0}:{value:b,enumerable:!0})),b);var r=(b,a,c)=>(l(b,typeof a!="symbol"?a+"":a,c),c);export{o as a,p as b,q as c,r as d};
2
+ //# sourceMappingURL=chunk-UJYSTOZE.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ import{a as q}from"./chunk-AV2V5I5D.js";import{a as X}from"./chunk-NR65YN67.js";import{a as V,c as F,d as x}from"./chunk-UJYSTOZE.js";var w=V(m=>{var h;(function(f){typeof DO_NOT_EXPORT_CRC=="undefined"?typeof m=="object"?f(m):typeof define=="function"&&define.amd?define(function(){var i={};return f(i),i}):f(h={}):f(h={})})(function(f){f.version="1.2.1";function i(){for(var r=0,u=new Array(256),t=0;t!=256;++t)r=t,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,r=r&1?-306674912^r>>>1:r>>>1,u[t]=r;return typeof Int32Array!="undefined"?new Int32Array(u):u}var a=i();function s(r){var u=0,t=0,e=0,n=typeof Int32Array!="undefined"?new Int32Array(4096):new Array(4096);for(e=0;e!=256;++e)n[e]=r[e];for(e=0;e!=256;++e)for(t=r[e],u=256+e;u<4096;u+=256)t=n[u]=t>>>8^r[t&255];var c=[];for(e=1;e!=16;++e)c[e-1]=typeof Int32Array!="undefined"?n.subarray(e*256,e*256+256):n.slice(e*256,e*256+256);return c}var o=s(a),y=o[0],b=o[1],p=o[2],I=o[3],P=o[4],S=o[5],E=o[6],O=o[7],_=o[8],C=o[9],H=o[10],D=o[11],j=o[12],k=o[13],Z=o[14];function L(r,u){for(var t=u^-1,e=0,n=r.length;e<n;)t=t>>>8^a[(t^r.charCodeAt(e++))&255];return~t}function N(r,u){for(var t=u^-1,e=r.length-15,n=0;n<e;)t=Z[r[n++]^t&255]^k[r[n++]^t>>8&255]^j[r[n++]^t>>16&255]^D[r[n++]^t>>>24]^H[r[n++]]^C[r[n++]]^_[r[n++]]^O[r[n++]]^E[r[n++]]^S[r[n++]]^P[r[n++]]^I[r[n++]]^p[r[n++]]^b[r[n++]]^y[r[n++]]^a[r[n++]];for(e+=15;n<e;)t=t>>>8^a[(t^r[n++])&255];return~t}function R(r,u){for(var t=u^-1,e=0,n=r.length,c=0,d=0;e<n;)c=r.charCodeAt(e++),c<128?t=t>>>8^a[(t^c)&255]:c<2048?(t=t>>>8^a[(t^(192|c>>6&31))&255],t=t>>>8^a[(t^(128|c&63))&255]):c>=55296&&c<57344?(c=(c&1023)+64,d=r.charCodeAt(e++)&1023,t=t>>>8^a[(t^(240|c>>8&7))&255],t=t>>>8^a[(t^(128|c>>2&63))&255],t=t>>>8^a[(t^(128|d>>6&15|(c&3)<<4))&255],t=t>>>8^a[(t^(128|d&63))&255]):(t=t>>>8^a[(t^(224|c>>12&15))&255],t=t>>>8^a[(t^(128|c>>6&63))&255],t=t>>>8^a[(t^(128|c&63))&255]);return~t}f.table=a,f.bstr=L,f.buf=N,f.str=R})});var T=F(X()),U=F(q()),g=F(w()),A=class{constructor(i){this.bytes=i}static fromHex(i){return new A(Uint8Array.from(Buffer.from(i,"hex")))}static fromPrincipal(i,a=v.ZERO){let s=z(`
2
+ account-id`),o=U.sha224.create();o.update([...s,...i.toUint8Array(),...a.toUint8Array()]);let y=new Uint8Array(o.array()),b=J(y),p=new Uint8Array([...b,...y]);return new A(p)}toProto(){let i=new T.AccountIdentifier;return i.setHash(this.bytes),i}toHex(){return G(this.bytes)}},l=class{constructor(i){this.bytes=i}static fromBytes(i){return i.length!=32?Error("Subaccount length must be 32-bytes"):new l(i)}static fromPrincipal(i){let a=new Uint8Array(32).fill(0),s=i.toUint8Array();a[0]=s.length;for(let o=0;o<s.length;o++)a[1+o]=s[o];return new l(a)}toUint8Array(){return this.bytes}},v=l;x(v,"ZERO",new l(new Uint8Array(32).fill(0)));var z=f=>Array.from(f).map(i=>i.charCodeAt(0)),G=f=>f.reduce((i,a)=>i+a.toString(16).padStart(2,"0"),""),J=f=>{let i=new ArrayBuffer(4);return new DataView(i).setUint32(0,g.buf(Buffer.from(f)),!1),Buffer.from(i)};export{A as a,v as b};
3
+ /*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
4
+ //# sourceMappingURL=chunk-XN3QHASA.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../node_modules/crc-32/crc32.js", "../../src/account_identifier.ts"],
4
+ "sourcesContent": ["/*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */\n/* vim: set ts=2: */\n/*exported CRC32 */\nvar CRC32;\n(function (factory) {\n\t/*jshint ignore:start */\n\t/*eslint-disable */\n\tif(typeof DO_NOT_EXPORT_CRC === 'undefined') {\n\t\tif('object' === typeof exports) {\n\t\t\tfactory(exports);\n\t\t} else if ('function' === typeof define && define.amd) {\n\t\t\tdefine(function () {\n\t\t\t\tvar module = {};\n\t\t\t\tfactory(module);\n\t\t\t\treturn module;\n\t\t\t});\n\t\t} else {\n\t\t\tfactory(CRC32 = {});\n\t\t}\n\t} else {\n\t\tfactory(CRC32 = {});\n\t}\n\t/*eslint-enable */\n\t/*jshint ignore:end */\n}(function(CRC32) {\nCRC32.version = '1.2.1';\n/*global Int32Array */\nfunction signed_crc_table() {\n\tvar c = 0, table = new Array(256);\n\n\tfor(var n =0; n != 256; ++n){\n\t\tc = n;\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\tc = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));\n\t\ttable[n] = c;\n\t}\n\n\treturn typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;\n}\n\nvar T0 = signed_crc_table();\nfunction slice_by_16_tables(T) {\n\tvar c = 0, v = 0, n = 0, table = typeof Int32Array !== 'undefined' ? new Int32Array(4096) : new Array(4096) ;\n\n\tfor(n = 0; n != 256; ++n) table[n] = T[n];\n\tfor(n = 0; n != 256; ++n) {\n\t\tv = T[n];\n\t\tfor(c = 256 + n; c < 4096; c += 256) v = table[c] = (v >>> 8) ^ T[v & 0xFF];\n\t}\n\tvar out = [];\n\tfor(n = 1; n != 16; ++n) out[n - 1] = typeof Int32Array !== 'undefined' ? table.subarray(n * 256, n * 256 + 256) : table.slice(n * 256, n * 256 + 256);\n\treturn out;\n}\nvar TT = slice_by_16_tables(T0);\nvar T1 = TT[0], T2 = TT[1], T3 = TT[2], T4 = TT[3], T5 = TT[4];\nvar T6 = TT[5], T7 = TT[6], T8 = TT[7], T9 = TT[8], Ta = TT[9];\nvar Tb = TT[10], Tc = TT[11], Td = TT[12], Te = TT[13], Tf = TT[14];\nfunction crc32_bstr(bstr, seed) {\n\tvar C = seed ^ -1;\n\tfor(var i = 0, L = bstr.length; i < L;) C = (C>>>8) ^ T0[(C^bstr.charCodeAt(i++))&0xFF];\n\treturn ~C;\n}\n\nfunction crc32_buf(B, seed) {\n\tvar C = seed ^ -1, L = B.length - 15, i = 0;\n\tfor(; i < L;) C =\n\t\tTf[B[i++] ^ (C & 255)] ^\n\t\tTe[B[i++] ^ ((C >> 8) & 255)] ^\n\t\tTd[B[i++] ^ ((C >> 16) & 255)] ^\n\t\tTc[B[i++] ^ (C >>> 24)] ^\n\t\tTb[B[i++]] ^ Ta[B[i++]] ^ T9[B[i++]] ^ T8[B[i++]] ^\n\t\tT7[B[i++]] ^ T6[B[i++]] ^ T5[B[i++]] ^ T4[B[i++]] ^\n\t\tT3[B[i++]] ^ T2[B[i++]] ^ T1[B[i++]] ^ T0[B[i++]];\n\tL += 15;\n\twhile(i < L) C = (C>>>8) ^ T0[(C^B[i++])&0xFF];\n\treturn ~C;\n}\n\nfunction crc32_str(str, seed) {\n\tvar C = seed ^ -1;\n\tfor(var i = 0, L = str.length, c = 0, d = 0; i < L;) {\n\t\tc = str.charCodeAt(i++);\n\t\tif(c < 0x80) {\n\t\t\tC = (C>>>8) ^ T0[(C^c)&0xFF];\n\t\t} else if(c < 0x800) {\n\t\t\tC = (C>>>8) ^ T0[(C ^ (192|((c>>6)&31)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];\n\t\t} else if(c >= 0xD800 && c < 0xE000) {\n\t\t\tc = (c&1023)+64; d = str.charCodeAt(i++)&1023;\n\t\t\tC = (C>>>8) ^ T0[(C ^ (240|((c>>8)&7)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|((c>>2)&63)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|((d>>6)&15)|((c&3)<<4)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|(d&63)))&0xFF];\n\t\t} else {\n\t\t\tC = (C>>>8) ^ T0[(C ^ (224|((c>>12)&15)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|((c>>6)&63)))&0xFF];\n\t\t\tC = (C>>>8) ^ T0[(C ^ (128|(c&63)))&0xFF];\n\t\t}\n\t}\n\treturn ~C;\n}\nCRC32.table = T0;\n// $FlowIgnore\nCRC32.bstr = crc32_bstr;\n// $FlowIgnore\nCRC32.buf = crc32_buf;\n// $FlowIgnore\nCRC32.str = crc32_str;\n}));\n", "import { AccountIdentifier as AccountIdentifierPb } from \"../proto/ledger_pb\";\nimport { sha224 } from \"js-sha256\";\nimport * as crc from \"crc-32\";\nimport { Principal } from \"@dfinity/principal\";\n\nexport class AccountIdentifier {\n private constructor(private readonly bytes: Uint8Array) {}\n\n public static fromHex(hex: string): AccountIdentifier {\n return new AccountIdentifier(Uint8Array.from(Buffer.from(hex, \"hex\")));\n }\n\n public static fromPrincipal(\n principal: Principal,\n subAccount = SubAccount.ZERO\n ): AccountIdentifier {\n // Hash (sha224) the principal, the subAccount and some padding\n const padding = asciiStringToByteArray(\"\\x0Aaccount-id\");\n\n const shaObj = sha224.create();\n shaObj.update([\n ...padding,\n ...principal.toUint8Array(),\n ...subAccount.toUint8Array(),\n ]);\n const hash = new Uint8Array(shaObj.array());\n\n // Prepend the checksum of the hash and convert to a hex string\n const checksum = calculateCrc32(hash);\n const bytes = new Uint8Array([...checksum, ...hash]);\n return new AccountIdentifier(bytes);\n }\n\n /**\n * @returns An AccountIdentifier protobuf object.\n */\n public toProto(): AccountIdentifierPb {\n const accountIdentifier = new AccountIdentifierPb();\n accountIdentifier.setHash(this.bytes);\n return accountIdentifier;\n }\n\n public toHex(): string {\n return toHexString(this.bytes);\n }\n}\n\nexport class SubAccount {\n private constructor(private readonly bytes: Uint8Array) {}\n\n public static fromBytes(bytes: Uint8Array): SubAccount | Error {\n if (bytes.length != 32) {\n return Error(\"Subaccount length must be 32-bytes\");\n }\n\n return new SubAccount(bytes);\n }\n\n public static fromPrincipal(principal: Principal): SubAccount {\n const bytes = new Uint8Array(32).fill(0);\n\n const principalBytes = principal.toUint8Array();\n bytes[0] = principalBytes.length;\n\n for (let i = 0; i < principalBytes.length; i++) {\n bytes[1 + i] = principalBytes[i];\n }\n\n return new SubAccount(bytes);\n }\n\n public static ZERO: SubAccount = new SubAccount(new Uint8Array(32).fill(0));\n\n public toUint8Array(): Uint8Array {\n return this.bytes;\n }\n}\n\nconst asciiStringToByteArray = (text: string): Array<number> => {\n return Array.from(text).map((c) => c.charCodeAt(0));\n};\n\nconst toHexString = (bytes: Uint8Array) =>\n bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, \"0\"), \"\");\n\nconst calculateCrc32 = (bytes: Uint8Array): Uint8Array => {\n const checksumArrayBuf = new ArrayBuffer(4);\n const view = new DataView(checksumArrayBuf);\n view.setUint32(0, crc.buf(Buffer.from(bytes)), false);\n return Buffer.from(checksumArrayBuf);\n};\n"],
5
+ "mappings": "sIAAA,YAGA,GAAI,GACJ,AAAC,UAAU,EAAS,CAGnB,AAAG,MAAO,oBAAsB,YAC/B,AAAG,AAAa,MAAO,IAApB,SACF,EAAQ,GACF,AAAI,AAAe,MAAO,SAAtB,YAAgC,OAAO,IACjD,OAAO,UAAY,CAClB,GAAI,GAAS,GACb,SAAQ,GACD,IAGR,EAAQ,EAAQ,IAGjB,EAAQ,EAAQ,MAIhB,SAAS,EAAO,CAClB,EAAM,QAAU,QAEhB,YAA4B,CAG3B,OAFI,GAAI,EAAG,EAAQ,GAAI,OAAM,KAErB,EAAG,EAAG,GAAK,IAAK,EAAE,EACzB,EAAI,EACJ,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAAM,EAAE,EAAM,WAAc,IAAM,EAAO,IAAM,EAC/C,EAA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,IAAS,EAAM,EAAK,SAAS,IAAI,SAAS,EAAG,KAAM,IAElE,EAAiB,AAAC,GAAkC,CACxD,GAAM,GAAmB,GAAI,aAAY,GAEzC,MADa,IAAI,UAAS,GACrB,UAAU,EAAG,AAAI,MAAI,OAAO,KAAK,IAAS,IACxC,OAAO,KAAK",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as p}from"./chunk-NR65YN67.js";import{c as A}from"./chunk-UJYSTOZE.js";var I=A(p()),_=BigInt(1e8),n=class{constructor(t){this.e8s=t}static fromE8s(t){return new n(t)}static fromString(t){t=t.trim().replace(/[,']/g,"");let i=t.match(/\d*(\.\d*)?/);if(!i||i[0]!==t)return e.INVALID_FORMAT;let[c,r]=t.split("."),s=BigInt(0);if(c)try{s+=BigInt(c)*_}catch{return e.INVALID_FORMAT}if(r){if(r.length>8)return e.FRACTIONAL_MORE_THAN_8_DECIMALS;try{s+=BigInt(r.padEnd(8,"0"))}catch{return e.INVALID_FORMAT}}return new n(s)}toE8s(){return this.e8s}toProto(){let t=new I.ICPTs;return t.setE8s(this.e8s.toString()),t}},e=(i=>(i[i.FRACTIONAL_MORE_THAN_8_DECIMALS=0]="FRACTIONAL_MORE_THAN_8_DECIMALS",i[i.INVALID_FORMAT=1]="INVALID_FORMAT",i))(e||{});export{n as a,e as b};
2
+ //# sourceMappingURL=chunk-YXM7FYC5.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/icp.ts"],
4
+ "sourcesContent": ["import { ICPTs } from \"../proto/ledger_pb\";\n\nconst E8S_PER_ICP = BigInt(100000000);\n\nexport class ICP {\n private constructor(private e8s: bigint) {}\n\n public static fromE8s(amount: bigint): ICP {\n return new ICP(amount);\n }\n\n /**\n * Initialize from a string. Accepted formats:\n *\n * 1234567.8901\n * 1'234'567.8901\n * 1,234,567.8901\n */\n public static fromString(amount: string): ICP | FromStringError {\n // Remove all instances of \",\" and \"'\".\n amount = amount.trim().replace(/[,']/g, \"\");\n\n // Verify that the string is of the format 1234.5678\n const regexMatch = amount.match(/\\d*(\\.\\d*)?/);\n if (!regexMatch || regexMatch[0] !== amount) {\n return FromStringError.INVALID_FORMAT;\n }\n\n const [integral, fractional] = amount.split(\".\");\n\n let e8s = BigInt(0);\n\n if (integral) {\n try {\n e8s += BigInt(integral) * E8S_PER_ICP;\n } catch {\n return FromStringError.INVALID_FORMAT;\n }\n }\n\n if (fractional) {\n if (fractional.length > 8) {\n return FromStringError.FRACTIONAL_MORE_THAN_8_DECIMALS;\n }\n try {\n e8s += BigInt(fractional.padEnd(8, \"0\"));\n } catch {\n return FromStringError.INVALID_FORMAT;\n }\n }\n\n return new ICP(e8s);\n }\n\n public toE8s(): bigint {\n return this.e8s;\n }\n\n public toProto(): ICPTs {\n const proto = new ICPTs();\n proto.setE8s(this.e8s.toString());\n return proto;\n }\n}\n\nexport enum FromStringError {\n FRACTIONAL_MORE_THAN_8_DECIMALS,\n INVALID_FORMAT,\n}\n"],
5
+ "mappings": "gFAAA,MAAsB,OAEhB,EAAc,OAAO,KAEpB,OAAU,CACP,YAAoB,EAAa,CAAb,iBAEd,SAAQ,EAAqB,CACzC,MAAO,IAAI,GAAI,SAUH,YAAW,EAAuC,CAE9D,EAAS,EAAO,OAAO,QAAQ,QAAS,IAGxC,GAAM,GAAa,EAAO,MAAM,eAChC,GAAI,CAAC,GAAc,EAAW,KAAO,EACnC,MAAO,GAAgB,eAGzB,GAAM,CAAC,EAAU,GAAc,EAAO,MAAM,KAExC,EAAM,OAAO,GAEjB,GAAI,EACF,GAAI,CACF,GAAO,OAAO,GAAY,OAC1B,CACA,MAAO,GAAgB,eAI3B,GAAI,EAAY,CACd,GAAI,EAAW,OAAS,EACtB,MAAO,GAAgB,gCAEzB,GAAI,CACF,GAAO,OAAO,EAAW,OAAO,EAAG,WACnC,CACA,MAAO,GAAgB,gBAI3B,MAAO,IAAI,GAAI,GAGV,OAAgB,CACrB,MAAO,MAAK,IAGP,SAAiB,CACtB,GAAM,GAAQ,GAAI,SAClB,SAAM,OAAO,KAAK,IAAI,YACf,IAIC,EAAL,CAAK,GACV,0EACA,uCAFU",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-AAXRCEPL.js";import"./chunk-QXLTRMTU.js";import"./chunk-AV2V5I5D.js";import"./chunk-UJYSTOZE.js";export{a as GovernanceCanister};
2
+ //# sourceMappingURL=governance.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a,b}from"./chunk-YXM7FYC5.js";import"./chunk-NR65YN67.js";import"./chunk-UJYSTOZE.js";export{b as FromStringError,a as ICP};
2
+ //# sourceMappingURL=icp.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as e,b as r}from"./chunk-XN3QHASA.js";import{a as o}from"./chunk-AAXRCEPL.js";import{g as t}from"./chunk-RKZCM7KO.js";import"./chunk-QXLTRMTU.js";import"./chunk-AV2V5I5D.js";import{a as n}from"./chunk-YXM7FYC5.js";import"./chunk-NR65YN67.js";import"./chunk-UJYSTOZE.js";export{e as AccountIdentifier,o as GovernanceCanister,n as ICP,t as LedgerCanister,r as SubAccount};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a,b,c,d,e,f,g}from"./chunk-RKZCM7KO.js";import"./chunk-QXLTRMTU.js";import"./chunk-AV2V5I5D.js";import"./chunk-YXM7FYC5.js";import"./chunk-NR65YN67.js";import"./chunk-UJYSTOZE.js";export{b as BadFee,c as InsufficientFunds,a as InvalidSender,g as LedgerCanister,e as TxCreatedInFuture,f as TxDuplicate,d as TxTooOld};
2
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('./cjs/index.cjs.js');
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './esm/index.js';
@@ -0,0 +1,21 @@
1
+ import { AccountIdentifier as AccountIdentifierPb } from "../proto/ledger_pb";
2
+ import { Principal } from "@dfinity/principal";
3
+ export declare class AccountIdentifier {
4
+ private readonly bytes;
5
+ private constructor();
6
+ static fromHex(hex: string): AccountIdentifier;
7
+ static fromPrincipal(principal: Principal, subAccount?: SubAccount): AccountIdentifier;
8
+ /**
9
+ * @returns An AccountIdentifier protobuf object.
10
+ */
11
+ toProto(): AccountIdentifierPb;
12
+ toHex(): string;
13
+ }
14
+ export declare class SubAccount {
15
+ private readonly bytes;
16
+ private constructor();
17
+ static fromBytes(bytes: Uint8Array): SubAccount | Error;
18
+ static fromPrincipal(principal: Principal): SubAccount;
19
+ static ZERO: SubAccount;
20
+ toUint8Array(): Uint8Array;
21
+ }
@@ -0,0 +1,30 @@
1
+ import { Agent } from "@dfinity/agent";
2
+ import { Principal } from "@dfinity/principal";
3
+ import { GovernanceService } from "../candid/governance.idl";
4
+ declare type NeuronId = bigint;
5
+ export declare type KnownNeuron = {
6
+ id: NeuronId;
7
+ name: string;
8
+ description: string | undefined;
9
+ };
10
+ export interface GovernanceCanisterOptions {
11
+ agent?: Agent;
12
+ canisterId?: Principal;
13
+ serviceOverride?: GovernanceService;
14
+ certifiedServiceOverride?: GovernanceService;
15
+ }
16
+ export declare class GovernanceCanister {
17
+ private readonly service;
18
+ private readonly certifiedService;
19
+ private constructor();
20
+ static create(options?: GovernanceCanisterOptions): GovernanceCanister;
21
+ /**
22
+ * Returns the list of neurons who have been approved by the community to
23
+ * appear as the default followee options.
24
+ *
25
+ * If `certified` is true, the request is fetched as an update call, otherwise
26
+ * it is fetched using a query call.
27
+ */
28
+ listKnownNeurons: (certified?: boolean) => Promise<KnownNeuron[]>;
29
+ }
30
+ export {};
@@ -0,0 +1,20 @@
1
+ import { ICPTs } from "../proto/ledger_pb";
2
+ export declare class ICP {
3
+ private e8s;
4
+ private constructor();
5
+ static fromE8s(amount: bigint): ICP;
6
+ /**
7
+ * Initialize from a string. Accepted formats:
8
+ *
9
+ * 1234567.8901
10
+ * 1'234'567.8901
11
+ * 1,234,567.8901
12
+ */
13
+ static fromString(amount: string): ICP | FromStringError;
14
+ toE8s(): bigint;
15
+ toProto(): ICPTs;
16
+ }
17
+ export declare enum FromStringError {
18
+ FRACTIONAL_MORE_THAN_8_DECIMALS = 0,
19
+ INVALID_FORMAT = 1
20
+ }
@@ -0,0 +1,5 @@
1
+ export { GovernanceCanister } from "./governance";
2
+ export type { KnownNeuron } from "./governance";
3
+ export { LedgerCanister } from "./ledger";
4
+ export { AccountIdentifier, SubAccount } from "./account_identifier";
5
+ export { ICP } from "./icp";
@@ -0,0 +1,54 @@
1
+ import { Agent } from "@dfinity/agent";
2
+ import { Principal } from "@dfinity/principal";
3
+ import { AccountIdentifier } from "./account_identifier";
4
+ import { ICP } from "./icp";
5
+ declare type BlockHeight = bigint;
6
+ export declare type TransferError = InvalidSender | InsufficientFunds | TxTooOld | TxCreatedInFuture | TxDuplicate | BadFee;
7
+ export declare class InvalidSender {
8
+ }
9
+ export declare class BadFee {
10
+ }
11
+ export declare class InsufficientFunds {
12
+ readonly balance: ICP;
13
+ constructor(balance: ICP);
14
+ }
15
+ export declare class TxTooOld {
16
+ readonly allowed_window_secs: number;
17
+ constructor(allowed_window_secs: number);
18
+ }
19
+ export declare class TxCreatedInFuture {
20
+ }
21
+ export declare class TxDuplicate {
22
+ readonly duplicateOf: BlockHeight;
23
+ constructor(duplicateOf: BlockHeight);
24
+ }
25
+ declare type Fetcher = (agent: Agent, canisterId: Principal, methodName: string, arg: ArrayBuffer) => Promise<Uint8Array | Error>;
26
+ export interface LedgerCanisterOptions {
27
+ agent?: Agent;
28
+ canisterId?: Principal;
29
+ updateCallOverride?: Fetcher;
30
+ queryCallOverride?: Fetcher;
31
+ }
32
+ export declare class LedgerCanister {
33
+ private readonly agent;
34
+ private readonly canisterId;
35
+ private readonly updateFetcher;
36
+ private readonly queryFetcher;
37
+ private constructor();
38
+ static create(options?: LedgerCanisterOptions): LedgerCanister;
39
+ /**
40
+ * Returns the balance of the specified account identifier.
41
+ *
42
+ * If `certified` is true, the request is fetched as an update call, otherwise
43
+ * it is fetched using a query call.
44
+ */
45
+ accountBalance: (accountIdentifier: AccountIdentifier, certified?: boolean) => Promise<ICP>;
46
+ /**
47
+ * Transfer ICP from the caller to the destination `accountIdentifier`.
48
+ * Returns the index of the block containing the tx if it was successful.
49
+ *
50
+ * TODO: support remaining options (subaccounts, memos, etc.)
51
+ */
52
+ transfer: (to: AccountIdentifier, amount: ICP, memo?: bigint | undefined) => Promise<BlockHeight | TransferError>;
53
+ }
54
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Agent } from "@dfinity/agent";
2
+ import { Principal } from "@dfinity/principal";
3
+ /**
4
+ * Submits an update call to the IC.
5
+ * @returns The (binary) response if the request succeeded, an error otherwise.
6
+ */
7
+ export declare const updateCall: (agent: Agent, canisterId: Principal, methodName: string, arg: ArrayBuffer) => Promise<Uint8Array | Error>;
8
+ /**
9
+ * Submits a query call to the IC.
10
+ * @returns The (binary) response if the request succeeded, an error otherwise.
11
+ */
12
+ export declare const queryCall: (agent: Agent, canisterId: Principal, methodName: string, arg: ArrayBuffer) => Promise<Uint8Array | Error>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/nns",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A library for interfacing with the Internet Computer's Network Nervous System.",
5
5
  "main": "dist/cjs/index.cjs.js",
6
6
  "module": "dist/esm/index.js",