@astrox/connection 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +23 -0
- package/lib/cjs/canisters/internet_identity_idl.d.ts +7 -0
- package/lib/cjs/canisters/internet_identity_idl.js +101 -0
- package/lib/cjs/canisters/internet_identity_idl.js.map +1 -0
- package/lib/cjs/canisters/ledger.idl.d.ts +7 -0
- package/lib/cjs/canisters/ledger.idl.js +81 -0
- package/lib/cjs/canisters/ledger.idl.js.map +1 -0
- package/lib/cjs/canisters/me.idl.d.ts +7 -0
- package/lib/cjs/canisters/me.idl.js +125 -0
- package/lib/cjs/canisters/me.idl.js.map +1 -0
- package/lib/cjs/canisters/nns-dapp-cert.idl.d.ts +7 -0
- package/lib/cjs/canisters/nns-dapp-cert.idl.js +86 -0
- package/lib/cjs/canisters/nns-dapp-cert.idl.js.map +1 -0
- package/lib/cjs/canisters/nns-dapp.idl.d.ts +7 -0
- package/lib/cjs/canisters/nns-dapp.idl.js +184 -0
- package/lib/cjs/canisters/nns-dapp.idl.js.map +1 -0
- package/lib/cjs/connections/baseConnection.d.ts +52 -0
- package/lib/cjs/connections/baseConnection.js +87 -0
- package/lib/cjs/connections/baseConnection.js.map +1 -0
- package/lib/cjs/connections/ledgerConnection.d.ts +57 -0
- package/lib/cjs/connections/ledgerConnection.js +135 -0
- package/lib/cjs/connections/ledgerConnection.js.map +1 -0
- package/lib/cjs/connections/nnsConnection.d.ts +62 -0
- package/lib/cjs/connections/nnsConnection.js +166 -0
- package/lib/cjs/connections/nnsConnection.js.map +1 -0
- package/lib/cjs/ic/icAuthClient.d.ts +31 -0
- package/lib/cjs/ic/icAuthClient.js +233 -0
- package/lib/cjs/ic/icAuthClient.js.map +1 -0
- package/lib/cjs/ic/icConnect.d.ts +32 -0
- package/lib/cjs/ic/icConnect.js +181 -0
- package/lib/cjs/ic/icConnect.js.map +1 -0
- package/lib/cjs/ic/icStorage.d.ts +16 -0
- package/lib/cjs/ic/icStorage.js +49 -0
- package/lib/cjs/ic/icStorage.js.map +1 -0
- package/lib/cjs/ic/icWindow.d.ts +7 -0
- package/lib/cjs/ic/icWindow.js +20 -0
- package/lib/cjs/ic/icWindow.js.map +1 -0
- package/lib/cjs/ic/index.d.ts +2 -0
- package/lib/cjs/ic/index.js +7 -0
- package/lib/cjs/ic/index.js.map +1 -0
- package/lib/cjs/ic/types.d.ts +129 -0
- package/lib/cjs/ic/types.js +17 -0
- package/lib/cjs/ic/types.js.map +1 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +18 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/utils/common/types.d.ts +15 -0
- package/lib/cjs/utils/common/types.js +12 -0
- package/lib/cjs/utils/common/types.js.map +1 -0
- package/lib/cjs/utils/constants.d.ts +6 -0
- package/lib/cjs/utils/constants.js +13 -0
- package/lib/cjs/utils/constants.js.map +1 -0
- package/lib/cjs/utils/converter.d.ts +32 -0
- package/lib/cjs/utils/converter.js +130 -0
- package/lib/cjs/utils/converter.js.map +1 -0
- package/lib/cjs/utils/index.d.ts +3 -0
- package/lib/cjs/utils/index.js +16 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/esm/canisters/internet_identity_idl.d.ts +7 -0
- package/lib/esm/canisters/internet_identity_idl.js +98 -0
- package/lib/esm/canisters/internet_identity_idl.js.map +1 -0
- package/lib/esm/canisters/ledger.idl.d.ts +7 -0
- package/lib/esm/canisters/ledger.idl.js +78 -0
- package/lib/esm/canisters/ledger.idl.js.map +1 -0
- package/lib/esm/canisters/me.idl.d.ts +7 -0
- package/lib/esm/canisters/me.idl.js +122 -0
- package/lib/esm/canisters/me.idl.js.map +1 -0
- package/lib/esm/canisters/nns-dapp-cert.idl.d.ts +7 -0
- package/lib/esm/canisters/nns-dapp-cert.idl.js +83 -0
- package/lib/esm/canisters/nns-dapp-cert.idl.js.map +1 -0
- package/lib/esm/canisters/nns-dapp.idl.d.ts +7 -0
- package/lib/esm/canisters/nns-dapp.idl.js +181 -0
- package/lib/esm/canisters/nns-dapp.idl.js.map +1 -0
- package/lib/esm/connections/baseConnection.d.ts +52 -0
- package/lib/esm/connections/baseConnection.js +80 -0
- package/lib/esm/connections/baseConnection.js.map +1 -0
- package/lib/esm/connections/ledgerConnection.d.ts +57 -0
- package/lib/esm/connections/ledgerConnection.js +128 -0
- package/lib/esm/connections/ledgerConnection.js.map +1 -0
- package/lib/esm/connections/nnsConnection.d.ts +62 -0
- package/lib/esm/connections/nnsConnection.js +159 -0
- package/lib/esm/connections/nnsConnection.js.map +1 -0
- package/lib/esm/ic/icAuthClient.d.ts +31 -0
- package/lib/esm/ic/icAuthClient.js +229 -0
- package/lib/esm/ic/icAuthClient.js.map +1 -0
- package/lib/esm/ic/icConnect.d.ts +32 -0
- package/lib/esm/ic/icConnect.js +177 -0
- package/lib/esm/ic/icConnect.js.map +1 -0
- package/lib/esm/ic/icStorage.d.ts +16 -0
- package/lib/esm/ic/icStorage.js +44 -0
- package/lib/esm/ic/icStorage.js.map +1 -0
- package/lib/esm/ic/icWindow.d.ts +7 -0
- package/lib/esm/ic/icWindow.js +16 -0
- package/lib/esm/ic/icWindow.js.map +1 -0
- package/lib/esm/ic/index.d.ts +2 -0
- package/lib/esm/ic/index.js +3 -0
- package/lib/esm/ic/index.js.map +1 -0
- package/lib/esm/ic/types.d.ts +129 -0
- package/lib/esm/ic/types.js +14 -0
- package/lib/esm/ic/types.js.map +1 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/utils/common/types.d.ts +15 -0
- package/lib/esm/utils/common/types.js +9 -0
- package/lib/esm/utils/common/types.js.map +1 -0
- package/lib/esm/utils/constants.d.ts +6 -0
- package/lib/esm/utils/constants.js +10 -0
- package/lib/esm/utils/constants.js.map +1 -0
- package/lib/esm/utils/converter.d.ts +32 -0
- package/lib/esm/utils/converter.js +124 -0
- package/lib/esm/utils/converter.js.map +1 -0
- package/lib/esm/utils/index.d.ts +3 -0
- package/lib/esm/utils/index.js +4 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/tsconfig-cjs.tsbuildinfo +2834 -0
- package/lib/tsconfig.tsbuildinfo +2833 -0
- package/package.json +53 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
|
2
|
+
import { DelegationIdentity } from '@dfinity/identity';
|
3
|
+
import { BaseConnection, CreateActorResult } from './baseConnection';
|
4
|
+
import NNS_SERVICE, { AccountDetails } from '../canisters/nns-dapp';
|
5
|
+
export declare class NNSConnection extends BaseConnection<NNS_SERVICE> {
|
6
|
+
identity: SignIdentity;
|
7
|
+
delegationIdentity: DelegationIdentity;
|
8
|
+
actor?: ActorSubclass<NNS_SERVICE> | undefined;
|
9
|
+
agent?: HttpAgent | undefined;
|
10
|
+
get accountDetails(): AccountDetails | undefined;
|
11
|
+
private _accountDetails?;
|
12
|
+
protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE> | undefined, agent?: HttpAgent | undefined, nnsCanisterId?: string);
|
13
|
+
/**
|
14
|
+
* create connection
|
15
|
+
* @param identity
|
16
|
+
* @param delegationIdentity
|
17
|
+
* @param actor
|
18
|
+
* @param agent
|
19
|
+
* @function createConnection
|
20
|
+
* @returns {NNSConnection}
|
21
|
+
*/
|
22
|
+
static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE>, agent?: HttpAgent): NNSConnection;
|
23
|
+
/**
|
24
|
+
* create Actor with DelegationIdentity
|
25
|
+
* @param delegationIdentity
|
26
|
+
* @param nnsCanisterId
|
27
|
+
* @function {function name}
|
28
|
+
* @returns {type} {description}
|
29
|
+
*/
|
30
|
+
static createActor(delegationIdentity: DelegationIdentity, nnsCanisterId?: string): Promise<CreateActorResult<NNS_SERVICE>>;
|
31
|
+
/**
|
32
|
+
* get NNS Actor, used internally
|
33
|
+
* @param nnsCanisterId
|
34
|
+
* @function {function name}
|
35
|
+
* @returns {type} {description}
|
36
|
+
*/
|
37
|
+
getNNSActor(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
|
38
|
+
/**
|
39
|
+
* get NNS Actor, used internally
|
40
|
+
* @param nnsCanisterId
|
41
|
+
* @function {function name}
|
42
|
+
* @returns {type} {description}
|
43
|
+
*/
|
44
|
+
getNNSActorCert(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
|
45
|
+
/**
|
46
|
+
* when NNSConnection is created, we can get account created to NNS.
|
47
|
+
* Even we can just calculate the login principal to NNS DApp, however,
|
48
|
+
* The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
|
49
|
+
* We need to manually create account using `add_account` when no account found.
|
50
|
+
*
|
51
|
+
* @param cert
|
52
|
+
* @function {function name}
|
53
|
+
* @returns {type} {description}
|
54
|
+
*/
|
55
|
+
getAccount(cert?: boolean): Promise<AccountDetails | undefined>;
|
56
|
+
/**
|
57
|
+
* create account when new identity logined to NNS
|
58
|
+
* @function {function name}
|
59
|
+
* @returns {type} {description}
|
60
|
+
*/
|
61
|
+
addAccount(): Promise<string>;
|
62
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.NNSConnection = void 0;
|
7
|
+
const baseConnection_1 = require("./baseConnection");
|
8
|
+
const nns_dapp_idl_1 = __importDefault(require("../canisters/nns-dapp.idl"));
|
9
|
+
const nns_dapp_cert_idl_1 = __importDefault(require("../canisters/nns-dapp-cert.idl"));
|
10
|
+
const constants_1 = require("../utils/constants");
|
11
|
+
// const canisterId: string = process.env.NNS_CANISTER_ID!;
|
12
|
+
// const NNS_URL: string = process.env.NNS_URL!;
|
13
|
+
// export const canisterIdPrincipal: Principal = Principal.fromText(canisterId);
|
14
|
+
// const KEY_SESSIONSTORAGE_KEY = 'identity';
|
15
|
+
// const KEY_SESSIONSTORAGE_DELEGATION = 'delegation';
|
16
|
+
class NNSConnection extends baseConnection_1.BaseConnection {
|
17
|
+
constructor(identity, delegationIdentity, actor, agent, nnsCanisterId) {
|
18
|
+
super(identity, delegationIdentity, nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : constants_1.NNS_CANISTER_ID, nns_dapp_idl_1.default, actor, agent);
|
19
|
+
this.identity = identity;
|
20
|
+
this.delegationIdentity = delegationIdentity;
|
21
|
+
this.actor = actor;
|
22
|
+
this.agent = agent;
|
23
|
+
}
|
24
|
+
get accountDetails() {
|
25
|
+
return this._accountDetails;
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* create connection
|
29
|
+
* @param identity
|
30
|
+
* @param delegationIdentity
|
31
|
+
* @param actor
|
32
|
+
* @param agent
|
33
|
+
* @function createConnection
|
34
|
+
* @returns {NNSConnection}
|
35
|
+
*/
|
36
|
+
static createConnection(identity, delegationIdentity, actor, agent) {
|
37
|
+
return new NNSConnection(identity, delegationIdentity, actor, agent);
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* create Actor with DelegationIdentity
|
41
|
+
* @param delegationIdentity
|
42
|
+
* @param nnsCanisterId
|
43
|
+
* @function {function name}
|
44
|
+
* @returns {type} {description}
|
45
|
+
*/
|
46
|
+
static async createActor(delegationIdentity, nnsCanisterId) {
|
47
|
+
const actor = await baseConnection_1._createActor(nns_dapp_idl_1.default, nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : constants_1.NNS_CANISTER_ID, delegationIdentity);
|
48
|
+
return actor;
|
49
|
+
}
|
50
|
+
// /**
|
51
|
+
// * create connection with II, we need to login II before login to NNS
|
52
|
+
// * only when AstroX ME linked With II, use 2 params as input
|
53
|
+
// * 1. use Identity created by devices, not delegation
|
54
|
+
// * 2. use II anchor that linked, will ensure NNS Dapp get the correct principal
|
55
|
+
// *
|
56
|
+
// * @param identity
|
57
|
+
// * @param anchor
|
58
|
+
// * @function {function name}
|
59
|
+
// * @returns {type} {description}
|
60
|
+
// */
|
61
|
+
// static async createConnectionWithII(
|
62
|
+
// identity: SignIdentity,
|
63
|
+
// anchor: string | bigint,
|
64
|
+
// ): Promise<NNSConnection> {
|
65
|
+
// const key = Ed25519KeyIdentity.generate();
|
66
|
+
// const s = await iiDelegation(
|
67
|
+
// identity,
|
68
|
+
// new Uint8Array(key.getPublicKey().toDer()),
|
69
|
+
// anchor,
|
70
|
+
// NNS_URL,
|
71
|
+
// /* days */ BigInt(7) * /* hours */ BigInt(24) * /* nanoseconds */ BigInt(3600000000000),
|
72
|
+
// );
|
73
|
+
// const iiDelegationResult = {
|
74
|
+
// kind: 'authorize-client-success',
|
75
|
+
// delegations: [s],
|
76
|
+
// userPublicKey: Uint8Array.from(s.userKey),
|
77
|
+
// };
|
78
|
+
// const storage = new NNSStorage(anchor.toString());
|
79
|
+
// const delegations = iiDelegationResult.delegations.map(signedDelegation => {
|
80
|
+
// return {
|
81
|
+
// delegation: new Delegation(
|
82
|
+
// signedDelegation.delegation.pubkey.buffer,
|
83
|
+
// signedDelegation.delegation.expiration,
|
84
|
+
// signedDelegation.delegation.targets,
|
85
|
+
// ),
|
86
|
+
// signature: signedDelegation.signature.buffer as Signature,
|
87
|
+
// };
|
88
|
+
// });
|
89
|
+
// const delegationChain = DelegationChain.fromDelegations(
|
90
|
+
// delegations,
|
91
|
+
// iiDelegationResult.userPublicKey.buffer as DerEncodedPublicKey,
|
92
|
+
// );
|
93
|
+
// await storage.saveJson({
|
94
|
+
// delegationChain: delegationChain.toJSON(),
|
95
|
+
// key,
|
96
|
+
// });
|
97
|
+
// const delegationResult = (await handleDelegation(iiDelegationResult, key)) as DelegationResult;
|
98
|
+
// const actorResult = await NNSConnection.createActor(delegationResult.delegationIdentity);
|
99
|
+
// return NNSConnection.createConnection(
|
100
|
+
// identity,
|
101
|
+
// delegationResult.delegationIdentity,
|
102
|
+
// actorResult.actor,
|
103
|
+
// actorResult.agent,
|
104
|
+
// );
|
105
|
+
// }
|
106
|
+
/**
|
107
|
+
* get NNS Actor, used internally
|
108
|
+
* @param nnsCanisterId
|
109
|
+
* @function {function name}
|
110
|
+
* @returns {type} {description}
|
111
|
+
*/
|
112
|
+
async getNNSActor(nnsCanisterId) {
|
113
|
+
const actor = await this._getActor(nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : constants_1.NNS_CANISTER_ID, nns_dapp_idl_1.default);
|
114
|
+
return actor;
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* get NNS Actor, used internally
|
118
|
+
* @param nnsCanisterId
|
119
|
+
* @function {function name}
|
120
|
+
* @returns {type} {description}
|
121
|
+
*/
|
122
|
+
async getNNSActorCert(nnsCanisterId) {
|
123
|
+
const actor = await this._getActor(nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : constants_1.NNS_CANISTER_ID, nns_dapp_cert_idl_1.default);
|
124
|
+
return actor;
|
125
|
+
}
|
126
|
+
/**
|
127
|
+
* when NNSConnection is created, we can get account created to NNS.
|
128
|
+
* Even we can just calculate the login principal to NNS DApp, however,
|
129
|
+
* The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
|
130
|
+
* We need to manually create account using `add_account` when no account found.
|
131
|
+
*
|
132
|
+
* @param cert
|
133
|
+
* @function {function name}
|
134
|
+
* @returns {type} {description}
|
135
|
+
*/
|
136
|
+
async getAccount(cert) {
|
137
|
+
const actor = cert === true ? await this.getNNSActorCert() : await this.getNNSActor();
|
138
|
+
const response = await baseConnection_1.executeWithLogging(() => actor.get_account());
|
139
|
+
if (response === { AccountNotFound: null }) {
|
140
|
+
return undefined;
|
141
|
+
}
|
142
|
+
else {
|
143
|
+
this._accountDetails = response['Ok'];
|
144
|
+
return response['Ok'];
|
145
|
+
}
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* create account when new identity logined to NNS
|
149
|
+
* @function {function name}
|
150
|
+
* @returns {type} {description}
|
151
|
+
*/
|
152
|
+
async addAccount() {
|
153
|
+
const actor = await this.getNNSActor();
|
154
|
+
const response = await baseConnection_1.executeWithLogging(() => actor.add_account());
|
155
|
+
return response;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
exports.NNSConnection = NNSConnection;
|
159
|
+
// export const requestNNSDelegation = async (
|
160
|
+
// identity: SignIdentity,
|
161
|
+
// ): Promise<DelegationIdentity> => {
|
162
|
+
// const tenMinutesInMsec = 10 * 1000 * 60;
|
163
|
+
// const date = new Date(Date.now() + tenMinutesInMsec);
|
164
|
+
// return requestDelegation(identity, { canisterId, date });
|
165
|
+
// };
|
166
|
+
//# sourceMappingURL=nnsConnection.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"nnsConnection.js","sourceRoot":"","sources":["../../../src/connections/nnsConnection.ts"],"names":[],"mappings":";;;;;;AAWA,qDAK0B;AAC1B,6EAAgD;AAChD,uFAA0D;AAE1D,kDAAqD;AAErD,2DAA2D;AAC3D,gDAAgD;AAEhD,gFAAgF;AAEhF,6CAA6C;AAC7C,sDAAsD;AAEtD,MAAa,aAAc,SAAQ,+BAA2B;IAO5D,YACS,QAAsB,EACtB,kBAAsC,EACtC,KAAkC,EAClC,KAAiB,EACxB,aAAsB;QAEtB,KAAK,CAAC,QAAQ,EAAE,kBAAkB,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,2BAAe,EAAE,sBAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QANtF,aAAQ,GAAR,QAAQ,CAAc;QACtB,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,UAAK,GAAL,KAAK,CAA6B;QAClC,UAAK,GAAL,KAAK,CAAY;IAI1B,CAAC;IAdD,IAAW,cAAc;QACvB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAcD;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CACrB,QAAs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@ -0,0 +1,31 @@
|
|
1
|
+
import { Identity, SignIdentity } from '@dfinity/agent';
|
2
|
+
import { DelegationChain, DelegationIdentity } from '@dfinity/identity';
|
3
|
+
import { AuthClientCreateOptions, AuthClientLoginOptions, AuthClientStorage } from './types';
|
4
|
+
export declare class AuthClient {
|
5
|
+
private _identity;
|
6
|
+
private _key;
|
7
|
+
private _chain;
|
8
|
+
private _storage;
|
9
|
+
private _appId?;
|
10
|
+
private _wallet?;
|
11
|
+
private _idpWindowOption?;
|
12
|
+
private _idpWindow?;
|
13
|
+
private _eventHandler?;
|
14
|
+
static create(options?: AuthClientCreateOptions): Promise<AuthClient>;
|
15
|
+
private _delegationIdentity?;
|
16
|
+
protected constructor(_identity: Identity, _key: SignIdentity | null, _chain: DelegationChain | null, _storage: AuthClientStorage, _appId?: string | undefined, _wallet?: string | undefined, _idpWindowOption?: string | undefined, _idpWindow?: Window | undefined, _eventHandler?: ((event: MessageEvent) => void) | undefined);
|
17
|
+
private _handleSuccess;
|
18
|
+
getIdentity(): Identity;
|
19
|
+
getDelegationIdentity(): DelegationIdentity | undefined;
|
20
|
+
getInnerKey(): SignIdentity | null;
|
21
|
+
get wallet(): string | undefined;
|
22
|
+
setWallet(data: string): void;
|
23
|
+
isAuthenticated(): Promise<boolean>;
|
24
|
+
login(options?: AuthClientLoginOptions): Promise<void>;
|
25
|
+
private _getEventHandler;
|
26
|
+
private _handleFailure;
|
27
|
+
private _removeEventListener;
|
28
|
+
logout(options?: {
|
29
|
+
returnTo?: string;
|
30
|
+
}): Promise<void>;
|
31
|
+
}
|
@@ -0,0 +1,233 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AuthClient = void 0;
|
4
|
+
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
5
|
+
const agent_1 = require("@dfinity/agent");
|
6
|
+
const authentication_1 = require("@dfinity/authentication");
|
7
|
+
const identity_1 = require("@dfinity/identity");
|
8
|
+
const types_1 = require("./types");
|
9
|
+
const icStorage_1 = require("./icStorage");
|
10
|
+
class AuthClient {
|
11
|
+
constructor(_identity, _key, _chain, _storage, _appId, _wallet, _idpWindowOption,
|
12
|
+
// A handle on the IdP window.
|
13
|
+
_idpWindow,
|
14
|
+
// The event handler for processing events from the IdP.
|
15
|
+
_eventHandler) {
|
16
|
+
this._identity = _identity;
|
17
|
+
this._key = _key;
|
18
|
+
this._chain = _chain;
|
19
|
+
this._storage = _storage;
|
20
|
+
this._appId = _appId;
|
21
|
+
this._wallet = _wallet;
|
22
|
+
this._idpWindowOption = _idpWindowOption;
|
23
|
+
this._idpWindow = _idpWindow;
|
24
|
+
this._eventHandler = _eventHandler;
|
25
|
+
}
|
26
|
+
static async create(options = {
|
27
|
+
appId: '',
|
28
|
+
}) {
|
29
|
+
var _a, _b;
|
30
|
+
const storage = (_a = options.storage) !== null && _a !== void 0 ? _a : new icStorage_1.SessionStorage('ic-');
|
31
|
+
let key = null;
|
32
|
+
if (options.identity) {
|
33
|
+
key = options.identity;
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
const maybeIdentityStorage = await storage.get(icStorage_1.KEY_SESSIONSTORAGE_KEY);
|
37
|
+
if (maybeIdentityStorage) {
|
38
|
+
try {
|
39
|
+
key = identity_1.Ed25519KeyIdentity.fromJSON(maybeIdentityStorage);
|
40
|
+
}
|
41
|
+
catch (e) {
|
42
|
+
// Ignore this, this means that the sessionStorage value isn't a valid Ed25519KeyIdentity
|
43
|
+
// serialization.
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
let identity = new agent_1.AnonymousIdentity();
|
48
|
+
let chain = null;
|
49
|
+
let wallet = null;
|
50
|
+
if (key) {
|
51
|
+
try {
|
52
|
+
const chainStorage = await storage.get(icStorage_1.KEY_SESSIONSTORAGE_DELEGATION);
|
53
|
+
wallet = await storage.get(icStorage_1.KEY_SESSIONSTORAGE_WALLET);
|
54
|
+
if (chainStorage) {
|
55
|
+
chain = identity_1.DelegationChain.fromJSON(chainStorage);
|
56
|
+
// Verify that the delegation isn't expired.
|
57
|
+
if (!authentication_1.isDelegationValid(chain)) {
|
58
|
+
await icStorage_1._deleteStorage(storage);
|
59
|
+
key = null;
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
identity = identity_1.DelegationIdentity.fromDelegation(key, chain);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
catch (e) {
|
67
|
+
console.error(e);
|
68
|
+
// If there was a problem loading the chain, delete the key.
|
69
|
+
await icStorage_1._deleteStorage(storage);
|
70
|
+
key = null;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return new this(identity, key, chain, storage, options.appId, wallet !== null ? wallet : undefined, (_b = options.idpWindowOption) !== null && _b !== void 0 ? _b : 'height=600, width=800, top=0, right=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
|
74
|
+
}
|
75
|
+
async _handleSuccess(message, onSuccess) {
|
76
|
+
var _a;
|
77
|
+
// console.log(message["identity"]);
|
78
|
+
if (message['identity'] !== undefined) {
|
79
|
+
const idDelegations = message['identity'].delegations.map(signedDelegation => {
|
80
|
+
return {
|
81
|
+
delegation: new identity_1.Delegation(signedDelegation.delegation.pubkey.buffer, signedDelegation.delegation.expiration, signedDelegation.delegation.targets),
|
82
|
+
signature: signedDelegation.signature.buffer,
|
83
|
+
};
|
84
|
+
});
|
85
|
+
const idDelegationChain = identity_1.DelegationChain.fromDelegations(idDelegations, message['identity'].userPublicKey
|
86
|
+
.buffer);
|
87
|
+
this._chain = idDelegationChain;
|
88
|
+
this._wallet = message['wallet'];
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
const iiDelegations = message.delegations.map(signedDelegation => {
|
92
|
+
return {
|
93
|
+
delegation: new identity_1.Delegation(signedDelegation.delegation.pubkey.buffer, signedDelegation.delegation.expiration, signedDelegation.delegation.targets),
|
94
|
+
signature: signedDelegation.signature.buffer,
|
95
|
+
};
|
96
|
+
});
|
97
|
+
const iiDelegationChain = identity_1.DelegationChain.fromDelegations(iiDelegations, message.userPublicKey.buffer);
|
98
|
+
this._chain = iiDelegationChain;
|
99
|
+
}
|
100
|
+
const key = this._key;
|
101
|
+
if (!key) {
|
102
|
+
return this;
|
103
|
+
}
|
104
|
+
this._delegationIdentity = identity_1.DelegationIdentity.fromDelegation(key, this._chain);
|
105
|
+
this._identity = this._delegationIdentity;
|
106
|
+
console.log(this._identity);
|
107
|
+
(_a = this._idpWindow) === null || _a === void 0 ? void 0 : _a.close();
|
108
|
+
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess());
|
109
|
+
this._removeEventListener();
|
110
|
+
return this;
|
111
|
+
}
|
112
|
+
getIdentity() {
|
113
|
+
return this._identity;
|
114
|
+
}
|
115
|
+
getDelegationIdentity() {
|
116
|
+
return this._delegationIdentity;
|
117
|
+
}
|
118
|
+
getInnerKey() {
|
119
|
+
return this._key;
|
120
|
+
}
|
121
|
+
get wallet() {
|
122
|
+
return this._wallet;
|
123
|
+
}
|
124
|
+
setWallet(data) {
|
125
|
+
this._wallet = data;
|
126
|
+
}
|
127
|
+
async isAuthenticated() {
|
128
|
+
return !this.getIdentity().getPrincipal().isAnonymous() && this._chain !== null;
|
129
|
+
}
|
130
|
+
async login(options) {
|
131
|
+
var _a, _b, _c;
|
132
|
+
let key = this._key;
|
133
|
+
if (!key) {
|
134
|
+
// Create a new key (whether or not one was in storage).
|
135
|
+
key = identity_1.Ed25519KeyIdentity.generate();
|
136
|
+
this._key = key;
|
137
|
+
await this._storage.set(icStorage_1.KEY_SESSIONSTORAGE_KEY, JSON.stringify(key));
|
138
|
+
}
|
139
|
+
// Create the URL of the IDP. (e.g. https://XXXX/#authorize)
|
140
|
+
const identityProviderUrl = new URL(((_a = options === null || options === void 0 ? void 0 : options.identityProvider) === null || _a === void 0 ? void 0 : _a.toString()) || icStorage_1.IDENTITY_PROVIDER_DEFAULT);
|
141
|
+
// Set the correct hash if it isn't already set.
|
142
|
+
identityProviderUrl.hash = icStorage_1.IDENTITY_PROVIDER_ENDPOINT;
|
143
|
+
// If `login` has been called previously, then close/remove any previous windows
|
144
|
+
// and event listeners.
|
145
|
+
(_b = this._idpWindow) === null || _b === void 0 ? void 0 : _b.close();
|
146
|
+
this._removeEventListener();
|
147
|
+
// Open a new window with the IDP provider.
|
148
|
+
this._idpWindow = (_c = window.open(identityProviderUrl.toString(), 'idpWindow', this._idpWindowOption)) !== null && _c !== void 0 ? _c : undefined;
|
149
|
+
// Add an event listener to handle responses.
|
150
|
+
return new Promise((resolve, reject) => {
|
151
|
+
this._eventHandler = this._getEventHandler(identityProviderUrl, resolve, reject, options);
|
152
|
+
window.addEventListener('message', this._eventHandler);
|
153
|
+
});
|
154
|
+
}
|
155
|
+
_getEventHandler(identityProviderUrl, resolve, reject, options) {
|
156
|
+
return async (event) => {
|
157
|
+
var _a, _b, _c;
|
158
|
+
if (event.origin !== identityProviderUrl.origin) {
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
const message = event.data;
|
162
|
+
switch (message.kind) {
|
163
|
+
case 'authorize-ready': {
|
164
|
+
// IDP is ready. Send a message to request authorization.
|
165
|
+
const request = {
|
166
|
+
kind: 'authorize-client',
|
167
|
+
sessionPublicKey: new Uint8Array((_a = this._key) === null || _a === void 0 ? void 0 : _a.getPublicKey().toDer()),
|
168
|
+
maxTimeToLive: options === null || options === void 0 ? void 0 : options.maxTimeToLive,
|
169
|
+
permissions: (_b = options === null || options === void 0 ? void 0 : options.permissions) !== null && _b !== void 0 ? _b : [types_1.PermissionsType.identity],
|
170
|
+
appId: this._appId,
|
171
|
+
};
|
172
|
+
(_c = this._idpWindow) === null || _c === void 0 ? void 0 : _c.postMessage(request, identityProviderUrl.origin);
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
case 'authorize-client-success':
|
176
|
+
// Create the delegation chain and store it.
|
177
|
+
try {
|
178
|
+
resolve(await this._handleSuccess(message, options === null || options === void 0 ? void 0 : options.onSuccess));
|
179
|
+
// Setting the storage is moved out of _handleSuccess to make
|
180
|
+
// it a sync function. Having _handleSuccess as an async function
|
181
|
+
// messes up the jest tests for some reason.
|
182
|
+
if (this._chain) {
|
183
|
+
await this._storage.set(icStorage_1.KEY_SESSIONSTORAGE_DELEGATION, JSON.stringify(this._chain.toJSON()));
|
184
|
+
}
|
185
|
+
if (this._wallet !== undefined) {
|
186
|
+
await this._storage.set(icStorage_1.KEY_SESSIONSTORAGE_WALLET, this._wallet);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
catch (err) {
|
190
|
+
reject(this._handleFailure(err.message, options === null || options === void 0 ? void 0 : options.onError));
|
191
|
+
}
|
192
|
+
break;
|
193
|
+
case 'authorize-client-failure':
|
194
|
+
reject(this._handleFailure(message.text, options === null || options === void 0 ? void 0 : options.onError));
|
195
|
+
break;
|
196
|
+
default:
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
};
|
200
|
+
}
|
201
|
+
_handleFailure(errorMessage, onError) {
|
202
|
+
var _a;
|
203
|
+
(_a = this._idpWindow) === null || _a === void 0 ? void 0 : _a.close();
|
204
|
+
onError === null || onError === void 0 ? void 0 : onError(errorMessage);
|
205
|
+
this._removeEventListener();
|
206
|
+
return errorMessage;
|
207
|
+
}
|
208
|
+
_removeEventListener() {
|
209
|
+
if (this._eventHandler) {
|
210
|
+
window.removeEventListener('message', this._eventHandler);
|
211
|
+
}
|
212
|
+
this._eventHandler = undefined;
|
213
|
+
}
|
214
|
+
async logout(options = {}) {
|
215
|
+
icStorage_1._deleteStorage(this._storage);
|
216
|
+
// Reset this auth client to a non-authenticated state.
|
217
|
+
this._identity = new agent_1.AnonymousIdentity();
|
218
|
+
this._key = null;
|
219
|
+
this._chain = null;
|
220
|
+
this._wallet = undefined;
|
221
|
+
if (options.returnTo) {
|
222
|
+
try {
|
223
|
+
window.history.pushState({}, '', options.returnTo);
|
224
|
+
}
|
225
|
+
catch (e) {
|
226
|
+
window.location.href = options.returnTo;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
230
|
+
}
|
231
|
+
exports.AuthClient = AuthClient;
|
232
|
+
//
|
233
|
+
//# sourceMappingURL=icAuthClient.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"icAuthClient.js","sourceRoot":"","sources":["../../../src/ic/icAuthClient.ts"],"names":[],"mappings":";;;AAAA,2EAA2E;AAC3E,0CAMwB;AACxB,4DAA4D;AAC5D,gDAK2B;AAC3B,mCAWiB;AACjB,2CAQqB;AAErB,MAAa,UAAU;IAkErB,YACU,SAAmB,EACnB,IAAyB,EACzB,MAA8B,EAC9B,QAA2B,EAC3B,MAAe,EACf,OAAgB,EAChB,gBAAyB;IACjC,8BAA8B;IACtB,UAAmB;IAC3B,wDAAwD;IAChD,aAA6C;QAV7C,cAAS,GAAT,SAAS,CAAU;QACnB,SAAI,GAAJ,IAAI,CAAqB;QACzB,WAAM,GAAN,MAAM,CAAwB;QAC9B,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAS;QAChB,qBAAgB,GAAhB,gBAAgB,CAAS;QAEzB,eAAU,GAAV,UAAU,CAAS;QAEnB,kBAAa,GAAb,aAAa,CAAgC;IACpD,CAAC;IA7EG,MAAM,CAAC,KAAK,CAAC,MAAM,CACxB,UAAmC;QACjC,KAAK,EAAE,EAAE;KACV;;QAED,MAAM,OAAO,SAAG,OAAO,CAAC,OAAO,mCAAI,IAAI,0BAAc,CAAC,KAAK,CAAC,CAAC;QAE7D,IAAI,GAAG,GAAwB,IAAI,CAAC;QACpC,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;SACxB;aAAM;YACL,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kCAAsB,CAAC,CAAC;YAEvE,IAAI,oBAAoB,EAAE;gBACxB,IAAI;oBACF,GAAG,GAAG,6BAAkB,CAAC,QAAQ,CAAC,oBAAoB,CAA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ity/candid/lib/cjs/idl';
|
3
|
+
import { Principal } from '@dfinity/principal';
|
4
|
+
import { AuthClient } from './icAuthClient';
|
5
|
+
import { ICWindow } from './icWindow';
|
6
|
+
import { ConnectOptions, TransactionOptions } from './types';
|
7
|
+
declare global {
|
8
|
+
interface Window {
|
9
|
+
ic: IC & any;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
export declare class IC extends ICWindow {
|
13
|
+
#private;
|
14
|
+
static connect(connectOptions: ConnectOptions): Promise<IC>;
|
15
|
+
protected constructor(authClient: AuthClient);
|
16
|
+
isAuthenticated(): Promise<boolean>;
|
17
|
+
get identity(): Identity;
|
18
|
+
get principal(): Principal;
|
19
|
+
get wallet(): string | undefined;
|
20
|
+
protected getAuthClient(): AuthClient;
|
21
|
+
disconnect: (options?: {
|
22
|
+
returnTo?: string;
|
23
|
+
}) => Promise<void>;
|
24
|
+
queryBalance: () => Promise<bigint>;
|
25
|
+
handleAuthenticated: (ic: IC) => Promise<IC>;
|
26
|
+
private injectWindow;
|
27
|
+
handleError(error?: string): void;
|
28
|
+
createActor: <T>(idlFactory: InterfaceFactory, canisterId: string) => ActorSubclass<T>;
|
29
|
+
requestTransfer: (options: TransactionOptions) => Promise<void>;
|
30
|
+
private _getEventHandler;
|
31
|
+
private _handleFailure;
|
32
|
+
}
|