@dfinity/nns 0.1.5 → 0.1.6
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/candid/governance.certified.did +12 -0
- package/candid/governance.certified.idl.d.ts +2 -0
- package/candid/governance.certified.idl.js +18 -0
- package/candid/governance.did +10 -0
- package/candid/governance.idl.d.ts +5 -0
- package/candid/governance.idl.js +18 -0
- package/candid/governanceTypes.d.ts +16 -0
- package/dist/governance.d.ts +30 -0
- package/dist/governance.js +55 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +15 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# The candid to interact with the governance canister using update calls in place of queries for additional security.
|
|
2
|
+
|
|
3
|
+
type KnownNeuron = record {
|
|
4
|
+
id : opt NeuronId;
|
|
5
|
+
known_neuron_data : opt KnownNeuronData;
|
|
6
|
+
};
|
|
7
|
+
type KnownNeuronData = record { name : text; description : opt text };
|
|
8
|
+
type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
|
|
9
|
+
type NeuronId = record { id : nat64 };
|
|
10
|
+
service : {
|
|
11
|
+
list_known_neurons : () -> (ListKnownNeuronsResponse);
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const idlFactory = ({ IDL }) => {
|
|
2
|
+
const NeuronId = IDL.Record({ 'id' : IDL.Nat64 });
|
|
3
|
+
const KnownNeuronData = IDL.Record({
|
|
4
|
+
'name' : IDL.Text,
|
|
5
|
+
'description' : IDL.Opt(IDL.Text),
|
|
6
|
+
});
|
|
7
|
+
const KnownNeuron = IDL.Record({
|
|
8
|
+
'id' : IDL.Opt(NeuronId),
|
|
9
|
+
'known_neuron_data' : IDL.Opt(KnownNeuronData),
|
|
10
|
+
});
|
|
11
|
+
const ListKnownNeuronsResponse = IDL.Record({
|
|
12
|
+
'known_neurons' : IDL.Vec(KnownNeuron),
|
|
13
|
+
});
|
|
14
|
+
return IDL.Service({
|
|
15
|
+
'list_known_neurons' : IDL.Func([], [ListKnownNeuronsResponse], []),
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export const init = ({ IDL }) => { return []; };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type KnownNeuron = record {
|
|
2
|
+
id : opt NeuronId;
|
|
3
|
+
known_neuron_data : opt KnownNeuronData;
|
|
4
|
+
};
|
|
5
|
+
type KnownNeuronData = record { name : text; description : opt text };
|
|
6
|
+
type ListKnownNeuronsResponse = record { known_neurons : vec KnownNeuron };
|
|
7
|
+
type NeuronId = record { id : nat64 };
|
|
8
|
+
service : {
|
|
9
|
+
list_known_neurons : () -> (ListKnownNeuronsResponse) query;
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const idlFactory = ({ IDL }) => {
|
|
2
|
+
const NeuronId = IDL.Record({ 'id' : IDL.Nat64 });
|
|
3
|
+
const KnownNeuronData = IDL.Record({
|
|
4
|
+
'name' : IDL.Text,
|
|
5
|
+
'description' : IDL.Opt(IDL.Text),
|
|
6
|
+
});
|
|
7
|
+
const KnownNeuron = IDL.Record({
|
|
8
|
+
'id' : IDL.Opt(NeuronId),
|
|
9
|
+
'known_neuron_data' : IDL.Opt(KnownNeuronData),
|
|
10
|
+
});
|
|
11
|
+
const ListKnownNeuronsResponse = IDL.Record({
|
|
12
|
+
'known_neurons' : IDL.Vec(KnownNeuron),
|
|
13
|
+
});
|
|
14
|
+
return IDL.Service({
|
|
15
|
+
'list_known_neurons' : IDL.Func([], [ListKnownNeuronsResponse], ['query']),
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export const init = ({ IDL }) => { return []; };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Principal } from '@dfinity/principal';
|
|
2
|
+
export interface KnownNeuron {
|
|
3
|
+
'id' : [] | [NeuronId],
|
|
4
|
+
'known_neuron_data' : [] | [KnownNeuronData],
|
|
5
|
+
}
|
|
6
|
+
export interface KnownNeuronData {
|
|
7
|
+
'name' : string,
|
|
8
|
+
'description' : [] | [string],
|
|
9
|
+
}
|
|
10
|
+
export interface ListKnownNeuronsResponse {
|
|
11
|
+
'known_neurons' : Array<KnownNeuron>,
|
|
12
|
+
}
|
|
13
|
+
export interface NeuronId { 'id' : bigint }
|
|
14
|
+
export interface _SERVICE {
|
|
15
|
+
'list_known_neurons' : () => Promise<ListKnownNeuronsResponse>,
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Agent } from "@dfinity/agent";
|
|
2
|
+
import { Principal } from "@dfinity/principal";
|
|
3
|
+
import { GovernanceService } from "../candid/governance.idl";
|
|
4
|
+
declare type NeuronId = bigint;
|
|
5
|
+
export declare type KnownNeuron = {
|
|
6
|
+
id: NeuronId;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export interface GovernanceCanisterOptions {
|
|
11
|
+
agent?: Agent;
|
|
12
|
+
canisterId?: Principal;
|
|
13
|
+
serviceOverride?: GovernanceService;
|
|
14
|
+
certifiedServiceOverride?: GovernanceService;
|
|
15
|
+
}
|
|
16
|
+
export declare class GovernanceCanister {
|
|
17
|
+
private readonly service;
|
|
18
|
+
private readonly certifiedService;
|
|
19
|
+
private constructor();
|
|
20
|
+
static create(options?: GovernanceCanisterOptions): GovernanceCanister;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the list of neurons who have been approved by the community to
|
|
23
|
+
* appear as the default followee options.
|
|
24
|
+
*
|
|
25
|
+
* If `certified` is true, the request is fetched as an update call, otherwise
|
|
26
|
+
* it is fetched using a query call.
|
|
27
|
+
*/
|
|
28
|
+
listKnownNeurons: (certified?: boolean) => Promise<KnownNeuron[]>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GovernanceCanister = void 0;
|
|
4
|
+
const agent_1 = require("@dfinity/agent");
|
|
5
|
+
const principal_1 = require("@dfinity/principal");
|
|
6
|
+
const governance_idl_1 = require("../candid/governance.idl");
|
|
7
|
+
const governance_certified_idl_1 = require("../candid/governance.certified.idl");
|
|
8
|
+
const MAINNET_GOVERNANCE_CANISTER_ID = principal_1.Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai");
|
|
9
|
+
class GovernanceCanister {
|
|
10
|
+
constructor(service, certifiedService) {
|
|
11
|
+
this.service = service;
|
|
12
|
+
this.certifiedService = certifiedService;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the list of neurons who have been approved by the community to
|
|
15
|
+
* appear as the default followee options.
|
|
16
|
+
*
|
|
17
|
+
* If `certified` is true, the request is fetched as an update call, otherwise
|
|
18
|
+
* it is fetched using a query call.
|
|
19
|
+
*/
|
|
20
|
+
this.listKnownNeurons = async (certified = true) => {
|
|
21
|
+
const service = certified ? this.certifiedService : this.service;
|
|
22
|
+
const response = await service.list_known_neurons();
|
|
23
|
+
return response.known_neurons.map(n => ({
|
|
24
|
+
id: n.id[0]?.id ?? BigInt(0),
|
|
25
|
+
name: n.known_neuron_data[0]?.name ?? "",
|
|
26
|
+
description: n.known_neuron_data[0]?.description[0]
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
static create(options = {}) {
|
|
31
|
+
const agent = options.agent ?? defaultAgent();
|
|
32
|
+
const canisterId = options.canisterId ?? MAINNET_GOVERNANCE_CANISTER_ID;
|
|
33
|
+
const service = options.serviceOverride ??
|
|
34
|
+
agent_1.Actor.createActor(governance_idl_1.idlFactory, {
|
|
35
|
+
agent,
|
|
36
|
+
canisterId,
|
|
37
|
+
});
|
|
38
|
+
const certifiedService = options.certifiedServiceOverride ??
|
|
39
|
+
agent_1.Actor.createActor(governance_certified_idl_1.idlFactory, {
|
|
40
|
+
agent,
|
|
41
|
+
canisterId,
|
|
42
|
+
});
|
|
43
|
+
return new GovernanceCanister(service, certifiedService);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.GovernanceCanister = GovernanceCanister;
|
|
47
|
+
/**
|
|
48
|
+
* @returns The default agent to use. An agent that connects to mainnet with the anonymous identity.
|
|
49
|
+
*/
|
|
50
|
+
function defaultAgent() {
|
|
51
|
+
return new agent_1.HttpAgent({
|
|
52
|
+
host: "https://ic0.app",
|
|
53
|
+
identity: new agent_1.AnonymousIdentity(),
|
|
54
|
+
});
|
|
55
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ICP = exports.SubAccount = exports.AccountIdentifier = exports.LedgerCanister = void 0;
|
|
3
|
+
exports.ICP = exports.SubAccount = exports.AccountIdentifier = exports.LedgerCanister = exports.GovernanceCanister = void 0;
|
|
4
|
+
var governance_1 = require("./governance");
|
|
5
|
+
Object.defineProperty(exports, "GovernanceCanister", { enumerable: true, get: function () { return governance_1.GovernanceCanister; } });
|
|
4
6
|
var ledger_1 = require("./ledger");
|
|
5
7
|
Object.defineProperty(exports, "LedgerCanister", { enumerable: true, get: function () { return ledger_1.LedgerCanister; } });
|
|
6
8
|
var account_identifier_1 = require("./account_identifier");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfinity/nns",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "A library for interfacing with the Internet Computer's Network Nervous System.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"internet computer",
|
|
@@ -23,33 +23,47 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc",
|
|
25
25
|
"test": "jest",
|
|
26
|
+
"doc": "typedoc ./src/index.ts",
|
|
26
27
|
"lint": "eslint --max-warnings 0 .",
|
|
27
28
|
"format": "prettier --write .",
|
|
28
29
|
"update_proto": "bash ./scripts/update_proto.sh"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@babel/preset-env": "^7.16.11",
|
|
31
33
|
"@types/google-protobuf": "^3.15.5",
|
|
32
34
|
"@types/jest": "^27.0.3",
|
|
33
35
|
"@types/text-encoding": "^0.0.36",
|
|
34
36
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
37
|
+
"babel-jest": "^27.4.6",
|
|
38
|
+
"babelify": "^10.0.0",
|
|
35
39
|
"eslint": "^7.29.0",
|
|
36
40
|
"eslint-config-standard": "^16.0.3",
|
|
37
41
|
"eslint-plugin-import": "^2.23.4",
|
|
38
42
|
"eslint-plugin-node": "^11.1.0",
|
|
39
43
|
"eslint-plugin-promise": "^5.1.0",
|
|
40
44
|
"jest": "^27.3.1",
|
|
45
|
+
"jest-mock-extended": "^2.0.4",
|
|
41
46
|
"prettier": "^2.5.0",
|
|
42
47
|
"text-encoding": "^0.7.0",
|
|
43
48
|
"ts-jest": "^27.0.7",
|
|
44
49
|
"ts-protoc-gen": "^0.15.0",
|
|
50
|
+
"typedoc": "^0.22.11",
|
|
45
51
|
"typescript": "^4.5.2",
|
|
46
52
|
"whatwg-fetch": "^3.6.2"
|
|
47
53
|
},
|
|
48
54
|
"dependencies": {
|
|
49
55
|
"@dfinity/agent": "^0.10.2",
|
|
56
|
+
"@dfinity/candid": "^0.10.2",
|
|
50
57
|
"@dfinity/principal": "^0.10.2",
|
|
51
58
|
"crc-32": "^1.2.0",
|
|
52
59
|
"google-protobuf": "^3.19.1",
|
|
53
60
|
"js-sha256": "^0.9.0"
|
|
61
|
+
},
|
|
62
|
+
"browserify": {
|
|
63
|
+
"transform": [
|
|
64
|
+
[
|
|
65
|
+
"babelify"
|
|
66
|
+
]
|
|
67
|
+
]
|
|
54
68
|
}
|
|
55
69
|
}
|