@dfinity/utils 0.0.5-next-2022-10-03 → 0.0.5-next-2022-10-04
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.
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
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", "../../src/utils/principal.utils.ts"],
|
|
4
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\";\nexport * from \"./utils/principal.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, Identity } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * Get a default agent that connects to mainnet with the anonymous identity.\n * @returns The default agent to use\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n\n/**\n * Create an agent for a given identity\n * @param identity A mandatory identity to use for the agent\n * @param host An optional host to connect to\n * @param fetchRootKey Fetch root key for certificate validation during local development or on testnet\n */\nexport const createAgent = async ({\n identity,\n host,\n fetchRootKey = false,\n}: {\n identity: Identity;\n host?: string;\n fetchRootKey?: boolean;\n}): Promise<HttpAgent> => {\n const agent: HttpAgent = new HttpAgent({\n identity,\n ...(host !== undefined && { host }),\n });\n\n if (fetchRootKey) {\n await agent.fetchRootKey();\n }\n\n return agent;\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", "import type { Principal } from \"@dfinity/principal\";\n\n/**\n * Convert a principal to a Uint8Array 32 length.\n * e.g. Useful to convert a canister ID when topping up cycles with the Cmc canister\n * @param principal The principal that needs to be converted to Subaccount\n */\nexport const principalToSubAccount = (principal: Principal): Uint8Array => {\n const bytes: Uint8Array = principal.toUint8Array();\n const subAccount: Uint8Array = new Uint8Array(32);\n subAccount[0] = bytes.length;\n subAccount.set(bytes, 1);\n return subAccount;\n};\n"],
|
|
5
|
-
"mappings": "yaAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,4BAAAC,EAAA,8BAAAC,EAAA,2BAAAC,EAAA,qBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,iBAAAC,EAAA,wBAAAC,EAAA,iBAAAC,EAAA,0BAAAC,EAAA,eAAAC,EAAA,8BAAAC,EAAA,uBAAAC,IAAA,eAAAC,EAAAhB,GCCA,IAAAiB,EAAsB,0BCAtB,IAAAC,EAA6C,0BAMhCC,EAAe,IAC1B,IAAI,YAAU,CACZ,KAAM,kBACN,SAAU,IAAI,mBAChB,CAAC,EAQUC,EAAc,MAAO,CAChC,SAAAC,EACA,KAAAC,EACA,aAAAC,EAAe,EACjB,IAI0B,CACxB,IAAMC,EAAmB,IAAI,YAAU,CACrC,SAAAH,EACA,GAAIC,IAAS,QAAa,CAAE,KAAAA,CAAK,CACnC,CAAC,EAED,OAAIC,GACF,MAAMC,EAAM,aAAa,EAGpBA,CACT,ED1BO,IAAMC,EAAiB,CAAI,CAChC,QAAS,CACP,WAAAC,EACA,gBAAAC,EACA,yBAAAC,EACA,MAAOC,CACT,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B,IAAI,WAAW,EAAE,EAChD,OAAAA,EAAW,GAAKD,EAAM,OACtBC,EAAW,IAAID,EAAO,CAAC,EAChBC,CACT",
|
|
6
|
+
"names": ["src_exports", "__export", "NullishError", "arrayBufferToUint8Array", "arrayOfNumberToUint8Array", "asciiStringToByteArray", "assertNonNullish", "createAgent", "createServices", "defaultAgent", "fromDefinedNullable", "fromNullable", "principalToSubAccount", "toNullable", "uint8ArrayToArrayOfNumber", "uint8ArrayToBigInt", "__toCommonJS", "import_agent", "import_agent", "defaultAgent", "createAgent", "identity", "host", "fetchRootKey", "agent", "createServices", "canisterId", "serviceOverride", "certifiedServiceOverride", "agentOption", "idlFactory", "certifiedIdlFactory", "agent", "defaultAgent", "service", "certifiedService", "uint8ArrayToBigInt", "array", "view", "high", "low", "arrayBufferToUint8Array", "buffer", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "NullishError", "assertNonNullish", "value", "message", "toNullable", "value", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "principalToSubAccount", "principal", "bytes", "subAccount"]
|
|
7
7
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
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", "../../src/utils/principal.utils.ts"],
|
|
4
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, Identity } from \"@dfinity/agent\";\nimport { AnonymousIdentity, HttpAgent } from \"@dfinity/agent\";\n\n/**\n * Get a default agent that connects to mainnet with the anonymous identity.\n * @returns The default agent to use\n */\nexport const defaultAgent = (): Agent =>\n new HttpAgent({\n host: \"https://ic0.app\",\n identity: new AnonymousIdentity(),\n });\n\n/**\n * Create an agent for a given identity\n * @param identity A mandatory identity to use for the agent\n * @param host An optional host to connect to\n * @param fetchRootKey Fetch root key for certificate validation during local development or on testnet\n */\nexport const createAgent = async ({\n identity,\n host,\n fetchRootKey = false,\n}: {\n identity: Identity;\n host?: string;\n fetchRootKey?: boolean;\n}): Promise<HttpAgent> => {\n const agent: HttpAgent = new HttpAgent({\n identity,\n ...(host !== undefined && { host }),\n });\n\n if (fetchRootKey) {\n await agent.fetchRootKey();\n }\n\n return agent;\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", "import type { Principal } from \"@dfinity/principal\";\n\n/**\n * Convert a principal to a Uint8Array 32 length.\n * e.g. Useful to convert a canister ID when topping up cycles with the Cmc canister\n * @param principal The principal that needs to be converted to Subaccount\n */\nexport const principalToSubAccount = (principal: Principal): Uint8Array => {\n const bytes: Uint8Array = principal.toUint8Array();\n const subAccount: Uint8Array = new Uint8Array(32);\n subAccount[0] = bytes.length;\n subAccount.set(bytes, 1);\n return subAccount;\n};\n"],
|
|
5
|
-
"mappings": "AACA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AACA,OAAS,SAAAA,MAAa,iBCAtB,OAAS,qBAAAC,EAAmB,aAAAC,MAAiB,iBAMtC,IAAMC,EAAe,IAC1B,IAAID,EAAU,CACZ,KAAM,kBACN,SAAU,IAAID,CAChB,CAAC,EAQUG,EAAc,MAAO,CAChC,SAAAC,EACA,KAAAC,EACA,aAAAC,EAAe,EACjB,IAI0B,CACxB,IAAMC,EAAmB,IAAIN,EAAU,CACrC,SAAAG,EACA,GAAIC,IAAS,Q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GAGJE,EAA0BF,GAAuB,CAC5D,IAAMG,EAASF,EAAaD,CAAK,EAEjC,OAAAI,EAAiBD,CAAM,EAEhBA,CACT,ECTO,IAAME,EAAyBC,GAAqC,CACzE,IAAMC,EAAoBD,EAAU,aAAa,EAC3CE,EAAyB,IAAI,WAAW,EAAE,EAChD,OAAAA,EAAW,GAAKD,EAAM,OACtBC,EAAW,IAAID,EAAO,CAAC,EAChBC,CACT",
|
|
6
|
+
"names": ["Actor", "AnonymousIdentity", "HttpAgent", "defaultAgent", "createAgent", "identity", "host", "fetchRootKey", "agent", "createServices", "canisterId", "serviceOverride", "certifiedServiceOverride", "agentOption", "idlFactory", "certifiedIdlFactory", "agent", "defaultAgent", "service", "Actor", "certifiedService", "uint8ArrayToBigInt", "array", "view", "high", "low", "arrayBufferToUint8Array", "buffer", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "NullishError", "assertNonNullish", "value", "message", "toNullable", "value", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "principalToSubAccount", "principal", "bytes", "subAccount"]
|
|
7
7
|
}
|
package/package.json
CHANGED