@dfinity/agent
Advanced tools
Comparing version 0.6.25-beta.0 to 0.6.25
{ | ||
"name": "@dfinity/agent", | ||
"version": "0.6.25-beta.0", | ||
"version": "0.6.25", | ||
"main": "src/index.js", | ||
"types": "src/index.d.ts", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"bundle": "npm run build", | ||
"ci": "npm run prettier && npm run lint && npm run test", | ||
"eslint": "eslint --ext '.js,.jsx,.ts,.tsx' src/index.ts src/auth.ts src/request_id.ts src/request_id.test.ts", | ||
"eslint:fix": "npm run lint -- --fix", | ||
"lint": "npm run eslint", | ||
"tslint": "tslint --project tsconfig.json --config tslint.json", | ||
"tslint:fix": "npm run lint -- --fix", | ||
"ci": "npm run prettier && npm run lint && npm run build && npm run test", | ||
"lint": "tslint --project tsconfig.json --config tslint.json", | ||
"lint:fix": "npm run lint -- --fix", | ||
"prettier": "prettier --check \"src/**/*.ts\"", | ||
@@ -23,3 +19,2 @@ "prettier:write": "npm run prettier -- --write", | ||
"base32.js": "^0.1.0", | ||
"base64-arraybuffer": "^0.2.0", | ||
"bignumber.js": "^9.0.0", | ||
@@ -35,6 +30,2 @@ "borc": "^2.1.1", | ||
"@trust/webcrypto": "^0.9.2", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
"@typescript-eslint/parser": "^4.14.2", | ||
"eslint": "^7.19.0", | ||
"eslint-plugin-jsdoc": "^31.6.0", | ||
"jest": "^24.9.0", | ||
@@ -49,4 +40,3 @@ "jest-expect-message": "^1.0.2", | ||
"whatwg-fetch": "^3.0.0" | ||
}, | ||
"gitHead": "9a4134900c86f67e84e4b7cdeba10a233d1455bb" | ||
} | ||
} |
@@ -184,3 +184,2 @@ "use strict"; | ||
async submit(submit, identity) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let transformedRequest = (await this._transform({ | ||
@@ -220,3 +219,2 @@ request: { | ||
// TODO: remove this any. This can be a Signed or UnSigned request. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let transformedRequest = await this._transform({ | ||
@@ -223,0 +221,0 @@ request: { |
@@ -1,2 +0,2 @@ | ||
import { ActorFactory, BinaryBlob, CallFields, JsonObject, Principal, QueryFields, QueryResponse, ReadStateFields, ReadStateResponse, SubmitResponse } from '..'; | ||
import { ActorFactory, BinaryBlob, CallFields, JsonObject, Principal, QueryFields, QueryResponse, ReadStateFields, ReadStateResponse, SubmitResponse } from '@dfinity/agent'; | ||
import * as IDL from '../idl'; | ||
@@ -3,0 +3,0 @@ import { Agent } from './api'; |
@@ -23,3 +23,3 @@ "use strict"; | ||
exports.ProxyAgent = exports.ProxyStubAgent = exports.ProxyMessageKind = void 0; | ||
const __1 = require(".."); | ||
const agent_1 = require("@dfinity/agent"); | ||
const actor = __importStar(require("../actor")); | ||
@@ -132,3 +132,3 @@ var ProxyMessageKind; | ||
if (typeof principalOrNull === 'string') { | ||
return __1.Principal.fromText(principalOrNull); | ||
return agent_1.Principal.fromText(principalOrNull); | ||
} | ||
@@ -135,0 +135,0 @@ else { |
@@ -32,3 +32,3 @@ import { HttpAgentRequest } from './http_agent_types'; | ||
*/ | ||
transformRequest(request: HttpAgentRequest): Promise<unknown>; | ||
transformRequest(request: HttpAgentRequest): Promise<any>; | ||
} | ||
@@ -56,27 +56,8 @@ /** | ||
* anything, but must be serializable to CBOR. | ||
* @param request - internet computer request to transform | ||
*/ | ||
transformRequest(request: HttpAgentRequest): Promise<unknown>; | ||
transformRequest(request: HttpAgentRequest): Promise<any>; | ||
} | ||
export declare class AnonymousIdentity implements Identity { | ||
getPrincipal(): Principal; | ||
transformRequest(request: HttpAgentRequest): Promise<unknown>; | ||
transformRequest(request: HttpAgentRequest): Promise<any>; | ||
} | ||
export interface AnonymousIdentityDescriptor { | ||
type: 'AnonymousIdentity'; | ||
} | ||
export interface PublicKeyIdentityDescriptor { | ||
type: 'PublicKeyIdentity'; | ||
publicKey: string; | ||
} | ||
export declare type IdentityDescriptor = AnonymousIdentityDescriptor | PublicKeyIdentityDescriptor; | ||
/** | ||
* Create an IdentityDescriptor from a @dfinity/authentication Identity | ||
* @param identity - identity describe in returned descriptor | ||
*/ | ||
export declare function createIdentityDescriptor(identity: SignIdentity | AnonymousIdentity): IdentityDescriptor; | ||
/** | ||
* Type Guard for whether the unknown value is an IdentityDescriptor or not. | ||
* @param value - value to type guard | ||
*/ | ||
export declare function isIdentityDescriptor(value: unknown | IdentityDescriptor): value is IdentityDescriptor; |
@@ -14,3 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isIdentityDescriptor = exports.createIdentityDescriptor = exports.AnonymousIdentity = exports.SignIdentity = void 0; | ||
exports.AnonymousIdentity = exports.SignIdentity = void 0; | ||
const buffer_1 = require("buffer/"); | ||
@@ -36,3 +36,2 @@ const principal_1 = require("./principal"); | ||
* anything, but must be serializable to CBOR. | ||
* @param request - internet computer request to transform | ||
*/ | ||
@@ -59,31 +58,2 @@ async transformRequest(request) { | ||
exports.AnonymousIdentity = AnonymousIdentity; | ||
/** | ||
* Create an IdentityDescriptor from a @dfinity/authentication Identity | ||
* @param identity - identity describe in returned descriptor | ||
*/ | ||
function createIdentityDescriptor(identity) { | ||
const identityIndicator = 'getPublicKey' in identity | ||
? { type: 'PublicKeyIdentity', publicKey: identity.getPublicKey().toDer().toString('hex') } | ||
: { type: 'AnonymousIdentity' }; | ||
return identityIndicator; | ||
} | ||
exports.createIdentityDescriptor = createIdentityDescriptor; | ||
/** | ||
* Type Guard for whether the unknown value is an IdentityDescriptor or not. | ||
* @param value - value to type guard | ||
*/ | ||
function isIdentityDescriptor(value) { | ||
var _a, _b; | ||
switch ((_a = value) === null || _a === void 0 ? void 0 : _a.type) { | ||
case 'AnonymousIdentity': | ||
return true; | ||
case 'PublicKeyIdentity': | ||
if (typeof ((_b = value) === null || _b === void 0 ? void 0 : _b.publicKey) !== 'string') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
exports.isIdentityDescriptor = isIdentityDescriptor; | ||
//# sourceMappingURL=auth.js.map |
@@ -51,3 +51,3 @@ "use strict"; | ||
const msg = buffer_1.Buffer.concat([domain_sep('ic-state-root'), rootHash]); | ||
const res = await bls_1.blsVerify(key, sig, msg); | ||
const res = await bls_1.BLS.blsVerify(bufferToHex(key), bufferToHex(sig), bufferToHex(msg)); | ||
this.verified = res; | ||
@@ -85,2 +85,5 @@ return res; | ||
} | ||
function bufferToHex(buf) { | ||
return buf.toString('hex'); | ||
} | ||
async function reconstruct(t) { | ||
@@ -87,0 +90,0 @@ switch (t[0]) { |
import { ActorSubclass } from './actor'; | ||
export * from './actor'; | ||
export * from './agent'; | ||
export * from './certificate'; | ||
export * from './auth'; | ||
export * from './certificate'; | ||
export * from './http_agent_transforms'; | ||
@@ -26,16 +26,2 @@ export * from './http_agent_types'; | ||
/** | ||
* Simple advertisement of features in whoever is managing this `globalThis.ic`. | ||
* Use Case | ||
* * Scripts that know they need an ic feature can detect using this and, if not present | ||
* (e.g. old bootstrap version), they can dynamically include their own and continue | ||
* operating (e.g. polyfill). | ||
* This is useful when adding features to bootstrap. You can still deploy your canister to | ||
* an ic with old bootstrap, then just dynamically reload your own new-version bootstrap if | ||
* needed. | ||
*/ | ||
features?: { | ||
/** This is falsy if authn isn't supported at all */ | ||
authentication?: boolean; | ||
}; | ||
/** | ||
* The Actor for the canister being used for the frontend. Normally should correspond to the | ||
@@ -48,4 +34,4 @@ * canister represented by the canister id in the URL. | ||
*/ | ||
canister: ActorSubclass | undefined; | ||
canister: ActorSubclass<{}> | undefined; | ||
}; | ||
} |
@@ -28,4 +28,4 @@ "use strict"; | ||
__exportStar(require("./agent"), exports); | ||
__exportStar(require("./certificate"), exports); | ||
__exportStar(require("./auth"), exports); | ||
__exportStar(require("./certificate"), exports); | ||
__exportStar(require("./http_agent_transforms"), exports); | ||
@@ -32,0 +32,0 @@ __exportStar(require("./http_agent_types"), exports); |
@@ -6,18 +6,4 @@ import { Buffer } from 'buffer/'; | ||
}; | ||
/** | ||
* get RequestId as hex-encoded blob. | ||
* @param requestId - RequestId to hex | ||
*/ | ||
export declare function toHex(requestId: RequestId): string; | ||
/** | ||
* sha256 hash the provided Buffer | ||
* @param data - input to hash function | ||
*/ | ||
export declare function hash(data: Buffer): Promise<BinaryBlob>; | ||
/** | ||
* Get the RequestId of the provided ic-ref request. | ||
* RequestId is the result of the representation-independent-hash function. | ||
* https://docs.dfinity.systems/public/#api-hash-of-map | ||
* @param request - ic-ref request to hash into RequestId | ||
*/ | ||
export declare function requestIdOf(request: Record<string, any>): Promise<RequestId>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.requestIdOf = exports.hash = exports.toHex = void 0; | ||
const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
const borc_1 = __importDefault(require("borc")); | ||
@@ -12,6 +13,2 @@ const buffer_1 = require("buffer/"); | ||
const leb128_1 = require("./utils/leb128"); | ||
/** | ||
* get RequestId as hex-encoded blob. | ||
* @param requestId - RequestId to hex | ||
*/ | ||
function toHex(requestId) { | ||
@@ -21,6 +18,2 @@ return types_1.blobToHex(requestId); | ||
exports.toHex = toHex; | ||
/** | ||
* sha256 hash the provided Buffer | ||
* @param data - input to hash function | ||
*/ | ||
async function hash(data) { | ||
@@ -33,12 +26,2 @@ const hashed = await crypto.subtle.digest({ | ||
exports.hash = hash; | ||
/** | ||
* Type Guard for BigNumber.js that have a protottype we don't have a reference to, so can't do | ||
* an `instanceof` check. This can happen in certain sets of dependency graphs for the | ||
* agent-js-monorepo, e.g. when used by authentication-demo. All this really verifies is the | ||
* truthiness of the `_isBigNumber` property that the source code defines as protected. | ||
* @param v - value to check for type=BigNumber.js | ||
*/ | ||
function isBigNumber(v) { | ||
return typeof v === 'object' && v !== null && v._isBigNumber; | ||
} | ||
async function hashValue(value) { | ||
@@ -51,2 +34,5 @@ if (value instanceof borc_1.default.Tagged) { | ||
} | ||
else if (value instanceof bignumber_js_1.default) { | ||
return hash(leb128_1.lebEncode(value)); | ||
} | ||
else if (typeof value === 'number') { | ||
@@ -73,13 +59,5 @@ return hash(leb128_1.lebEncode(value)); | ||
} | ||
else if (isBigNumber(value)) { | ||
// Do this check much later than the other BigNumber check because this one is much less | ||
// type-safe. | ||
// So we want to try all the high-assurance type guards before this 'probable' one. | ||
return hash(leb128_1.lebEncode(value)); | ||
else { | ||
throw new Error(`Attempt to hash a value of unsupported type: ${value}`); | ||
} | ||
throw Object.assign(new Error(`Attempt to hash a value of unsupported type: ${value}`), { | ||
// include so logs/callers can understand the confusing value. | ||
// (when stringified in error message, prototype info is lost) | ||
value, | ||
}); | ||
} | ||
@@ -91,19 +69,8 @@ const hashString = (value) => { | ||
}; | ||
/** | ||
* Concatenate many blobs. | ||
* @param bs - blobs to concatenate | ||
*/ | ||
function concat(bs) { | ||
return types_1.blobFromBuffer(buffer_1.Buffer.concat(bs)); | ||
} | ||
/** | ||
* Get the RequestId of the provided ic-ref request. | ||
* RequestId is the result of the representation-independent-hash function. | ||
* https://docs.dfinity.systems/public/#api-hash-of-map | ||
* @param request - ic-ref request to hash into RequestId | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
async function requestIdOf(request) { | ||
const hashed = Object.entries(request) | ||
.filter(([, value]) => value !== undefined) | ||
.filter(([_, value]) => value !== undefined) | ||
.map(async ([key, value]) => { | ||
@@ -115,3 +82,3 @@ const hashedKey = await hashString(key); | ||
const traversed = await Promise.all(hashed); | ||
const sorted = traversed.sort(([k1], [k2]) => { | ||
const sorted = traversed.sort(([k1, v1], [k2, v2]) => { | ||
return buffer_1.Buffer.compare(buffer_1.Buffer.from(k1), buffer_1.Buffer.from(k2)); | ||
@@ -118,0 +85,0 @@ }); |
@@ -1,2 +0,5 @@ | ||
export declare let verify: (pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) => boolean; | ||
export declare function blsVerify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean>; | ||
export declare class BLS { | ||
static blsVerify(pk: string, sig: string, msg: string): Promise<boolean>; | ||
private static verify; | ||
private constructor(); | ||
} |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.blsVerify = exports.verify = void 0; | ||
const bls_1 = __importStar(require("../vendor/bls/bls")); | ||
async function blsVerify(pk, sig, msg) { | ||
if (!exports.verify) { | ||
await bls_1.default(); | ||
if (bls_1.bls_init() !== 0) { | ||
throw new Error('Cannot initialize BLS'); | ||
exports.BLS = void 0; | ||
// tslint:disable-next-line:no-var-requires | ||
const BLSModule = require('./bls_gen'); | ||
class BLS { | ||
constructor() { } | ||
static async blsVerify(pk, sig, msg) { | ||
if (!BLS.verify) { | ||
const m = await BLSModule(); | ||
if (m._init() !== 0) { | ||
throw new Error('Cannot initialize BLS'); | ||
} | ||
BLS.verify = m.cwrap('verify', 'boolean', ['string', 'string', 'string']); | ||
} | ||
exports.verify = (pk1, sig1, msg1) => { | ||
// Reorder things from what the WASM expects (sig, m, w). | ||
return bls_1.bls_verify(sig1, msg1, pk1) === 0; | ||
}; | ||
const res = BLS.verify(pk, sig, msg); | ||
return res; | ||
} | ||
return exports.verify(pk, sig, msg); | ||
} | ||
exports.blsVerify = blsVerify; | ||
exports.BLS = BLS; | ||
//# sourceMappingURL=bls.js.map |
@@ -5,3 +5,3 @@ import BigNumber from 'bignumber.js'; | ||
export declare function safeRead(pipe: Pipe, num: number): Buffer; | ||
export declare function lebEncode(value: number | BigNumber | bigint | BigInt): Buffer; | ||
export declare function lebEncode(value: number | BigNumber): Buffer; | ||
export declare function lebDecode(pipe: Pipe): BigNumber; | ||
@@ -8,0 +8,0 @@ export declare function slebEncode(value: BigNumber | number): Buffer; |
@@ -26,6 +26,3 @@ "use strict"; | ||
function lebEncode(value) { | ||
if (typeof value === 'bigint' || value instanceof BigInt) { | ||
value = new bignumber_js_1.default(value.toString(10), 10); | ||
} | ||
else if (typeof value === 'number') { | ||
if (typeof value === 'number') { | ||
value = new bignumber_js_1.default(value); | ||
@@ -32,0 +29,0 @@ } |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
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
10
10
252398
1
4898
2
5
- Removedbase64-arraybuffer@^0.2.0
- Removedbase64-arraybuffer@0.2.0(transitive)