@dfinity/nns 0.1.6 → 0.1.7

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 (55) 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 -12
  31. package/dist/{account_identifier.d.ts → types/account_identifier.d.ts} +0 -0
  32. package/dist/{governance.d.ts → types/governance.d.ts} +0 -0
  33. package/dist/{icp.d.ts → types/icp.d.ts} +0 -0
  34. package/dist/{index.d.ts → types/index.d.ts} +1 -1
  35. package/dist/{ledger.d.ts → types/ledger.d.ts} +0 -0
  36. package/dist/{utils → types/utils}/proto.d.ts +0 -0
  37. package/package.json +37 -28
  38. package/candid/governance.certified.did +0 -12
  39. package/candid/governance.certified.idl.d.ts +0 -2
  40. package/candid/governance.certified.idl.js +0 -18
  41. package/candid/governance.did +0 -10
  42. package/candid/governance.idl.d.ts +0 -5
  43. package/candid/governance.idl.js +0 -18
  44. package/candid/governanceTypes.d.ts +0 -16
  45. package/dist/account_identifier.js +0 -95
  46. package/dist/governance.js +0 -55
  47. package/dist/icp.js +0 -65
  48. package/dist/ledger.js +0 -131
  49. package/dist/utils/proto.js +0 -59
  50. package/proto/base_types.proto +0 -60
  51. package/proto/base_types_pb.d.ts +0 -144
  52. package/proto/base_types_pb.js +0 -1142
  53. package/proto/ledger.proto +0 -277
  54. package/proto/ledger_pb.d.ts +0 -911
  55. package/proto/ledger_pb.js +0 -7151
@@ -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,cAC/C,KAAK;AAAA,IAIX,GAAI,CACF,GAAM,GAAO,KAAM,GAAQ,gBACzB,EACA,EACA,EAAe,UACf,EAAQ,mBAEV,MAAO,IAAI,YAAW,SACf,EAAP,CACA,GAAI,YAAe,OAEjB,MAAO,GAIT,KAAM,KAQG,EAAY,MACvB,EACA,EACA,EACA,IACgC,CAChC,GAAM,GAAgB,KAAM,GAAM,MAAM,EAAY,CAClD,aACA,QAGF,MAAI,GAAc,QAAU,WACnB,GAAI,OACT,CACE,eACA,aAAa,IACb,kBAAkB,IAClB,uBAAuB,EAAc,cACrC,uBAAuB,EAAc,kBACrC,KAAK;AAAA,IAIJ,GAAI,YAAW,EAAc,MAAM,MDjE5C,GAAM,GAA6B,EAAU,SAC3C,+BAaK,OAAoB,GACpB,OAAa,GACb,OAAwB,CAC7B,YAA4B,EAAc,CAAd,iBAEvB,OAAe,CACpB,YAA4B,EAA6B,CAA7B,6BAEvB,OAAwB,GACxB,OAAkB,CACvB,YAA4B,EAA0B,CAA1B,qBAwBvB,OAAqB,CAClB,YACW,EACA,EACA,EACA,EACjB,CAJiB,aACA,kB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BACtC,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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d,YAA6B,EAAmB,CAAnB,mBAEvB,WAAU,EAAuC,CAC7D,MAAI,GAAM,QAAU,GACX,MAAM,sCAGR,GAAI,GAAW,SAGV,eAAc,EAAkC,CAC5D,GAAM,GAAQ,GAAI,YAAW,IAAI,KAAK,GAEhC,EAAiB,EAAU,eACjC,EAAM,GAAK,EAAe,OAE1B,OAAS,GAAI,EAAG,EAAI,EAAe,OAAQ,IACzC,EAAM,EAAI,GAAK,EAAe,GAGhC,MAAO,IAAI,GAAW,GAKjB,cAA2B,CAChC,MAAO,MAAK,QA3BT,IAwBS,EAxBT,EAwBS,OAAmB,GAAI,GAAW,GAAI,YAAW,IAAI,KAAK,KAO1E,GAAM,GAAyB,AAAC,GACvB,MAAM,KAAK,GAAM,IAAI,AAAC,GAAM,EAAE,WAAW,IAG5C,EAAc,AAAC,GACnB,EAAM,OAAO,CAAC,EAAK,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 r,b as e}from"./chunk-XN3QHASA.js";import{a as o}from"./chunk-AAXRCEPL.js";import{g as n}from"./chunk-RKZCM7KO.js";import"./chunk-QXLTRMTU.js";import"./chunk-AV2V5I5D.js";import{a as t}from"./chunk-YXM7FYC5.js";import"./chunk-NR65YN67.js";import"./chunk-UJYSTOZE.js";export{r as AccountIdentifier,o as GovernanceCanister,t as ICP,n as LedgerCanister,e 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 CHANGED
@@ -1,12 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ICP = exports.SubAccount = exports.AccountIdentifier = exports.LedgerCanister = exports.GovernanceCanister = void 0;
4
- var governance_1 = require("./governance");
5
- Object.defineProperty(exports, "GovernanceCanister", { enumerable: true, get: function () { return governance_1.GovernanceCanister; } });
6
- var ledger_1 = require("./ledger");
7
- Object.defineProperty(exports, "LedgerCanister", { enumerable: true, get: function () { return ledger_1.LedgerCanister; } });
8
- var account_identifier_1 = require("./account_identifier");
9
- Object.defineProperty(exports, "AccountIdentifier", { enumerable: true, get: function () { return account_identifier_1.AccountIdentifier; } });
10
- Object.defineProperty(exports, "SubAccount", { enumerable: true, get: function () { return account_identifier_1.SubAccount; } });
11
- var icp_1 = require("./icp");
12
- Object.defineProperty(exports, "ICP", { enumerable: true, get: function () { return icp_1.ICP; } });
1
+ export * from './esm/index.js';
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- export { GovernanceCanister, KnownNeuron } from "./governance";
1
+ export { GovernanceCanister } from "./governance";
2
2
  export { LedgerCanister } from "./ledger";
3
3
  export { AccountIdentifier, SubAccount } from "./account_identifier";
4
4
  export { ICP } from "./icp";
File without changes
File without changes
package/package.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
2
  "name": "@dfinity/nns",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A library for interfacing with the Internet Computer's Network Nervous System.",
5
- "keywords": [
6
- "internet computer",
7
- "internet-computer",
8
- "ic",
9
- "dfinity",
10
- "dfx",
11
- "canister",
12
- "candid",
13
- "motoko",
14
- "javascript",
15
- "typescript",
16
- "blockchain",
17
- "crypto",
18
- "nns",
19
- "network nervous system",
20
- "network-nervous-system"
5
+ "main": "dist/cjs/index.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
21
11
  ],
22
- "main": "dist/index.js",
23
12
  "scripts": {
24
- "build": "tsc",
13
+ "rmdir": "node ./scripts/rmdir.mjs",
14
+ "ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
15
+ "build": "npm run rmdir && node esbuild.mjs && npm run ts-declaration",
25
16
  "test": "jest",
26
17
  "doc": "typedoc ./src/index.ts",
27
18
  "lint": "eslint --max-warnings 0 .",
28
19
  "format": "prettier --write .",
29
20
  "update_proto": "bash ./scripts/update_proto.sh"
30
21
  },
22
+ "dependencies": {
23
+ "@dfinity/agent": "^0.10.2",
24
+ "@dfinity/candid": "^0.10.2",
25
+ "@dfinity/principal": "^0.10.2",
26
+ "crc-32": "^1.2.0",
27
+ "google-protobuf": "^3.19.1",
28
+ "js-sha256": "^0.9.0"
29
+ },
31
30
  "devDependencies": {
32
31
  "@babel/preset-env": "^7.16.11",
33
32
  "@types/google-protobuf": "^3.15.5",
@@ -36,6 +35,7 @@
36
35
  "@typescript-eslint/eslint-plugin": "^5.4.0",
37
36
  "babel-jest": "^27.4.6",
38
37
  "babelify": "^10.0.0",
38
+ "esbuild": "^0.14.14",
39
39
  "eslint": "^7.29.0",
40
40
  "eslint-config-standard": "^16.0.3",
41
41
  "eslint-plugin-import": "^2.23.4",
@@ -51,19 +51,28 @@
51
51
  "typescript": "^4.5.2",
52
52
  "whatwg-fetch": "^3.6.2"
53
53
  },
54
- "dependencies": {
55
- "@dfinity/agent": "^0.10.2",
56
- "@dfinity/candid": "^0.10.2",
57
- "@dfinity/principal": "^0.10.2",
58
- "crc-32": "^1.2.0",
59
- "google-protobuf": "^3.19.1",
60
- "js-sha256": "^0.9.0"
61
- },
62
54
  "browserify": {
63
55
  "transform": [
64
56
  [
65
57
  "babelify"
66
58
  ]
67
59
  ]
68
- }
60
+ },
61
+ "keywords": [
62
+ "internet computer",
63
+ "internet-computer",
64
+ "ic",
65
+ "dfinity",
66
+ "dfx",
67
+ "canister",
68
+ "candid",
69
+ "motoko",
70
+ "javascript",
71
+ "typescript",
72
+ "blockchain",
73
+ "crypto",
74
+ "nns",
75
+ "network nervous system",
76
+ "network-nervous-system"
77
+ ]
69
78
  }
@@ -1,12 +0,0 @@
1
- # The candid to interact with the governance canister using update calls in place of queries for additional security.
2
-
3
- type KnownNeuron = record {
4
- id : opt NeuronId;
5
- known_neuron_data : opt KnownNeuronData;
6
- };
7
- type KnownNeuronData = record { name : text; description : opt text };
8
- type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
9
- type NeuronId = record { id : nat64 };
10
- service : {
11
- list_known_neurons : () -> (ListKnownNeuronsResponse);
12
- }
@@ -1,2 +0,0 @@
1
- import type { IDL } from "@dfinity/candid";
2
- export const idlFactory: IDL.InterfaceFactory;
@@ -1,18 +0,0 @@
1
- export const idlFactory = ({ IDL }) => {
2
- const NeuronId = IDL.Record({ 'id' : IDL.Nat64 });
3
- const KnownNeuronData = IDL.Record({
4
- 'name' : IDL.Text,
5
- 'description' : IDL.Opt(IDL.Text),
6
- });
7
- const KnownNeuron = IDL.Record({
8
- 'id' : IDL.Opt(NeuronId),
9
- 'known_neuron_data' : IDL.Opt(KnownNeuronData),
10
- });
11
- const ListKnownNeuronsResponse = IDL.Record({
12
- 'known_neurons' : IDL.Vec(KnownNeuron),
13
- });
14
- return IDL.Service({
15
- 'list_known_neurons' : IDL.Func([], [ListKnownNeuronsResponse], []),
16
- });
17
- };
18
- export const init = ({ IDL }) => { return []; };
@@ -1,10 +0,0 @@
1
- type KnownNeuron = record {
2
- id : opt NeuronId;
3
- known_neuron_data : opt KnownNeuronData;
4
- };
5
- type KnownNeuronData = record { name : text; description : opt text };
6
- type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
7
- type NeuronId = record { id : nat64 };
8
- service : {
9
- list_known_neurons : () -> (ListKnownNeuronsResponse) query;
10
- }
@@ -1,5 +0,0 @@
1
- import type { IDL } from "@dfinity/candid";
2
- export const idlFactory: IDL.InterfaceFactory;
3
-
4
- import { _SERVICE } from "./governanceTypes";
5
- export { _SERVICE as GovernanceService };
@@ -1,18 +0,0 @@
1
- export const idlFactory = ({ IDL }) => {
2
- const NeuronId = IDL.Record({ 'id' : IDL.Nat64 });
3
- const KnownNeuronData = IDL.Record({
4
- 'name' : IDL.Text,
5
- 'description' : IDL.Opt(IDL.Text),
6
- });
7
- const KnownNeuron = IDL.Record({
8
- 'id' : IDL.Opt(NeuronId),
9
- 'known_neuron_data' : IDL.Opt(KnownNeuronData),
10
- });
11
- const ListKnownNeuronsResponse = IDL.Record({
12
- 'known_neurons' : IDL.Vec(KnownNeuron),
13
- });
14
- return IDL.Service({
15
- 'list_known_neurons' : IDL.Func([], [ListKnownNeuronsResponse], ['query']),
16
- });
17
- };
18
- export const init = ({ IDL }) => { return []; };
@@ -1,16 +0,0 @@
1
- import type { Principal } from '@dfinity/principal';
2
- export interface KnownNeuron {
3
- 'id' : [] | [NeuronId],
4
- 'known_neuron_data' : [] | [KnownNeuronData],
5
- }
6
- export interface KnownNeuronData {
7
- 'name' : string,
8
- 'description' : [] | [string],
9
- }
10
- export interface ListKnownNeuronsResponse {
11
- 'known_neurons' : Array<KnownNeuron>,
12
- }
13
- export interface NeuronId { 'id' : bigint }
14
- export interface _SERVICE {
15
- 'list_known_neurons' : () => Promise<ListKnownNeuronsResponse>,
16
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.SubAccount = exports.AccountIdentifier = void 0;
23
- const ledger_pb_1 = require("../proto/ledger_pb");
24
- const js_sha256_1 = require("js-sha256");
25
- const crc = __importStar(require("crc-32"));
26
- class AccountIdentifier {
27
- constructor(bytes) {
28
- this.bytes = bytes;
29
- }
30
- static fromHex(hex) {
31
- return new AccountIdentifier(Uint8Array.from(Buffer.from(hex, "hex")));
32
- }
33
- static fromPrincipal(principal, subAccount = SubAccount.ZERO) {
34
- // Hash (sha224) the principal, the subAccount and some padding
35
- const padding = asciiStringToByteArray("\x0Aaccount-id");
36
- const shaObj = js_sha256_1.sha224.create();
37
- shaObj.update([
38
- ...padding,
39
- ...principal.toUint8Array(),
40
- ...subAccount.toUint8Array(),
41
- ]);
42
- const hash = new Uint8Array(shaObj.array());
43
- // Prepend the checksum of the hash and convert to a hex string
44
- const checksum = calculateCrc32(hash);
45
- const bytes = new Uint8Array([...checksum, ...hash]);
46
- return new AccountIdentifier(bytes);
47
- }
48
- /**
49
- * @returns An AccountIdentifier protobuf object.
50
- */
51
- toProto() {
52
- const accountIdentifier = new ledger_pb_1.AccountIdentifier();
53
- accountIdentifier.setHash(this.bytes);
54
- return accountIdentifier;
55
- }
56
- toHex() {
57
- return toHexString(this.bytes);
58
- }
59
- }
60
- exports.AccountIdentifier = AccountIdentifier;
61
- class SubAccount {
62
- constructor(bytes) {
63
- this.bytes = bytes;
64
- }
65
- static fromBytes(bytes) {
66
- if (bytes.length != 32) {
67
- return Error("Subaccount length must be 32-bytes");
68
- }
69
- return new SubAccount(bytes);
70
- }
71
- static fromPrincipal(principal) {
72
- const bytes = new Uint8Array(32).fill(0);
73
- const principalBytes = principal.toUint8Array();
74
- bytes[0] = principalBytes.length;
75
- for (let i = 0; i < principalBytes.length; i++) {
76
- bytes[1 + i] = principalBytes[i];
77
- }
78
- return new SubAccount(bytes);
79
- }
80
- toUint8Array() {
81
- return this.bytes;
82
- }
83
- }
84
- exports.SubAccount = SubAccount;
85
- SubAccount.ZERO = new SubAccount(new Uint8Array(32).fill(0));
86
- const asciiStringToByteArray = (text) => {
87
- return Array.from(text).map((c) => c.charCodeAt(0));
88
- };
89
- const toHexString = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
90
- const calculateCrc32 = (bytes) => {
91
- const checksumArrayBuf = new ArrayBuffer(4);
92
- const view = new DataView(checksumArrayBuf);
93
- view.setUint32(0, crc.buf(Buffer.from(bytes)), false);
94
- return Buffer.from(checksumArrayBuf);
95
- };
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GovernanceCanister = void 0;
4
- const agent_1 = require("@dfinity/agent");
5
- const principal_1 = require("@dfinity/principal");
6
- const governance_idl_1 = require("../candid/governance.idl");
7
- const governance_certified_idl_1 = require("../candid/governance.certified.idl");
8
- const MAINNET_GOVERNANCE_CANISTER_ID = principal_1.Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai");
9
- class GovernanceCanister {
10
- constructor(service, certifiedService) {
11
- this.service = service;
12
- this.certifiedService = certifiedService;
13
- /**
14
- * Returns the list of neurons who have been approved by the community to
15
- * appear as the default followee options.
16
- *
17
- * If `certified` is true, the request is fetched as an update call, otherwise
18
- * it is fetched using a query call.
19
- */
20
- this.listKnownNeurons = async (certified = true) => {
21
- const service = certified ? this.certifiedService : this.service;
22
- const response = await service.list_known_neurons();
23
- return response.known_neurons.map(n => ({
24
- id: n.id[0]?.id ?? BigInt(0),
25
- name: n.known_neuron_data[0]?.name ?? "",
26
- description: n.known_neuron_data[0]?.description[0]
27
- }));
28
- };
29
- }
30
- static create(options = {}) {
31
- const agent = options.agent ?? defaultAgent();
32
- const canisterId = options.canisterId ?? MAINNET_GOVERNANCE_CANISTER_ID;
33
- const service = options.serviceOverride ??
34
- agent_1.Actor.createActor(governance_idl_1.idlFactory, {
35
- agent,
36
- canisterId,
37
- });
38
- const certifiedService = options.certifiedServiceOverride ??
39
- agent_1.Actor.createActor(governance_certified_idl_1.idlFactory, {
40
- agent,
41
- canisterId,
42
- });
43
- return new GovernanceCanister(service, certifiedService);
44
- }
45
- }
46
- exports.GovernanceCanister = GovernanceCanister;
47
- /**
48
- * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.
49
- */
50
- function defaultAgent() {
51
- return new agent_1.HttpAgent({
52
- host: "https://ic0.app",
53
- identity: new agent_1.AnonymousIdentity(),
54
- });
55
- }
package/dist/icp.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FromStringError = exports.ICP = void 0;
4
- const ledger_pb_1 = require("../proto/ledger_pb");
5
- const E8S_PER_ICP = BigInt(100000000);
6
- class ICP {
7
- constructor(e8s) {
8
- this.e8s = e8s;
9
- }
10
- static fromE8s(amount) {
11
- return new ICP(amount);
12
- }
13
- /**
14
- * Initialize from a string. Accepted formats:
15
- *
16
- * 1234567.8901
17
- * 1'234'567.8901
18
- * 1,234,567.8901
19
- */
20
- static fromString(amount) {
21
- // Remove all instances of "," and "'".
22
- amount = amount.trim().replace(/[,']/g, "");
23
- // Verify that the string is of the format 1234.5678
24
- const regexMatch = amount.match(/\d*(\.\d*)?/);
25
- if (!regexMatch || regexMatch[0] !== amount) {
26
- return FromStringError.INVALID_FORMAT;
27
- }
28
- const [integral, fractional] = amount.split(".");
29
- let e8s = BigInt(0);
30
- if (integral) {
31
- try {
32
- e8s += BigInt(integral) * E8S_PER_ICP;
33
- }
34
- catch {
35
- return FromStringError.INVALID_FORMAT;
36
- }
37
- }
38
- if (fractional) {
39
- if (fractional.length > 8) {
40
- return FromStringError.FRACTIONAL_MORE_THAN_8_DECIMALS;
41
- }
42
- try {
43
- e8s += BigInt(fractional.padEnd(8, "0"));
44
- }
45
- catch {
46
- return FromStringError.INVALID_FORMAT;
47
- }
48
- }
49
- return new ICP(e8s);
50
- }
51
- toE8s() {
52
- return this.e8s;
53
- }
54
- toProto() {
55
- const proto = new ledger_pb_1.ICPTs();
56
- proto.setE8s(this.e8s.toString());
57
- return proto;
58
- }
59
- }
60
- exports.ICP = ICP;
61
- var FromStringError;
62
- (function (FromStringError) {
63
- FromStringError[FromStringError["FRACTIONAL_MORE_THAN_8_DECIMALS"] = 0] = "FRACTIONAL_MORE_THAN_8_DECIMALS";
64
- FromStringError[FromStringError["INVALID_FORMAT"] = 1] = "INVALID_FORMAT";
65
- })(FromStringError = exports.FromStringError || (exports.FromStringError = {}));