Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dfinity/agent

Package Overview
Dependencies
Maintainers
10
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/agent - npm Package Compare versions

Comparing version 0.6.23 to 0.6.24-lerna.0

LICENSE

5

package.json
{
"name": "@dfinity/agent",
"version": "0.6.23",
"version": "0.6.24-lerna.0",
"main": "src/index.js",

@@ -38,3 +38,4 @@ "scripts": {

"whatwg-fetch": "^3.0.0"
}
},
"gitHead": "52e44d6879d89e649e7f9a03c62a86aca7a3c9a5"
}

1

src/actor.d.ts

@@ -5,2 +5,3 @@ import { Agent } from './agent';

import { BinaryBlob } from './types';
export declare function getRootKey(): Promise<BinaryBlob>;
/**

@@ -7,0 +8,0 @@ * Configuration to make calls to the Replica.

@@ -22,5 +22,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.makeActorFactory = exports.Actor = exports.CanisterInstallMode = void 0;
exports.makeActorFactory = exports.Actor = exports.CanisterInstallMode = exports.getRootKey = void 0;
const buffer_1 = require("buffer/");
const agent_1 = require("./agent");
const management_1 = require("./canisters/management");

@@ -33,2 +32,20 @@ const certificate_1 = require("./certificate");

const types_1 = require("./types");
function getDefaultAgent() {
const agent = typeof window === 'undefined'
? typeof global === 'undefined'
? typeof self === 'undefined'
? undefined
: self.ic.agent
: global.ic.agent
: window.ic.agent;
if (!agent) {
throw new Error('No Agent could be found.');
}
return agent;
}
async function getRootKey() {
// TODO add the real root key for Mercury
return (await getDefaultAgent().status()).root_key;
}
exports.getRootKey = getRootKey;
/**

@@ -141,3 +158,3 @@ * The mode used when installing a canister.

return async function (...args) {
const agent = this[metadataSymbol].agent || agent_1.getDefaultAgent();
const agent = this[metadataSymbol].agent || getDefaultAgent();
const cid = this[metadataSymbol].canisterId;

@@ -158,3 +175,3 @@ const arg = IDL.encode(func.argTypes, args);

return async function (...args) {
const agent = this[metadataSymbol].agent || agent_1.getDefaultAgent();
const agent = this[metadataSymbol].agent || getDefaultAgent();
const cid = this[metadataSymbol].canisterId;

@@ -191,3 +208,3 @@ const { maxAttempts, throttleDurationInMSecs } = this[metadataSymbol];

const state = await agent.readState({ paths: [path] });
const cert = new certificate_1.Certificate(state, agent);
const cert = new certificate_1.Certificate(state);
const verified = await cert.verify();

@@ -194,0 +211,0 @@ if (!verified) {

@@ -1,5 +0,3 @@

import { Agent } from './api';
export * from './api';
export * from './http';
export * from './proxy';
export declare function getDefaultAgent(): Agent;

@@ -13,20 +13,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultAgent = void 0;
__exportStar(require("./api"), exports);
__exportStar(require("./http"), exports);
__exportStar(require("./proxy"), exports);
function getDefaultAgent() {
const agent = typeof window === 'undefined'
? typeof global === 'undefined'
? typeof self === 'undefined'
? undefined
: self.ic.agent
: global.ic.agent
: window.ic.agent;
if (!agent) {
throw new Error('No Agent could be found.');
}
return agent;
}
exports.getDefaultAgent = getDefaultAgent;
//# sourceMappingURL=index.js.map

@@ -10,3 +10,3 @@ "use strict";

this.value = undefined;
const status = document.createElement('span');
const status = document.createElement('div');
status.className = 'status';

@@ -21,4 +21,3 @@ this.status = status;

});
ui.input.addEventListener('input', () => {
status.style.display = 'none';
ui.input.addEventListener('focus', () => {
ui.input.classList.remove('reject');

@@ -25,0 +24,0 @@ });

@@ -104,3 +104,3 @@ "use strict";

len.max = '100';
len.style.width = '8rem';
len.style.width = '3em';
len.placeholder = 'len';

@@ -107,0 +107,0 @@ len.classList.add('open');

import { Buffer } from 'buffer/';
import { Agent } from './agent';
import { ReadStateResponse } from './http_agent_types';
export declare type HashTree = [0] | [1, HashTree, HashTree] | [2, ArrayBuffer, HashTree] | [3, ArrayBuffer] | [4, ArrayBuffer];
export declare class Certificate {
private _agent;
private readonly cert;
private verified;
private _rootKey;
constructor(response: ReadStateResponse, _agent?: Agent);
constructor(response: ReadStateResponse);
lookup(path: Buffer[]): Buffer | undefined;
verify(): Promise<boolean>;
private _checkDelegation;
}
export declare function reconstruct(t: HashTree): Promise<Buffer>;
export declare function lookup_path(path: Buffer[], tree: HashTree): Buffer | undefined;

@@ -24,15 +24,9 @@ "use strict";

const buffer_1 = require("buffer/");
const agent_1 = require("./agent");
const actor_1 = require("./actor");
const cbor = __importStar(require("./cbor"));
const request_id_1 = require("./request_id");
const bls_1 = require("./utils/bls");
async function getRootKey(agent) {
// TODO add the real root key for Mercury
return (await agent.status()).root_key;
}
class Certificate {
constructor(response, _agent = agent_1.getDefaultAgent()) {
this._agent = _agent;
constructor(response) {
this.verified = false;
this._rootKey = null;
this.cert = cbor.decode(response.certificate);

@@ -46,28 +40,27 @@ }

}
async verify() {
const rootHash = await reconstruct(this.cert.tree);
const derKey = await this._checkDelegation(this.cert.delegation);
const sig = this.cert.signature;
const key = extractDER(derKey);
const msg = buffer_1.Buffer.concat([domain_sep('ic-state-root'), rootHash]);
const res = await bls_1.BLS.blsVerify(bufferToHex(key), bufferToHex(sig), bufferToHex(msg));
this.verified = res;
return res;
verify() {
return (async () => {
const rootHash = await reconstruct(this.cert.tree);
const derKey = await checkDelegation(this.cert.delegation);
const sig = this.cert.signature;
const key = extractDER(derKey);
const msg = buffer_1.Buffer.concat([domain_sep('ic-state-root'), rootHash]);
const res = await bls_1.BLS.blsVerify(bufferToHex(key), bufferToHex(sig), bufferToHex(msg));
this.verified = res;
return res;
})();
}
async _checkDelegation(d) {
if (!d) {
if (!this._rootKey) {
this._rootKey = await getRootKey(this._agent);
}
return this._rootKey;
}
const cert = new Certificate(d, this._agent);
if (!(await cert.verify())) {
throw new Error('fail to verify delegation certificate');
}
const res = cert.lookup([buffer_1.Buffer.from('subnet'), d.subnet_id, buffer_1.Buffer.from('public_key')]);
return Promise.resolve(res);
}
exports.Certificate = Certificate;
async function checkDelegation(d) {
if (!d) {
return await actor_1.getRootKey();
}
const cert = new Certificate(d);
if (!(await cert.verify())) {
throw new Error('fail to verify delegation certificate');
}
const res = cert.lookup([buffer_1.Buffer.from('subnet'), d.subnet_id, buffer_1.Buffer.from('public_key')]);
return Promise.resolve(res);
}
exports.Certificate = Certificate;
const DER_PREFIX = buffer_1.Buffer.from('308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100', 'hex');

@@ -74,0 +67,0 @@ const KEY_LENGTH = 96;

@@ -8,3 +8,2 @@ "use strict";

const base32_js_1 = __importDefault(require("base32.js"));
const buffer_1 = require("buffer/");
const types_1 = require("./types");

@@ -57,3 +56,3 @@ const getCrc_1 = require("./utils/getCrc");

view.setUint32(0, getCrc_1.getCrc32(this.toHex().toLowerCase()), false);
const checksum = Uint8Array.from(buffer_1.Buffer.from(checksumArrayBuf));
const checksum = Uint8Array.from(Buffer.from(checksumArrayBuf));
const bytes = Uint8Array.from(this._blob);

@@ -60,0 +59,0 @@ const array = new Uint8Array([...checksum, ...bytes]);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc