@dfinity/utils
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
"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}); | ||
"use strict";var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var b=(t,r)=>{for(var e in r)c(t,e,{get:r[e],enumerable:!0})},x=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of d(r))!T.call(t,o)&&o!==e&&c(t,o,{get:()=>r[o],enumerable:!(n=l(r,o))||n.enumerable});return t};var U=t=>x(c({},"__esModule",{value:!0}),t);var R={};b(R,{NullishError:()=>s,arrayBufferToUint8Array:()=>N,arrayOfNumberToUint8Array:()=>S,asciiStringToByteArray:()=>B,assertNonNullish:()=>f,createAgent:()=>I,createServices:()=>w,defaultAgent:()=>p,fromDefinedNullable:()=>P,fromNullable:()=>A,principalToSubAccount:()=>D,toNullable:()=>C,uint8ArrayToArrayOfNumber:()=>O,uint8ArrayToBigInt:()=>h});module.exports=U(R);var y=require("@dfinity/agent");var i=require("@dfinity/agent"),p=()=>new i.HttpAgent({host:"https://ic0.app",identity:new i.AnonymousIdentity}),I=async({identity:t,host:r,fetchRootKey:e=!1})=>{let n=new i.HttpAgent({identity:t,...r!==void 0&&{host:r}});return e&&await n.fetchRootKey(),n};var w=({options:{canisterId:t,serviceOverride:r,certifiedServiceOverride:e,agent:n},idlFactory:o,certifiedIdlFactory:m})=>{let a=n??p(),u=r??y.Actor.createActor(o,{agent:a,canisterId:t}),g=e??y.Actor.createActor(m,{agent:a,canisterId:t});return{service:u,certifiedService:g,agent:a,canisterId:t}};var h=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}},N=t=>new Uint8Array(t),O=t=>Array.from(t),S=t=>new Uint8Array(t),B=t=>Array.from(t).map(r=>r.charCodeAt(0));var s=class extends Error{},f=(t,r)=>{if(t==null)throw new s(r)};var C=t=>t?[t]:[],A=t=>t==null?void 0:t[0],P=t=>{let r=A(t);return f(r),r};var D=t=>{let r=t.toUint8Array(),e=new Uint8Array(32);return e[0]=r.length,e.set(r,1),e};0&&(module.exports={NullishError,arrayBufferToUint8Array,arrayOfNumberToUint8Array,asciiStringToByteArray,assertNonNullish,createAgent,createServices,defaultAgent,fromDefinedNullable,fromNullable,principalToSubAccount,toNullable,uint8ArrayToArrayOfNumber,uint8ArrayToBigInt}); | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
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}; | ||
import{Actor as c}from"@dfinity/agent";import{AnonymousIdentity as m,HttpAgent as s}from"@dfinity/agent";var a=()=>new s({host:"https://ic0.app",identity:new m}),d=async({identity:t,host:r,fetchRootKey:e=!1})=>{let n=new s({identity:t,...r!==void 0&&{host:r}});return e&&await n.fetchRootKey(),n};var U=({options:{canisterId:t,serviceOverride:r,certifiedServiceOverride:e,agent:n},idlFactory:y,certifiedIdlFactory:f})=>{let o=n??a(),A=r??c.createActor(y,{agent:o,canisterId:t}),u=e??c.createActor(f,{agent:o,canisterId:t});return{service:A,certifiedService:u,agent:o,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)),n=BigInt(r.getUint32(4));return(e<<BigInt(32))+n}},h=t=>new Uint8Array(t),N=t=>Array.from(t),O=t=>new Uint8Array(t),S=t=>Array.from(t).map(r=>r.charCodeAt(0));var i=class extends Error{},p=(t,r)=>{if(t==null)throw new i(r)};var P=t=>t?[t]:[],l=t=>t?.[0],D=t=>{let r=l(t);return p(r),r};var F=t=>{let r=t.toUint8Array(),e=new Uint8Array(32);return e[0]=r.length,e.set(r,1),e};export{i as NullishError,h as arrayBufferToUint8Array,O as arrayOfNumberToUint8Array,S as asciiStringToByteArray,p as assertNonNullish,d as createAgent,U as createServices,a as defaultAgent,D as fromDefinedNullable,l as fromNullable,F as principalToSubAccount,P as toNullable,N as uint8ArrayToArrayOfNumber,w as uint8ArrayToBigInt}; | ||
//# sourceMappingURL=index.js.map |
@@ -7,1 +7,2 @@ export type { CanisterOptions } from "./types/canister.options"; | ||
export * from "./utils/did.utils"; | ||
export * from "./utils/principal.utils"; |
@@ -1,5 +0,18 @@ | ||
import type { Agent } from "@dfinity/agent"; | ||
import type { Agent, Identity } from "@dfinity/agent"; | ||
import { HttpAgent } from "@dfinity/agent"; | ||
/** | ||
* @returns The default agent to use. An agent that connects to mainnet with the anonymous identity. | ||
* Get a default agent that connects to mainnet with the anonymous identity. | ||
* @returns The default agent to use | ||
*/ | ||
export declare const defaultAgent: () => Agent; | ||
/** | ||
* Create an agent for a given identity | ||
* @param identity A mandatory identity to use for the agent | ||
* @param host An optional host to connect to | ||
* @param fetchRootKey Fetch root key for certificate validation during local development or on testnet | ||
*/ | ||
export declare const createAgent: ({ identity, host, fetchRootKey, }: { | ||
identity: Identity; | ||
host?: string | undefined; | ||
fetchRootKey?: boolean | undefined; | ||
}) => Promise<HttpAgent>; |
{ | ||
"name": "@dfinity/utils", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A collection of utilities and constants for NNS/SNS projects.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -35,2 +35,3 @@ # utils-js | ||
- [defaultAgent](#gear-defaultagent) | ||
- [createAgent](#gear-createagent) | ||
- [createServices](#gear-createservices) | ||
@@ -46,5 +47,8 @@ - [uint8ArrayToBigInt](#gear-uint8arraytobigint) | ||
- [fromDefinedNullable](#gear-fromdefinednullable) | ||
- [principalToSubAccount](#gear-principaltosubaccount) | ||
#### :gear: defaultAgent | ||
Get a default agent that connects to mainnet with the anonymous identity. | ||
| Function | Type | | ||
@@ -54,2 +58,16 @@ | -------------- | ------------- | | ||
#### :gear: createAgent | ||
Create an agent for a given identity | ||
| Function | Type | | ||
| ------------- | --------------------------------------------------------------------------------------------------------------------------- | | ||
| `createAgent` | `({ identity, host, fetchRootKey, }: { identity: Identity; host?: string; fetchRootKey?: boolean; }) => Promise<HttpAgent>` | | ||
Parameters: | ||
- `identity`: A mandatory identity to use for the agent | ||
- `host`: An optional host to connect to | ||
- `fetchRootKey`: Fetch root key for certificate validation during local development or on testnet | ||
#### :gear: createServices | ||
@@ -115,2 +133,15 @@ | ||
#### :gear: principalToSubAccount | ||
Convert a principal to a Uint8Array 32 length. | ||
e.g. Useful to convert a canister ID when topping up cycles with the Cmc canister | ||
| Function | Type | | ||
| ----------------------- | -------------------------------------- | | ||
| `principalToSubAccount` | `(principal: Principal) => Uint8Array` | | ||
Parameters: | ||
- `principal`: The principal that needs to be converted to Subaccount | ||
### :factory: NullishError | ||
@@ -117,0 +148,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38023
17
84
154