@dfinity/utils 0.0.2 → 0.0.3-next-2022-09-23

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/README.md CHANGED
@@ -33,6 +33,11 @@ npm i @dfinity/agent @dfinity/candid @dfinity/principal
33
33
 
34
34
  - [defaultAgent](#gear-defaultagent)
35
35
  - [createServices](#gear-createservices)
36
+ - [uint8ArrayToBigInt](#gear-uint8arraytobigint)
37
+ - [arrayBufferToUint8Array](#gear-arraybuffertouint8array)
38
+ - [uint8ArrayToArrayOfNumber](#gear-uint8arraytoarrayofnumber)
39
+ - [arrayOfNumberToUint8Array](#gear-arrayofnumbertouint8array)
40
+ - [asciiStringToByteArray](#gear-asciistringtobytearray)
36
41
  - [assertNonNullish](#gear-assertnonnullish)
37
42
  - [toNullable](#gear-tonullable)
38
43
  - [fromNullable](#gear-fromnullable)
@@ -50,6 +55,36 @@ npm i @dfinity/agent @dfinity/candid @dfinity/principal
50
55
  | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51
56
  | `createServices` | `<T>({ options: { canisterId, serviceOverride, certifiedServiceOverride, agent: agentOption, }, idlFactory, certifiedIdlFactory, }: { options: RequiredCanisterOptions<T>; idlFactory: InterfaceFactory; certifiedIdlFactory: InterfaceFactory; }) => { ...; }` |
52
57
 
58
+ #### :gear: uint8ArrayToBigInt
59
+
60
+ | Function | Type |
61
+ | -------------------- | ------------------------------- |
62
+ | `uint8ArrayToBigInt` | `(array: Uint8Array) => bigint` |
63
+
64
+ #### :gear: arrayBufferToUint8Array
65
+
66
+ | Function | Type |
67
+ | ------------------------- | ------------------------------------- |
68
+ | `arrayBufferToUint8Array` | `(buffer: ArrayBuffer) => Uint8Array` |
69
+
70
+ #### :gear: uint8ArrayToArrayOfNumber
71
+
72
+ | Function | Type |
73
+ | --------------------------- | --------------------------------- |
74
+ | `uint8ArrayToArrayOfNumber` | `(array: Uint8Array) => number[]` |
75
+
76
+ #### :gear: arrayOfNumberToUint8Array
77
+
78
+ | Function | Type |
79
+ | --------------------------- | ----------------------------------- |
80
+ | `arrayOfNumberToUint8Array` | `(numbers: number[]) => Uint8Array` |
81
+
82
+ #### :gear: asciiStringToByteArray
83
+
84
+ | Function | Type |
85
+ | ------------------------ | ---------------------------- |
86
+ | `asciiStringToByteArray` | `(text: string) => number[]` |
87
+
53
88
  #### :gear: assertNonNullish
54
89
 
55
90
  | Function | Type |
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!g.call(t,r)&&r!==o&&p(t,r,{get:()=>e[r],enumerable:!(n=y(e,r))||n.enumerable});return t};var I=t=>b(p({},"__esModule",{value:!0}),t);var C={};x(C,{NullishError:()=>s,assertNonNullish:()=>m,createServices:()=>N,defaultAgent:()=>a,fromDefinedNullable:()=>O,fromNullable:()=>d,toNullable:()=>S});module.exports=I(C);var f=require("@dfinity/agent");var i=require("@dfinity/agent"),a=()=>new i.HttpAgent({host:"https://ic0.app",identity:new i.AnonymousIdentity});var N=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:o,agent:n},idlFactory:r,certifiedIdlFactory:l})=>{let c=n??a(),T=e??f.Actor.createActor(r,{agent:c,canisterId:t}),u=o??f.Actor.createActor(l,{agent:c,canisterId:t});return{service:T,certifiedService:u,agent:c,canisterId:t}};var s=class extends Error{},m=(t,e)=>{if(t==null)throw new s(e)};var S=t=>t?[t]:[],d=t=>t==null?void 0:t[0],O=t=>{let e=d(t);return m(e),e};0&&(module.exports={NullishError,assertNonNullish,createServices,defaultAgent,fromDefinedNullable,fromNullable,toNullable});
1
+ "use strict";var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var e in r)c(t,e,{get:r[e],enumerable:!0})},b=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of l(r))!d.call(t,n)&&n!==e&&c(t,n,{get:()=>r[n],enumerable:!(o=T(r,n))||o.enumerable});return t};var I=t=>b(c({},"__esModule",{value:!0}),t);var D={};x(D,{NullishError:()=>s,arrayBufferToUint8Array:()=>N,arrayOfNumberToUint8Array:()=>B,asciiStringToByteArray:()=>S,assertNonNullish:()=>y,createServices:()=>U,defaultAgent:()=>p,fromDefinedNullable:()=>C,fromNullable:()=>m,toNullable:()=>h,uint8ArrayToArrayOfNumber:()=>O,uint8ArrayToBigInt:()=>w});module.exports=I(D);var f=require("@dfinity/agent");var i=require("@dfinity/agent"),p=()=>new i.HttpAgent({host:"https://ic0.app",identity:new i.AnonymousIdentity});var U=({options:{canisterId:t,serviceOverride:r,certifiedServiceOverride:e,agent:o},idlFactory:n,certifiedIdlFactory:A})=>{let a=o??p(),u=r??f.Actor.createActor(n,{agent:a,canisterId:t}),g=e??f.Actor.createActor(A,{agent:a,canisterId:t});return{service:u,certifiedService:g,agent:a,canisterId:t}};var w=t=>{let r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(typeof r.getBigUint64=="function")return r.getBigUint64(0);{let e=BigInt(r.getUint32(0)),o=BigInt(r.getUint32(4));return(e<<BigInt(32))+o}},N=t=>new Uint8Array(t),O=t=>Array.from(t),B=t=>new Uint8Array(t),S=t=>Array.from(t).map(r=>r.charCodeAt(0));var s=class extends Error{},y=(t,r)=>{if(t==null)throw new s(r)};var h=t=>t?[t]:[],m=t=>t==null?void 0:t[0],C=t=>{let r=m(t);return y(r),r};0&&(module.exports={NullishError,arrayBufferToUint8Array,arrayOfNumberToUint8Array,asciiStringToByteArray,assertNonNullish,createServices,defaultAgent,fromDefinedNullable,fromNullable,toNullable,uint8ArrayToArrayOfNumber,uint8ArrayToBigInt});
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts", "../../src/utils/actor.utils.ts", "../../src/utils/agent.utils.ts", "../../src/utils/asserts.utils.ts", "../../src/utils/did.utils.ts"],
4
- "sourcesContent": ["export type { CanisterOptions } from \"./types/canister.options\";\nexport * from \"./utils/actor.utils\";\nexport * from \"./utils/agent.utils\";\nexport * from \"./utils/asserts.utils\";\nexport * from \"./utils/did.utils\";\n", "import type { ActorSubclass, Agent } from \"@dfinity/agent\";\nimport { Actor } from \"@dfinity/agent\";\nimport type { IDL } from \"@dfinity/candid\";\nimport type { Principal } from \"@dfinity/principal\";\nimport type { CanisterOptions } from \"../types/canister.options\";\nimport { defaultAgent } from \"./agent.utils\";\n\ntype RequiredCanisterOptions<T> = Required<\n Pick<CanisterOptions<T>, \"canisterId\">\n> &\n Omit<CanisterOptions<T>, \"canisterId\">;\n\nexport const createServices = <T>({\n options: {\n canisterId,\n serviceOverride,\n certifiedServiceOverride,\n agent: agentOption,\n },\n idlFactory,\n certifiedIdlFactory,\n}: {\n options: RequiredCanisterOptions<T>;\n idlFactory: IDL.InterfaceFactory;\n certifiedIdlFactory: IDL.InterfaceFactory;\n}): {\n service: ActorSubclass<T>;\n certifiedService: ActorSubclass<T>;\n agent: Agent;\n canisterId: Principal;\n} => {\n const agent: Agent = agentOption ?? defaultAgent();\n\n const service: ActorSubclass<T> =\n serviceOverride ??\n Actor.createActor<T>(idlFactory, {\n agent,\n canisterId,\n });\n\n const certifiedService: ActorSubclass<T> =\n certifiedServiceOverride ??\n Actor.createActor<T>(certifiedIdlFactory, {\n agent,\n canisterId,\n });\n\n return { service, certifiedService, agent, canisterId };\n};\n", "import type { Agent } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n", "export class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(\n value: T,\n message?: string\n): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n", "import { assertNonNullish } from \"./asserts.utils\";\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return value ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const fromDefinedNullable = <T>(value: [] | [T]): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n"],
5
- "mappings": "yaAAA,oLCCA,MAAsB,0BCAtB,MAA6C,0BAKhC,EAAe,IAC1B,GAAI,aAAU,CACZ,KAAM,kBACN,SAAU,GAAI,oBAChB,CAAC,EDEI,GAAM,GAAiB,CAAI,CAChC,QAAS,CACP,aACA,kBACA,2BACA,MAAO,GAET,aACA,yBAUG,CACH,GAAM,GAAe,GAAe,EAAa,EAE3C,EACJ,GACA,QAAM,YAAe,EAAY,CAC/B,QACA,YACF,CAAC,EAEG,EACJ,GACA,QAAM,YAAe,EAAqB,CACxC,QACA,YACF,CAAC,EAEH,MAAO,CAAE,UAAS,mBAAkB,QAAO,YAAW,CACxD,EEhDO,GAAM,GAAN,aAA2B,MAAM,CAAC,EAE5B,EAG0B,CACrC,EACA,IACS,CACT,GAAI,GAAU,KACZ,KAAM,IAAI,GAAa,CAAO,CAElC,ECVO,GAAM,GAAa,AAAI,GACrB,EAAQ,CAAC,CAAK,EAAI,CAAC,EAGf,EAAe,AAAI,GACvB,iBAAQ,GAGJ,EAAsB,AAAI,GAAuB,CAC5D,GAAM,GAAS,EAAa,CAAK,EAEjC,SAAiB,CAAM,EAEhB,CACT",
3
+ "sources": ["../../src/index.ts", "../../src/utils/actor.utils.ts", "../../src/utils/agent.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/asserts.utils.ts", "../../src/utils/did.utils.ts"],
4
+ "sourcesContent": ["export type { CanisterOptions } from \"./types/canister.options\";\nexport * from \"./utils/actor.utils\";\nexport * from \"./utils/agent.utils\";\nexport * from \"./utils/arrays.utils\";\nexport * from \"./utils/asserts.utils\";\nexport * from \"./utils/did.utils\";\n", "import type { ActorSubclass, Agent } from \"@dfinity/agent\";\nimport { Actor } from \"@dfinity/agent\";\nimport type { IDL } from \"@dfinity/candid\";\nimport type { Principal } from \"@dfinity/principal\";\nimport type { CanisterOptions } from \"../types/canister.options\";\nimport { defaultAgent } from \"./agent.utils\";\n\ntype RequiredCanisterOptions<T> = Required<\n Pick<CanisterOptions<T>, \"canisterId\">\n> &\n Omit<CanisterOptions<T>, \"canisterId\">;\n\nexport const createServices = <T>({\n options: {\n canisterId,\n serviceOverride,\n certifiedServiceOverride,\n agent: agentOption,\n },\n idlFactory,\n certifiedIdlFactory,\n}: {\n options: RequiredCanisterOptions<T>;\n idlFactory: IDL.InterfaceFactory;\n certifiedIdlFactory: IDL.InterfaceFactory;\n}): {\n service: ActorSubclass<T>;\n certifiedService: ActorSubclass<T>;\n agent: Agent;\n canisterId: Principal;\n} => {\n const agent: Agent = agentOption ?? defaultAgent();\n\n const service: ActorSubclass<T> =\n serviceOverride ??\n Actor.createActor<T>(idlFactory, {\n agent,\n canisterId,\n });\n\n const certifiedService: ActorSubclass<T> =\n certifiedServiceOverride ??\n Actor.createActor<T>(certifiedIdlFactory, {\n agent,\n canisterId,\n });\n\n return { service, certifiedService, agent, canisterId };\n};\n", "import type { Agent } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n", "export const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === \"function\") {\n return view.getBigUint64(0);\n } else {\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n }\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array =>\n new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> =>\n Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n", "export class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(\n value: T,\n message?: string\n): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n", "import { assertNonNullish } from \"./asserts.utils\";\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return value ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const fromDefinedNullable = <T>(value: [] | [T]): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n"],
5
+ "mappings": "yaAAA,wUCCA,MAAsB,0BCAtB,MAA6C,0BAKhC,EAAe,IAC1B,GAAI,aAAU,CACZ,KAAM,kBACN,SAAU,GAAI,oBAChB,CAAC,EDEI,GAAM,GAAiB,CAAI,CAChC,QAAS,CACP,aACA,kBACA,2BACA,MAAO,GAET,aACA,yBAUG,CACH,GAAM,GAAe,GAAe,EAAa,EAE3C,EACJ,GACA,QAAM,YAAe,EAAY,CAC/B,QACA,YACF,CAAC,EAEG,EACJ,GACA,QAAM,YAAe,EAAqB,CACxC,QACA,YACF,CAAC,EAEH,MAAO,CAAE,UAAS,mBAAkB,QAAO,YAAW,CACxD,EEhDO,GAAM,GAAqB,AAAC,GAA8B,CAC/D,GAAM,GAAO,GAAI,UAAS,EAAM,OAAQ,EAAM,WAAY,EAAM,UAAU,EAC1E,GAAI,MAAO,GAAK,cAAiB,WAC/B,MAAO,GAAK,aAAa,CAAC,EACrB,CACL,GAAM,GAAO,OAAO,EAAK,UAAU,CAAC,CAAC,EAC/B,EAAM,OAAO,EAAK,UAAU,CAAC,CAAC,EAEpC,MAAQ,IAAQ,OAAO,EAAE,GAAK,CAChC,CACF,EAEa,EAA0B,AAAC,GACtC,GAAI,YAAW,CAAM,EAEV,EAA4B,AAAC,GACxC,MAAM,KAAK,CAAK,EAEL,EAA4B,AAAC,GACxC,GAAI,YAAW,CAAO,EAEX,EAAyB,AAAC,GACrC,MAAM,KAAK,CAAI,EAAE,IAAI,AAAC,GAAM,EAAE,WAAW,CAAC,CAAC,ECtBtC,GAAM,GAAN,aAA2B,MAAM,CAAC,EAE5B,EAG0B,CACrC,EACA,IACS,CACT,GAAI,GAAU,KACZ,KAAM,IAAI,GAAa,CAAO,CAElC,ECVO,GAAM,GAAa,AAAI,GACrB,EAAQ,CAAC,CAAK,EAAI,CAAC,EAGf,EAAe,AAAI,GACvB,iBAAQ,GAGJ,EAAsB,AAAI,GAAuB,CAC5D,GAAM,GAAS,EAAa,CAAK,EAEjC,SAAiB,CAAM,EAEhB,CACT",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Actor as i}from"@dfinity/agent";import{AnonymousIdentity as d,HttpAgent as T}from"@dfinity/agent";var n=()=>new T({host:"https://ic0.app",identity:new d});var b=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:c,agent:p},idlFactory:a,certifiedIdlFactory:f})=>{let r=p??n(),l=e??i.createActor(a,{agent:r,canisterId:t}),m=c??i.createActor(f,{agent:r,canisterId:t});return{service:l,certifiedService:m,agent:r,canisterId:t}};var o=class extends Error{},s=(t,e)=>{if(t==null)throw new o(e)};var O=t=>t?[t]:[],u=t=>t?.[0],v=t=>{let e=u(t);return s(e),e};export{o as NullishError,s as assertNonNullish,b as createServices,n as defaultAgent,v as fromDefinedNullable,u as fromNullable,O as toNullable};
1
+ import{Actor as a}from"@dfinity/agent";import{AnonymousIdentity as u,HttpAgent as A}from"@dfinity/agent";var s=()=>new A({host:"https://ic0.app",identity:new u});var b=({options:{canisterId:t,serviceOverride:r,certifiedServiceOverride:e,agent:n},idlFactory:p,certifiedIdlFactory:f})=>{let o=n??s(),y=r??a.createActor(p,{agent:o,canisterId:t}),m=e??a.createActor(f,{agent:o,canisterId:t});return{service:y,certifiedService:m,agent:o,canisterId:t}};var U=t=>{let r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(typeof r.getBigUint64=="function")return r.getBigUint64(0);{let e=BigInt(r.getUint32(0)),n=BigInt(r.getUint32(4));return(e<<BigInt(32))+n}},w=t=>new Uint8Array(t),N=t=>Array.from(t),O=t=>new Uint8Array(t),B=t=>Array.from(t).map(r=>r.charCodeAt(0));var i=class extends Error{},c=(t,r)=>{if(t==null)throw new i(r)};var C=t=>t?[t]:[],l=t=>t?.[0],D=t=>{let r=l(t);return c(r),r};export{i as NullishError,w as arrayBufferToUint8Array,O as arrayOfNumberToUint8Array,B as asciiStringToByteArray,c as assertNonNullish,b as createServices,s as defaultAgent,D as fromDefinedNullable,l as fromNullable,C as toNullable,N as uint8ArrayToArrayOfNumber,U as uint8ArrayToBigInt};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/utils/actor.utils.ts", "../../src/utils/agent.utils.ts", "../../src/utils/asserts.utils.ts", "../../src/utils/did.utils.ts"],
4
- "sourcesContent": ["import type { ActorSubclass, Agent } from \"@dfinity/agent\";\nimport { Actor } from \"@dfinity/agent\";\nimport type { IDL } from \"@dfinity/candid\";\nimport type { Principal } from \"@dfinity/principal\";\nimport type { CanisterOptions } from \"../types/canister.options\";\nimport { defaultAgent } from \"./agent.utils\";\n\ntype RequiredCanisterOptions<T> = Required<\n Pick<CanisterOptions<T>, \"canisterId\">\n> &\n Omit<CanisterOptions<T>, \"canisterId\">;\n\nexport const createServices = <T>({\n options: {\n canisterId,\n serviceOverride,\n certifiedServiceOverride,\n agent: agentOption,\n },\n idlFactory,\n certifiedIdlFactory,\n}: {\n options: RequiredCanisterOptions<T>;\n idlFactory: IDL.InterfaceFactory;\n certifiedIdlFactory: IDL.InterfaceFactory;\n}): {\n service: ActorSubclass<T>;\n certifiedService: ActorSubclass<T>;\n agent: Agent;\n canisterId: Principal;\n} => {\n const agent: Agent = agentOption ?? defaultAgent();\n\n const service: ActorSubclass<T> =\n serviceOverride ??\n Actor.createActor<T>(idlFactory, {\n agent,\n canisterId,\n });\n\n const certifiedService: ActorSubclass<T> =\n certifiedServiceOverride ??\n Actor.createActor<T>(certifiedIdlFactory, {\n agent,\n canisterId,\n });\n\n return { service, certifiedService, agent, canisterId };\n};\n", "import type { Agent } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n", "export class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(\n value: T,\n message?: string\n): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n", "import { assertNonNullish } from \"./asserts.utils\";\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return value ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const fromDefinedNullable = <T>(value: [] | [T]): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n"],
5
- "mappings": "AACA,uCCAA,kEAKO,GAAM,GAAe,IAC1B,GAAI,GAAU,CACZ,KAAM,kBACN,SAAU,GAAI,EAChB,CAAC,EDEI,GAAM,GAAiB,CAAI,CAChC,QAAS,CACP,aACA,kBACA,2BACA,MAAO,GAET,aACA,yBAUG,CACH,GAAM,GAAe,GAAe,EAAa,EAE3C,EACJ,GACA,EAAM,YAAe,EAAY,CAC/B,QACA,YACF,CAAC,EAEG,EACJ,GACA,EAAM,YAAe,EAAqB,CACxC,QACA,YACF,CAAC,EAEH,MAAO,CAAE,UAAS,mBAAkB,QAAO,YAAW,CACxD,EEhDO,GAAM,GAAN,aAA2B,MAAM,CAAC,EAE5B,EAG0B,CACrC,EACA,IACS,CACT,GAAI,GAAU,KACZ,KAAM,IAAI,GAAa,CAAO,CAElC,ECVO,GAAM,GAAa,AAAI,GACrB,EAAQ,CAAC,CAAK,EAAI,CAAC,EAGf,EAAe,AAAI,GACvB,IAAQ,GAGJ,EAAsB,AAAI,GAAuB,CAC5D,GAAM,GAAS,EAAa,CAAK,EAEjC,SAAiB,CAAM,EAEhB,CACT",
3
+ "sources": ["../../src/utils/actor.utils.ts", "../../src/utils/agent.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/asserts.utils.ts", "../../src/utils/did.utils.ts"],
4
+ "sourcesContent": ["import type { ActorSubclass, Agent } from \"@dfinity/agent\";\nimport { Actor } from \"@dfinity/agent\";\nimport type { IDL } from \"@dfinity/candid\";\nimport type { Principal } from \"@dfinity/principal\";\nimport type { CanisterOptions } from \"../types/canister.options\";\nimport { defaultAgent } from \"./agent.utils\";\n\ntype RequiredCanisterOptions<T> = Required<\n Pick<CanisterOptions<T>, \"canisterId\">\n> &\n Omit<CanisterOptions<T>, \"canisterId\">;\n\nexport const createServices = <T>({\n options: {\n canisterId,\n serviceOverride,\n certifiedServiceOverride,\n agent: agentOption,\n },\n idlFactory,\n certifiedIdlFactory,\n}: {\n options: RequiredCanisterOptions<T>;\n idlFactory: IDL.InterfaceFactory;\n certifiedIdlFactory: IDL.InterfaceFactory;\n}): {\n service: ActorSubclass<T>;\n certifiedService: ActorSubclass<T>;\n agent: Agent;\n canisterId: Principal;\n} => {\n const agent: Agent = agentOption ?? defaultAgent();\n\n const service: ActorSubclass<T> =\n serviceOverride ??\n Actor.createActor<T>(idlFactory, {\n agent,\n canisterId,\n });\n\n const certifiedService: ActorSubclass<T> =\n certifiedServiceOverride ??\n Actor.createActor<T>(certifiedIdlFactory, {\n agent,\n canisterId,\n });\n\n return { service, certifiedService, agent, canisterId };\n};\n", "import type { Agent } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n", "export const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === \"function\") {\n return view.getBigUint64(0);\n } else {\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n }\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array =>\n new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> =>\n Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n", "export class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(\n value: T,\n message?: string\n): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n", "import { assertNonNullish } from \"./asserts.utils\";\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return value ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const fromDefinedNullable = <T>(value: [] | [T]): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n"],
5
+ "mappings": "AACA,uCCAA,kEAKO,GAAM,GAAe,IAC1B,GAAI,GAAU,CACZ,KAAM,kBACN,SAAU,GAAI,EAChB,CAAC,EDEI,GAAM,GAAiB,CAAI,CAChC,QAAS,CACP,aACA,kBACA,2BACA,MAAO,GAET,aACA,yBAUG,CACH,GAAM,GAAe,GAAe,EAAa,EAE3C,EACJ,GACA,EAAM,YAAe,EAAY,CAC/B,QACA,YACF,CAAC,EAEG,EACJ,GACA,EAAM,YAAe,EAAqB,CACxC,QACA,YACF,CAAC,EAEH,MAAO,CAAE,UAAS,mBAAkB,QAAO,YAAW,CACxD,EEhDO,GAAM,GAAqB,AAAC,GAA8B,CAC/D,GAAM,GAAO,GAAI,UAAS,EAAM,OAAQ,EAAM,WAAY,EAAM,UAAU,EAC1E,GAAI,MAAO,GAAK,cAAiB,WAC/B,MAAO,GAAK,aAAa,CAAC,EACrB,CACL,GAAM,GAAO,OAAO,EAAK,UAAU,CAAC,CAAC,EAC/B,EAAM,OAAO,EAAK,UAAU,CAAC,CAAC,EAEpC,MAAQ,IAAQ,OAAO,EAAE,GAAK,CAChC,CACF,EAEa,EAA0B,AAAC,GACtC,GAAI,YAAW,CAAM,EAEV,EAA4B,AAAC,GACxC,MAAM,KAAK,CAAK,EAEL,EAA4B,AAAC,GACxC,GAAI,YAAW,CAAO,EAEX,EAAyB,AAAC,GACrC,MAAM,KAAK,CAAI,EAAE,IAAI,AAAC,GAAM,EAAE,WAAW,CAAC,CAAC,ECtBtC,GAAM,GAAN,aAA2B,MAAM,CAAC,EAE5B,EAG0B,CACrC,EACA,IACS,CACT,GAAI,GAAU,KACZ,KAAM,IAAI,GAAa,CAAO,CAElC,ECVO,GAAM,GAAa,AAAI,GACrB,EAAQ,CAAC,CAAK,EAAI,CAAC,EAGf,EAAe,AAAI,GACvB,IAAQ,GAGJ,EAAsB,AAAI,GAAuB,CAC5D,GAAM,GAAS,EAAa,CAAK,EAEjC,SAAiB,CAAM,EAEhB,CACT",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,6 @@
1
1
  export type { CanisterOptions } from "./types/canister.options";
2
2
  export * from "./utils/actor.utils";
3
3
  export * from "./utils/agent.utils";
4
+ export * from "./utils/arrays.utils";
4
5
  export * from "./utils/asserts.utils";
5
6
  export * from "./utils/did.utils";
@@ -0,0 +1,5 @@
1
+ export declare const uint8ArrayToBigInt: (array: Uint8Array) => bigint;
2
+ export declare const arrayBufferToUint8Array: (buffer: ArrayBuffer) => Uint8Array;
3
+ export declare const uint8ArrayToArrayOfNumber: (array: Uint8Array) => Array<number>;
4
+ export declare const arrayOfNumberToUint8Array: (numbers: Array<number>) => Uint8Array;
5
+ export declare const asciiStringToByteArray: (text: string) => Array<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-next-2022-09-23",
4
4
  "description": "A collection of utilities and constants for NNS/SNS projects.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/cjs/index.cjs.js",
@@ -48,4 +48,4 @@
48
48
  "service nervous system",
49
49
  "service-nervous-system"
50
50
  ]
51
- }
51
+ }