@astrox/connection 0.0.16 → 0.0.24
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/lib/tsconfig.tsbuildinfo +1 -2838
- package/package.json +2 -2
- package/lib/cjs/canisters/internet_identity_idl.d.ts +0 -7
- package/lib/cjs/canisters/internet_identity_idl.js +0 -101
- package/lib/cjs/canisters/internet_identity_idl.js.map +0 -1
- package/lib/cjs/canisters/ledger.idl.d.ts +0 -7
- package/lib/cjs/canisters/ledger.idl.js +0 -81
- package/lib/cjs/canisters/ledger.idl.js.map +0 -1
- package/lib/cjs/canisters/me.idl.d.ts +0 -7
- package/lib/cjs/canisters/me.idl.js +0 -125
- package/lib/cjs/canisters/me.idl.js.map +0 -1
- package/lib/cjs/canisters/nns-dapp-cert.idl.d.ts +0 -7
- package/lib/cjs/canisters/nns-dapp-cert.idl.js +0 -86
- package/lib/cjs/canisters/nns-dapp-cert.idl.js.map +0 -1
- package/lib/cjs/canisters/nns-dapp.idl.d.ts +0 -7
- package/lib/cjs/canisters/nns-dapp.idl.js +0 -184
- package/lib/cjs/canisters/nns-dapp.idl.js.map +0 -1
- package/lib/cjs/connections/baseConnection.d.ts +0 -23
- package/lib/cjs/connections/baseConnection.js +0 -87
- package/lib/cjs/connections/baseConnection.js.map +0 -1
- package/lib/cjs/connections/ledgerConnection.d.ts +0 -53
- package/lib/cjs/connections/ledgerConnection.js +0 -137
- package/lib/cjs/connections/ledgerConnection.js.map +0 -1
- package/lib/cjs/connections/nnsConnection.d.ts +0 -63
- package/lib/cjs/connections/nnsConnection.js +0 -166
- package/lib/cjs/connections/nnsConnection.js.map +0 -1
- package/lib/cjs/ic/icAuthClient.d.ts +0 -31
- package/lib/cjs/ic/icAuthClient.js +0 -233
- package/lib/cjs/ic/icAuthClient.js.map +0 -1
- package/lib/cjs/ic/icConnect.d.ts +0 -34
- package/lib/cjs/ic/icConnect.js +0 -184
- package/lib/cjs/ic/icConnect.js.map +0 -1
- package/lib/cjs/ic/icStorage.d.ts +0 -16
- package/lib/cjs/ic/icStorage.js +0 -49
- package/lib/cjs/ic/icStorage.js.map +0 -1
- package/lib/cjs/ic/icWindow.d.ts +0 -7
- package/lib/cjs/ic/icWindow.js +0 -20
- package/lib/cjs/ic/icWindow.js.map +0 -1
- package/lib/cjs/ic/index.d.ts +0 -2
- package/lib/cjs/ic/index.js +0 -7
- package/lib/cjs/ic/index.js.map +0 -1
- package/lib/cjs/ic/types.d.ts +0 -129
- package/lib/cjs/ic/types.js +0 -17
- package/lib/cjs/ic/types.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -5
- package/lib/cjs/index.js +0 -18
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/types/index.d.ts +0 -166
- package/lib/cjs/types/index.js +0 -17
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/utils/common/types.d.ts +0 -15
- package/lib/cjs/utils/common/types.js +0 -12
- package/lib/cjs/utils/common/types.js.map +0 -1
- package/lib/cjs/utils/constants.d.ts +0 -6
- package/lib/cjs/utils/constants.js +0 -13
- package/lib/cjs/utils/constants.js.map +0 -1
- package/lib/cjs/utils/converter.d.ts +0 -32
- package/lib/cjs/utils/converter.js +0 -130
- package/lib/cjs/utils/converter.js.map +0 -1
- package/lib/cjs/utils/index.d.ts +0 -3
- package/lib/cjs/utils/index.js +0 -16
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/esm/canisters/internet_identity_idl.d.ts +0 -7
- package/lib/esm/canisters/internet_identity_idl.js +0 -98
- package/lib/esm/canisters/internet_identity_idl.js.map +0 -1
- package/lib/esm/canisters/ledger.idl.d.ts +0 -7
- package/lib/esm/canisters/ledger.idl.js +0 -78
- package/lib/esm/canisters/ledger.idl.js.map +0 -1
- package/lib/esm/canisters/me.idl.d.ts +0 -7
- package/lib/esm/canisters/me.idl.js +0 -122
- package/lib/esm/canisters/me.idl.js.map +0 -1
- package/lib/esm/canisters/nns-dapp-cert.idl.d.ts +0 -7
- package/lib/esm/canisters/nns-dapp-cert.idl.js +0 -83
- package/lib/esm/canisters/nns-dapp-cert.idl.js.map +0 -1
- package/lib/esm/canisters/nns-dapp.idl.d.ts +0 -7
- package/lib/esm/canisters/nns-dapp.idl.js +0 -181
- package/lib/esm/canisters/nns-dapp.idl.js.map +0 -1
- package/lib/esm/connections/baseConnection.d.ts +0 -23
- package/lib/esm/connections/baseConnection.js +0 -80
- package/lib/esm/connections/baseConnection.js.map +0 -1
- package/lib/esm/connections/ledgerConnection.d.ts +0 -53
- package/lib/esm/connections/ledgerConnection.js +0 -130
- package/lib/esm/connections/ledgerConnection.js.map +0 -1
- package/lib/esm/connections/nnsConnection.d.ts +0 -63
- package/lib/esm/connections/nnsConnection.js +0 -159
- package/lib/esm/connections/nnsConnection.js.map +0 -1
- package/lib/esm/ic/icAuthClient.d.ts +0 -31
- package/lib/esm/ic/icAuthClient.js +0 -229
- package/lib/esm/ic/icAuthClient.js.map +0 -1
- package/lib/esm/ic/icConnect.d.ts +0 -34
- package/lib/esm/ic/icConnect.js +0 -180
- package/lib/esm/ic/icConnect.js.map +0 -1
- package/lib/esm/ic/icStorage.d.ts +0 -16
- package/lib/esm/ic/icStorage.js +0 -44
- package/lib/esm/ic/icStorage.js.map +0 -1
- package/lib/esm/ic/icWindow.d.ts +0 -7
- package/lib/esm/ic/icWindow.js +0 -16
- package/lib/esm/ic/icWindow.js.map +0 -1
- package/lib/esm/ic/index.d.ts +0 -2
- package/lib/esm/ic/index.js +0 -3
- package/lib/esm/ic/index.js.map +0 -1
- package/lib/esm/ic/types.d.ts +0 -129
- package/lib/esm/ic/types.js +0 -14
- package/lib/esm/ic/types.js.map +0 -1
- package/lib/esm/index.d.ts +0 -5
- package/lib/esm/index.js +0 -6
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/index.d.ts +0 -166
- package/lib/esm/types/index.js +0 -14
- package/lib/esm/types/index.js.map +0 -1
- package/lib/esm/utils/common/types.d.ts +0 -15
- package/lib/esm/utils/common/types.js +0 -9
- package/lib/esm/utils/common/types.js.map +0 -1
- package/lib/esm/utils/constants.d.ts +0 -6
- package/lib/esm/utils/constants.js +0 -10
- package/lib/esm/utils/constants.js.map +0 -1
- package/lib/esm/utils/converter.d.ts +0 -32
- package/lib/esm/utils/converter.js +0 -124
- package/lib/esm/utils/converter.js.map +0 -1
- package/lib/esm/utils/index.d.ts +0 -3
- package/lib/esm/utils/index.js +0 -4
- package/lib/esm/utils/index.js.map +0 -1
- package/lib/tsconfig-cjs.tsbuildinfo +0 -2839
@@ -1,63 +0,0 @@
|
|
1
|
-
import { ActorSubclass, HttpAgent, SignIdentity } from '@dfinity/agent';
|
2
|
-
import { DelegationIdentity } from '@dfinity/identity';
|
3
|
-
import { BaseConnection } from './baseConnection';
|
4
|
-
import NNS_SERVICE, { AccountDetails } from '../canisters/nns-dapp';
|
5
|
-
import { CreateActorResult } from '../types';
|
6
|
-
export declare class NNSConnection extends BaseConnection<NNS_SERVICE> {
|
7
|
-
identity: SignIdentity;
|
8
|
-
delegationIdentity: DelegationIdentity;
|
9
|
-
actor?: ActorSubclass<NNS_SERVICE> | undefined;
|
10
|
-
agent?: HttpAgent | undefined;
|
11
|
-
get accountDetails(): AccountDetails | undefined;
|
12
|
-
private _accountDetails?;
|
13
|
-
protected constructor(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE> | undefined, agent?: HttpAgent | undefined, nnsCanisterId?: string);
|
14
|
-
/**
|
15
|
-
* create connection
|
16
|
-
* @param identity
|
17
|
-
* @param delegationIdentity
|
18
|
-
* @param actor
|
19
|
-
* @param agent
|
20
|
-
* @function createConnection
|
21
|
-
* @returns {NNSConnection}
|
22
|
-
*/
|
23
|
-
static createConnection(identity: SignIdentity, delegationIdentity: DelegationIdentity, actor?: ActorSubclass<NNS_SERVICE>, agent?: HttpAgent): NNSConnection;
|
24
|
-
/**
|
25
|
-
* create Actor with DelegationIdentity
|
26
|
-
* @param delegationIdentity
|
27
|
-
* @param nnsCanisterId
|
28
|
-
* @function {function name}
|
29
|
-
* @returns {type} {description}
|
30
|
-
*/
|
31
|
-
static createActor(delegationIdentity: DelegationIdentity, nnsCanisterId?: string): Promise<CreateActorResult<NNS_SERVICE>>;
|
32
|
-
/**
|
33
|
-
* get NNS Actor, used internally
|
34
|
-
* @param nnsCanisterId
|
35
|
-
* @function {function name}
|
36
|
-
* @returns {type} {description}
|
37
|
-
*/
|
38
|
-
getNNSActor(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
|
39
|
-
/**
|
40
|
-
* get NNS Actor, used internally
|
41
|
-
* @param nnsCanisterId
|
42
|
-
* @function {function name}
|
43
|
-
* @returns {type} {description}
|
44
|
-
*/
|
45
|
-
getNNSActorCert(nnsCanisterId?: string): Promise<ActorSubclass<NNS_SERVICE>>;
|
46
|
-
/**
|
47
|
-
* when NNSConnection is created, we can get account created to NNS.
|
48
|
-
* Even we can just calculate the login principal to NNS DApp, however,
|
49
|
-
* The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
|
50
|
-
* We need to manually create account using `add_account` when no account found.
|
51
|
-
*
|
52
|
-
* @param cert
|
53
|
-
* @function {function name}
|
54
|
-
* @returns {type} {description}
|
55
|
-
*/
|
56
|
-
getAccount(cert?: boolean): Promise<AccountDetails | undefined>;
|
57
|
-
/**
|
58
|
-
* create account when new identity logined to NNS
|
59
|
-
* @function {function name}
|
60
|
-
* @returns {type} {description}
|
61
|
-
*/
|
62
|
-
addAccount(): Promise<string>;
|
63
|
-
}
|
@@ -1,159 +0,0 @@
|
|
1
|
-
import { BaseConnection, executeWithLogging, _createActor } from './baseConnection';
|
2
|
-
import nns_idl from '../canisters/nns-dapp.idl';
|
3
|
-
import nns_idl_cert from '../canisters/nns-dapp-cert.idl';
|
4
|
-
import { NNS_CANISTER_ID } from '../utils/constants';
|
5
|
-
// const canisterId: string = process.env.NNS_CANISTER_ID!;
|
6
|
-
// const NNS_URL: string = process.env.NNS_URL!;
|
7
|
-
// export const canisterIdPrincipal: Principal = Principal.fromText(canisterId);
|
8
|
-
// const KEY_SESSIONSTORAGE_KEY = 'identity';
|
9
|
-
// const KEY_SESSIONSTORAGE_DELEGATION = 'delegation';
|
10
|
-
export class NNSConnection extends BaseConnection {
|
11
|
-
constructor(identity, delegationIdentity, actor, agent, nnsCanisterId) {
|
12
|
-
super(identity, delegationIdentity, nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : NNS_CANISTER_ID, nns_idl, actor, agent);
|
13
|
-
this.identity = identity;
|
14
|
-
this.delegationIdentity = delegationIdentity;
|
15
|
-
this.actor = actor;
|
16
|
-
this.agent = agent;
|
17
|
-
}
|
18
|
-
get accountDetails() {
|
19
|
-
return this._accountDetails;
|
20
|
-
}
|
21
|
-
/**
|
22
|
-
* create connection
|
23
|
-
* @param identity
|
24
|
-
* @param delegationIdentity
|
25
|
-
* @param actor
|
26
|
-
* @param agent
|
27
|
-
* @function createConnection
|
28
|
-
* @returns {NNSConnection}
|
29
|
-
*/
|
30
|
-
static createConnection(identity, delegationIdentity, actor, agent) {
|
31
|
-
return new NNSConnection(identity, delegationIdentity, actor, agent);
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* create Actor with DelegationIdentity
|
35
|
-
* @param delegationIdentity
|
36
|
-
* @param nnsCanisterId
|
37
|
-
* @function {function name}
|
38
|
-
* @returns {type} {description}
|
39
|
-
*/
|
40
|
-
static async createActor(delegationIdentity, nnsCanisterId) {
|
41
|
-
const actor = await _createActor(nns_idl, nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : NNS_CANISTER_ID, delegationIdentity);
|
42
|
-
return actor;
|
43
|
-
}
|
44
|
-
// /**
|
45
|
-
// * create connection with II, we need to login II before login to NNS
|
46
|
-
// * only when AstroX ME linked With II, use 2 params as input
|
47
|
-
// * 1. use Identity created by devices, not delegation
|
48
|
-
// * 2. use II anchor that linked, will ensure NNS Dapp get the correct principal
|
49
|
-
// *
|
50
|
-
// * @param identity
|
51
|
-
// * @param anchor
|
52
|
-
// * @function {function name}
|
53
|
-
// * @returns {type} {description}
|
54
|
-
// */
|
55
|
-
// static async createConnectionWithII(
|
56
|
-
// identity: SignIdentity,
|
57
|
-
// anchor: string | bigint,
|
58
|
-
// ): Promise<NNSConnection> {
|
59
|
-
// const key = Ed25519KeyIdentity.generate();
|
60
|
-
// const s = await iiDelegation(
|
61
|
-
// identity,
|
62
|
-
// new Uint8Array(key.getPublicKey().toDer()),
|
63
|
-
// anchor,
|
64
|
-
// NNS_URL,
|
65
|
-
// /* days */ BigInt(7) * /* hours */ BigInt(24) * /* nanoseconds */ BigInt(3600000000000),
|
66
|
-
// );
|
67
|
-
// const iiDelegationResult = {
|
68
|
-
// kind: 'authorize-client-success',
|
69
|
-
// delegations: [s],
|
70
|
-
// userPublicKey: Uint8Array.from(s.userKey),
|
71
|
-
// };
|
72
|
-
// const storage = new NNSStorage(anchor.toString());
|
73
|
-
// const delegations = iiDelegationResult.delegations.map(signedDelegation => {
|
74
|
-
// return {
|
75
|
-
// delegation: new Delegation(
|
76
|
-
// signedDelegation.delegation.pubkey.buffer,
|
77
|
-
// signedDelegation.delegation.expiration,
|
78
|
-
// signedDelegation.delegation.targets,
|
79
|
-
// ),
|
80
|
-
// signature: signedDelegation.signature.buffer as Signature,
|
81
|
-
// };
|
82
|
-
// });
|
83
|
-
// const delegationChain = DelegationChain.fromDelegations(
|
84
|
-
// delegations,
|
85
|
-
// iiDelegationResult.userPublicKey.buffer as DerEncodedPublicKey,
|
86
|
-
// );
|
87
|
-
// await storage.saveJson({
|
88
|
-
// delegationChain: delegationChain.toJSON(),
|
89
|
-
// key,
|
90
|
-
// });
|
91
|
-
// const delegationResult = (await handleDelegation(iiDelegationResult, key)) as DelegationResult;
|
92
|
-
// const actorResult = await NNSConnection.createActor(delegationResult.delegationIdentity);
|
93
|
-
// return NNSConnection.createConnection(
|
94
|
-
// identity,
|
95
|
-
// delegationResult.delegationIdentity,
|
96
|
-
// actorResult.actor,
|
97
|
-
// actorResult.agent,
|
98
|
-
// );
|
99
|
-
// }
|
100
|
-
/**
|
101
|
-
* get NNS Actor, used internally
|
102
|
-
* @param nnsCanisterId
|
103
|
-
* @function {function name}
|
104
|
-
* @returns {type} {description}
|
105
|
-
*/
|
106
|
-
async getNNSActor(nnsCanisterId) {
|
107
|
-
const actor = await this._getActor(nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : NNS_CANISTER_ID, nns_idl);
|
108
|
-
return actor;
|
109
|
-
}
|
110
|
-
/**
|
111
|
-
* get NNS Actor, used internally
|
112
|
-
* @param nnsCanisterId
|
113
|
-
* @function {function name}
|
114
|
-
* @returns {type} {description}
|
115
|
-
*/
|
116
|
-
async getNNSActorCert(nnsCanisterId) {
|
117
|
-
const actor = await this._getActor(nnsCanisterId !== null && nnsCanisterId !== void 0 ? nnsCanisterId : NNS_CANISTER_ID, nns_idl_cert);
|
118
|
-
return actor;
|
119
|
-
}
|
120
|
-
/**
|
121
|
-
* when NNSConnection is created, we can get account created to NNS.
|
122
|
-
* Even we can just calculate the login principal to NNS DApp, however,
|
123
|
-
* The NNS DApp stores and create account, thus, a new Identity login will get NO ACCOUNT created by default.
|
124
|
-
* We need to manually create account using `add_account` when no account found.
|
125
|
-
*
|
126
|
-
* @param cert
|
127
|
-
* @function {function name}
|
128
|
-
* @returns {type} {description}
|
129
|
-
*/
|
130
|
-
async getAccount(cert) {
|
131
|
-
const actor = cert === true ? await this.getNNSActorCert() : await this.getNNSActor();
|
132
|
-
const response = await executeWithLogging(() => actor.get_account());
|
133
|
-
if (response === { AccountNotFound: null }) {
|
134
|
-
return undefined;
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
this._accountDetails = response['Ok'];
|
138
|
-
return response['Ok'];
|
139
|
-
}
|
140
|
-
}
|
141
|
-
/**
|
142
|
-
* create account when new identity logined to NNS
|
143
|
-
* @function {function name}
|
144
|
-
* @returns {type} {description}
|
145
|
-
*/
|
146
|
-
async addAccount() {
|
147
|
-
const actor = await this.getNNSActor();
|
148
|
-
const response = await executeWithLogging(() => actor.add_account());
|
149
|
-
return response;
|
150
|
-
}
|
151
|
-
}
|
152
|
-
// export const requestNNSDelegation = async (
|
153
|
-
// identity: SignIdentity,
|
154
|
-
// ): Promise<DelegationIdentity> => {
|
155
|
-
// const tenMinutesInMsec = 10 * 1000 * 60;
|
156
|
-
// const date = new Date(Date.now() + tenMinutesInMsec);
|
157
|
-
// return requestDelegation(identity, { canisterId, date });
|
158
|
-
// };
|
159
|
-
//# sourceMappingURL=nnsConnection.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"nnsConnection.js","sourceRoot":"","sources":["../../../src/connections/nnsConnection.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAChD,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,2DAA2D;AAC3D,gDAAgD;AAEhD,gFAAgF;AAEhF,6CAA6C;AAC7C,sDAAsD;AAEtD,MAAM,OAAO,aAAc,SAAQ,cAA2B;IAO5D,YACS,QAAsB,EACtB,kBAAsC,EACtC,KAAkC,EAClC,KAAiB,EACxB,aAAsB;QAEtB,KAAK,CAAC,QAAQ,EAAE,kBAAkB,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,eAAe,EAAE,OAAO,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;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KAAK"}
|
@@ -1,31 +0,0 @@
|
|
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
|
-
}
|
@@ -1,229 +0,0 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
2
|
-
import { AnonymousIdentity, } from '@dfinity/agent';
|
3
|
-
import { isDelegationValid } from '@dfinity/authentication';
|
4
|
-
import { Delegation, DelegationChain, DelegationIdentity, Ed25519KeyIdentity, } from '@dfinity/identity';
|
5
|
-
import { PermissionsType, } from '../types';
|
6
|
-
import { IDENTITY_PROVIDER_DEFAULT, IDENTITY_PROVIDER_ENDPOINT, KEY_SESSIONSTORAGE_DELEGATION, KEY_SESSIONSTORAGE_KEY, KEY_SESSIONSTORAGE_WALLET, SessionStorage, _deleteStorage, } from './icStorage';
|
7
|
-
export class AuthClient {
|
8
|
-
constructor(_identity, _key, _chain, _storage, _appId, _wallet, _idpWindowOption,
|
9
|
-
// A handle on the IdP window.
|
10
|
-
_idpWindow,
|
11
|
-
// The event handler for processing events from the IdP.
|
12
|
-
_eventHandler) {
|
13
|
-
this._identity = _identity;
|
14
|
-
this._key = _key;
|
15
|
-
this._chain = _chain;
|
16
|
-
this._storage = _storage;
|
17
|
-
this._appId = _appId;
|
18
|
-
this._wallet = _wallet;
|
19
|
-
this._idpWindowOption = _idpWindowOption;
|
20
|
-
this._idpWindow = _idpWindow;
|
21
|
-
this._eventHandler = _eventHandler;
|
22
|
-
}
|
23
|
-
static async create(options = {
|
24
|
-
appId: '',
|
25
|
-
}) {
|
26
|
-
var _a, _b;
|
27
|
-
const storage = (_a = options.storage) !== null && _a !== void 0 ? _a : new SessionStorage('ic-');
|
28
|
-
let key = null;
|
29
|
-
if (options.identity) {
|
30
|
-
key = options.identity;
|
31
|
-
}
|
32
|
-
else {
|
33
|
-
const maybeIdentityStorage = await storage.get(KEY_SESSIONSTORAGE_KEY);
|
34
|
-
if (maybeIdentityStorage) {
|
35
|
-
try {
|
36
|
-
key = Ed25519KeyIdentity.fromJSON(maybeIdentityStorage);
|
37
|
-
}
|
38
|
-
catch (e) {
|
39
|
-
// Ignore this, this means that the sessionStorage value isn't a valid Ed25519KeyIdentity
|
40
|
-
// serialization.
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
let identity = new AnonymousIdentity();
|
45
|
-
let chain = null;
|
46
|
-
let wallet = null;
|
47
|
-
if (key) {
|
48
|
-
try {
|
49
|
-
const chainStorage = await storage.get(KEY_SESSIONSTORAGE_DELEGATION);
|
50
|
-
wallet = await storage.get(KEY_SESSIONSTORAGE_WALLET);
|
51
|
-
if (chainStorage) {
|
52
|
-
chain = DelegationChain.fromJSON(chainStorage);
|
53
|
-
// Verify that the delegation isn't expired.
|
54
|
-
if (!isDelegationValid(chain)) {
|
55
|
-
await _deleteStorage(storage);
|
56
|
-
key = null;
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
identity = DelegationIdentity.fromDelegation(key, chain);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
catch (e) {
|
64
|
-
console.error(e);
|
65
|
-
// If there was a problem loading the chain, delete the key.
|
66
|
-
await _deleteStorage(storage);
|
67
|
-
key = null;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
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');
|
71
|
-
}
|
72
|
-
async _handleSuccess(message, onSuccess) {
|
73
|
-
var _a;
|
74
|
-
// console.log(message["identity"]);
|
75
|
-
if (message['identity'] !== undefined) {
|
76
|
-
const idDelegations = message['identity'].delegations.map(signedDelegation => {
|
77
|
-
return {
|
78
|
-
delegation: new Delegation(signedDelegation.delegation.pubkey.buffer, signedDelegation.delegation.expiration, signedDelegation.delegation.targets),
|
79
|
-
signature: signedDelegation.signature.buffer,
|
80
|
-
};
|
81
|
-
});
|
82
|
-
const idDelegationChain = DelegationChain.fromDelegations(idDelegations, message['identity'].userPublicKey
|
83
|
-
.buffer);
|
84
|
-
this._chain = idDelegationChain;
|
85
|
-
this._wallet = message['wallet'];
|
86
|
-
}
|
87
|
-
else {
|
88
|
-
const iiDelegations = message.delegations.map(signedDelegation => {
|
89
|
-
return {
|
90
|
-
delegation: new Delegation(signedDelegation.delegation.pubkey.buffer, signedDelegation.delegation.expiration, signedDelegation.delegation.targets),
|
91
|
-
signature: signedDelegation.signature.buffer,
|
92
|
-
};
|
93
|
-
});
|
94
|
-
const iiDelegationChain = DelegationChain.fromDelegations(iiDelegations, message.userPublicKey.buffer);
|
95
|
-
this._chain = iiDelegationChain;
|
96
|
-
}
|
97
|
-
const key = this._key;
|
98
|
-
if (!key) {
|
99
|
-
return this;
|
100
|
-
}
|
101
|
-
this._delegationIdentity = DelegationIdentity.fromDelegation(key, this._chain);
|
102
|
-
this._identity = this._delegationIdentity;
|
103
|
-
console.log(this._identity);
|
104
|
-
(_a = this._idpWindow) === null || _a === void 0 ? void 0 : _a.close();
|
105
|
-
await (onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess());
|
106
|
-
this._removeEventListener();
|
107
|
-
return this;
|
108
|
-
}
|
109
|
-
getIdentity() {
|
110
|
-
return this._identity;
|
111
|
-
}
|
112
|
-
getDelegationIdentity() {
|
113
|
-
return this._delegationIdentity;
|
114
|
-
}
|
115
|
-
getInnerKey() {
|
116
|
-
return this._key;
|
117
|
-
}
|
118
|
-
get wallet() {
|
119
|
-
return this._wallet;
|
120
|
-
}
|
121
|
-
setWallet(data) {
|
122
|
-
this._wallet = data;
|
123
|
-
}
|
124
|
-
async isAuthenticated() {
|
125
|
-
return !this.getIdentity().getPrincipal().isAnonymous() && this._chain !== null;
|
126
|
-
}
|
127
|
-
async login(options) {
|
128
|
-
var _a, _b, _c;
|
129
|
-
let key = this._key;
|
130
|
-
if (!key) {
|
131
|
-
// Create a new key (whether or not one was in storage).
|
132
|
-
key = Ed25519KeyIdentity.generate();
|
133
|
-
this._key = key;
|
134
|
-
await this._storage.set(KEY_SESSIONSTORAGE_KEY, JSON.stringify(key));
|
135
|
-
}
|
136
|
-
// Create the URL of the IDP. (e.g. https://XXXX/#authorize)
|
137
|
-
const identityProviderUrl = new URL(((_a = options === null || options === void 0 ? void 0 : options.identityProvider) === null || _a === void 0 ? void 0 : _a.toString()) || IDENTITY_PROVIDER_DEFAULT);
|
138
|
-
// Set the correct hash if it isn't already set.
|
139
|
-
identityProviderUrl.hash = IDENTITY_PROVIDER_ENDPOINT;
|
140
|
-
// If `login` has been called previously, then close/remove any previous windows
|
141
|
-
// and event listeners.
|
142
|
-
(_b = this._idpWindow) === null || _b === void 0 ? void 0 : _b.close();
|
143
|
-
this._removeEventListener();
|
144
|
-
// Open a new window with the IDP provider.
|
145
|
-
this._idpWindow = (_c = window.open(identityProviderUrl.toString(), 'idpWindow', this._idpWindowOption)) !== null && _c !== void 0 ? _c : undefined;
|
146
|
-
// Add an event listener to handle responses.
|
147
|
-
return new Promise((resolve, reject) => {
|
148
|
-
this._eventHandler = this._getEventHandler(identityProviderUrl, resolve, reject, options);
|
149
|
-
window.addEventListener('message', this._eventHandler);
|
150
|
-
});
|
151
|
-
}
|
152
|
-
_getEventHandler(identityProviderUrl, resolve, reject, options) {
|
153
|
-
return async (event) => {
|
154
|
-
var _a, _b, _c;
|
155
|
-
if (event.origin !== identityProviderUrl.origin) {
|
156
|
-
return;
|
157
|
-
}
|
158
|
-
const message = event.data;
|
159
|
-
switch (message.kind) {
|
160
|
-
case 'authorize-ready': {
|
161
|
-
// IDP is ready. Send a message to request authorization.
|
162
|
-
const request = {
|
163
|
-
kind: 'authorize-client',
|
164
|
-
sessionPublicKey: new Uint8Array((_a = this._key) === null || _a === void 0 ? void 0 : _a.getPublicKey().toDer()),
|
165
|
-
maxTimeToLive: options === null || options === void 0 ? void 0 : options.maxTimeToLive,
|
166
|
-
permissions: (_b = options === null || options === void 0 ? void 0 : options.permissions) !== null && _b !== void 0 ? _b : [PermissionsType.identity],
|
167
|
-
appId: this._appId,
|
168
|
-
};
|
169
|
-
(_c = this._idpWindow) === null || _c === void 0 ? void 0 : _c.postMessage(request, identityProviderUrl.origin);
|
170
|
-
break;
|
171
|
-
}
|
172
|
-
case 'authorize-client-success':
|
173
|
-
// Create the delegation chain and store it.
|
174
|
-
try {
|
175
|
-
resolve(await this._handleSuccess(message, options === null || options === void 0 ? void 0 : options.onSuccess));
|
176
|
-
// Setting the storage is moved out of _handleSuccess to make
|
177
|
-
// it a sync function. Having _handleSuccess as an async function
|
178
|
-
// messes up the jest tests for some reason.
|
179
|
-
if (this._chain) {
|
180
|
-
await this._storage.set(KEY_SESSIONSTORAGE_DELEGATION, JSON.stringify(this._chain.toJSON()));
|
181
|
-
}
|
182
|
-
if (this._wallet !== undefined) {
|
183
|
-
await this._storage.set(KEY_SESSIONSTORAGE_WALLET, this._wallet);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
catch (err) {
|
187
|
-
reject(this._handleFailure(err.message, options === null || options === void 0 ? void 0 : options.onError));
|
188
|
-
}
|
189
|
-
break;
|
190
|
-
case 'authorize-client-failure':
|
191
|
-
reject(this._handleFailure(message.text, options === null || options === void 0 ? void 0 : options.onError));
|
192
|
-
break;
|
193
|
-
default:
|
194
|
-
break;
|
195
|
-
}
|
196
|
-
};
|
197
|
-
}
|
198
|
-
_handleFailure(errorMessage, onError) {
|
199
|
-
var _a;
|
200
|
-
(_a = this._idpWindow) === null || _a === void 0 ? void 0 : _a.close();
|
201
|
-
onError === null || onError === void 0 ? void 0 : onError(errorMessage);
|
202
|
-
this._removeEventListener();
|
203
|
-
return errorMessage;
|
204
|
-
}
|
205
|
-
_removeEventListener() {
|
206
|
-
if (this._eventHandler) {
|
207
|
-
window.removeEventListener('message', this._eventHandler);
|
208
|
-
}
|
209
|
-
this._eventHandler = undefined;
|
210
|
-
}
|
211
|
-
async logout(options = {}) {
|
212
|
-
_deleteStorage(this._storage);
|
213
|
-
// Reset this auth client to a non-authenticated state.
|
214
|
-
this._identity = new AnonymousIdentity();
|
215
|
-
this._key = null;
|
216
|
-
this._chain = null;
|
217
|
-
this._wallet = undefined;
|
218
|
-
if (options.returnTo) {
|
219
|
-
try {
|
220
|
-
window.history.pushState({}, '', options.returnTo);
|
221
|
-
}
|
222
|
-
catch (e) {
|
223
|
-
window.location.href = options.returnTo;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
228
|
-
//
|
229
|
-
//# sourceMappingURL=icAuthClient.js.map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M,CAAC,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;aACzC;SACF;IACH,CAAC;CACF;AAED,EAAE"}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { ActorSubclass, Identity } from '@dfinity/agent';
|
2
|
-
import { InterfaceFactory } from '@dfinity/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, { ledgerCanisterId }: {
|
26
|
-
ledgerCanisterId?: string | undefined;
|
27
|
-
}) => Promise<IC>;
|
28
|
-
private injectWindow;
|
29
|
-
handleError(error?: string): void;
|
30
|
-
createActor: <T>(idlFactory: InterfaceFactory, canisterId: string) => ActorSubclass<T>;
|
31
|
-
requestTransfer: (options: TransactionOptions) => Promise<void>;
|
32
|
-
private _getEventHandler;
|
33
|
-
private _handleFailure;
|
34
|
-
}
|