@novasamatech/host-papp 0.5.0-17 → 0.5.0-19
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/.papi/descriptors/generated.json +1 -0
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +8 -7
- package/dist/helpers/abortError.d.ts +0 -1
- package/dist/helpers/abortError.js +0 -3
- package/dist/index.d.ts +1 -1
- package/dist/papp.js +2 -2
- package/dist/sso/auth/attestationService.js +1 -1
- package/dist/sso/auth/impl.d.ts +29 -3
- package/dist/sso/auth/impl.js +60 -35
- package/dist/sso/auth/types.d.ts +13 -2
- package/dist/sso/userSecretRepository.d.ts +1 -1
- package/dist/sso/userSecretRepository.js +2 -2
- package/package.json +5 -5
- package/dist/adapters/identity/rpc.d.ts +0 -6
- package/dist/adapters/identity/rpc.js +0 -101
- package/dist/adapters/identity/types.d.ts +0 -10
- package/dist/adapters/identity/types.js +0 -1
- package/dist/adapters/lazyClient/papi.d.ts +0 -3
- package/dist/adapters/lazyClient/papi.js +0 -17
- package/dist/adapters/lazyClient/types.d.ts +0 -5
- package/dist/adapters/lazyClient/types.js +0 -1
- package/dist/adapters/statement/rpc.d.ts +0 -3
- package/dist/adapters/statement/rpc.js +0 -93
- package/dist/adapters/statement/types.d.ts +0 -9
- package/dist/adapters/statement/types.js +0 -1
- package/dist/adapters/storage/localStorage.d.ts +0 -2
- package/dist/adapters/storage/localStorage.js +0 -34
- package/dist/adapters/storage/memory.d.ts +0 -2
- package/dist/adapters/storage/memory.js +0 -22
- package/dist/adapters/storage/types.d.ts +0 -7
- package/dist/adapters/storage/types.js +0 -1
- package/dist/adapters/transport/rpc.d.ts +0 -3
- package/dist/adapters/transport/rpc.js +0 -51
- package/dist/adapters/transport/types.d.ts +0 -6
- package/dist/adapters/transport/types.js +0 -1
- package/dist/components/auth/codec.d.ts +0 -9
- package/dist/components/auth/codec.js +0 -10
- package/dist/components/auth/codecs.d.ts +0 -9
- package/dist/components/auth/codecs.js +0 -10
- package/dist/components/auth/index.d.ts +0 -36
- package/dist/components/auth/index.js +0 -150
- package/dist/components/auth/types.d.ts +0 -15
- package/dist/components/auth/types.js +0 -1
- package/dist/components/session.d.ts +0 -34
- package/dist/components/session.js +0 -54
- package/dist/components/sso/index.d.ts +0 -36
- package/dist/components/sso/index.js +0 -150
- package/dist/components/sso/scale/handshake.d.ts +0 -9
- package/dist/components/sso/scale/handshake.js +0 -10
- package/dist/components/sso/types.d.ts +0 -15
- package/dist/components/sso/types.js +0 -1
- package/dist/components/transport.d.ts +0 -27
- package/dist/components/transport.js +0 -57
- package/dist/components/user/codec.d.ts +0 -16
- package/dist/components/user/codec.js +0 -13
- package/dist/components/user/index.d.ts +0 -22
- package/dist/components/user/index.js +0 -58
- package/dist/components/user/ssoMessageStream.d.ts +0 -10
- package/dist/components/user/ssoMessageStream.js +0 -8
- package/dist/components/user/ssoSession.d.ts +0 -5
- package/dist/components/user/ssoSession.js +0 -5
- package/dist/components/user/storage.d.ts +0 -27
- package/dist/components/user/storage.js +0 -143
- package/dist/components/user/types.d.ts +0 -6
- package/dist/components/user/types.js +0 -1
- package/dist/components/user/userSessionStorage.d.ts +0 -20
- package/dist/components/user/userSessionStorage.js +0 -24
- package/dist/components/user.d.ts +0 -74
- package/dist/components/user.js +0 -188
- package/dist/helpers/result.d.ts +0 -12
- package/dist/helpers/result.js +0 -15
- package/dist/helpers/result.spec.d.ts +0 -1
- package/dist/helpers/result.spec.js +0 -23
- package/dist/helpers.d.ts +0 -1
- package/dist/helpers.js +0 -3
- package/dist/modules/accounts.d.ts +0 -1
- package/dist/modules/accounts.js +0 -2
- package/dist/modules/crypto.d.ts +0 -23
- package/dist/modules/crypto.js +0 -51
- package/dist/modules/secretStorage.d.ts +0 -15
- package/dist/modules/secretStorage.js +0 -44
- package/dist/modules/session/helpers.d.ts +0 -5
- package/dist/modules/session/helpers.js +0 -29
- package/dist/modules/session/session.d.ts +0 -12
- package/dist/modules/session/session.js +0 -50
- package/dist/modules/session/types.d.ts +0 -12
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/signIn.d.ts +0 -67
- package/dist/modules/signIn.js +0 -188
- package/dist/modules/state.d.ts +0 -16
- package/dist/modules/state.js +0 -50
- package/dist/modules/statementStore.d.ts +0 -12
- package/dist/modules/statementStore.js +0 -22
- package/dist/modules/statementTopic.d.ts +0 -34
- package/dist/modules/statementTopic.js +0 -46
- package/dist/modules/storageView.d.ts +0 -25
- package/dist/modules/storageView.js +0 -51
- package/dist/modules/syncStorage.d.ts +0 -25
- package/dist/modules/syncStorage.js +0 -76
- package/dist/modules/transport/codec.d.ts +0 -24
- package/dist/modules/transport/codec.js +0 -36
- package/dist/modules/transport/crypto.d.ts +0 -2
- package/dist/modules/transport/crypto.js +0 -20
- package/dist/modules/transport/transport.d.ts +0 -42
- package/dist/modules/transport/transport.js +0 -66
- package/dist/modules/user.d.ts +0 -67
- package/dist/modules/user.js +0 -188
- package/dist/modules/userManager.d.ts +0 -15
- package/dist/modules/userManager.js +0 -105
- package/dist/modules/userStorage.d.ts +0 -19
- package/dist/modules/userStorage.js +0 -108
- package/dist/modules/userStore.d.ts +0 -15
- package/dist/modules/userStore.js +0 -105
- package/dist/sso/session/impl.d.ts +0 -23
- package/dist/sso/session/impl.js +0 -57
- package/dist/sso/session/scale/remoteMessage.d.ts +0 -10
- package/dist/sso/session/scale/remoteMessage.js +0 -13
- package/dist/sso/session/sessionManager.d.ts +0 -23
- package/dist/sso/session/sessionManager.js +0 -58
- package/dist/sso/session/ssoSession.d.ts +0 -8
- package/dist/sso/session/ssoSession.js +0 -5
- package/dist/sso/session/ssoSessionStorage.d.ts +0 -21
- package/dist/sso/session/ssoSessionStorage.js +0 -20
- package/dist/sso/session/types.d.ts +0 -6
- package/dist/sso/session/types.js +0 -1
- package/dist/sso/session/userSessionStorage.d.ts +0 -21
- package/dist/sso/session/userSessionStorage.js +0 -20
- package/dist/sso/sessionManager/attestationService.d.ts +0 -5
- package/dist/sso/sessionManager/attestationService.js +0 -15
- package/dist/sso/sessionManager/repository/ssoSessionRepository.d.ts +0 -22
- package/dist/sso/sessionManager/repository/ssoSessionRepository.js +0 -27
- package/dist/sso/sessionManager/scale/signRequest.d.ts +0 -19
- package/dist/sso/sessionManager/scale/signRequest.js +0 -19
- package/dist/sso/sessionManager/scale/signResponse.d.ts +0 -6
- package/dist/sso/sessionManager/scale/signResponse.js +0 -5
- package/dist/sso/sessionManager/ssoSession.d.ts +0 -23
- package/dist/sso/sessionManager/ssoSession.js +0 -69
- package/dist/sso/sessionManager/ssoSessionProver.d.ts +0 -4
- package/dist/sso/sessionManager/ssoSessionProver.js +0 -35
- package/dist/sso/ssoSessionRepository.d.ts +0 -18
- package/dist/sso/ssoSessionRepository.js +0 -27
- package/dist/structs.d.ts +0 -24
- package/dist/structs.js +0 -36
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { createStatementSdk } from '@polkadot-api/sdk-statement';
|
|
2
|
-
import { Binary } from '@polkadot-api/substrate-bindings';
|
|
3
|
-
import { toHex } from '@polkadot-api/utils';
|
|
4
|
-
import { fromPromise } from 'neverthrow';
|
|
5
|
-
import { toError } from '../../helpers/utils.js';
|
|
6
|
-
const POLLING_INTERVAL = 1000;
|
|
7
|
-
function createKey(topics) {
|
|
8
|
-
return topics.map(toHex).sort().join('');
|
|
9
|
-
}
|
|
10
|
-
export function createPapiStatementAdapter(lazyClient) {
|
|
11
|
-
const sdk = createStatementSdk((method, params) => {
|
|
12
|
-
const client = lazyClient.getClient();
|
|
13
|
-
return client._request(method, params);
|
|
14
|
-
});
|
|
15
|
-
const pollings = new Map();
|
|
16
|
-
const subscriptions = new Map();
|
|
17
|
-
function addSubscription(key, subscription) {
|
|
18
|
-
let subs = subscriptions.get(key);
|
|
19
|
-
if (!subs) {
|
|
20
|
-
subs = [];
|
|
21
|
-
subscriptions.set(key, subs);
|
|
22
|
-
}
|
|
23
|
-
subs.push(subscription);
|
|
24
|
-
return subs;
|
|
25
|
-
}
|
|
26
|
-
function removeSubscription(key, subscription) {
|
|
27
|
-
let subs = subscriptions.get(key);
|
|
28
|
-
if (!subs) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
subs = subs.filter(x => x !== subscription);
|
|
32
|
-
return subs;
|
|
33
|
-
}
|
|
34
|
-
const transportProvider = {
|
|
35
|
-
queryStatements(topics, destination) {
|
|
36
|
-
return fromPromise(sdk.getStatements({
|
|
37
|
-
topics: topics.map(t => Binary.fromBytes(t)),
|
|
38
|
-
dest: destination ? Binary.fromBytes(destination) : null,
|
|
39
|
-
}), toError);
|
|
40
|
-
},
|
|
41
|
-
subscribeStatements(topics, callback) {
|
|
42
|
-
const key = createKey(topics);
|
|
43
|
-
const callbacks = addSubscription(key, callback);
|
|
44
|
-
if (callbacks.length === 1) {
|
|
45
|
-
const unsub = polling(POLLING_INTERVAL, () => transportProvider.queryStatements(topics), statements => {
|
|
46
|
-
const list = subscriptions.get(key);
|
|
47
|
-
if (list) {
|
|
48
|
-
for (const fn of list) {
|
|
49
|
-
fn(statements);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
pollings.set(key, unsub);
|
|
54
|
-
}
|
|
55
|
-
return () => {
|
|
56
|
-
const callbacks = removeSubscription(key, callback);
|
|
57
|
-
if (callbacks.length === 0) {
|
|
58
|
-
const stopPolling = pollings.get(key);
|
|
59
|
-
stopPolling?.();
|
|
60
|
-
pollings.delete(key);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
submitStatement(statement) {
|
|
65
|
-
return fromPromise(sdk.submit(statement), toError);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
return transportProvider;
|
|
69
|
-
}
|
|
70
|
-
function polling(interval, request, callback) {
|
|
71
|
-
let active = true;
|
|
72
|
-
let tm = null;
|
|
73
|
-
function createCycle() {
|
|
74
|
-
tm = setTimeout(() => {
|
|
75
|
-
if (!active) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
request().match(data => {
|
|
79
|
-
callback(data);
|
|
80
|
-
createCycle();
|
|
81
|
-
}, () => {
|
|
82
|
-
createCycle();
|
|
83
|
-
});
|
|
84
|
-
}, interval);
|
|
85
|
-
}
|
|
86
|
-
createCycle();
|
|
87
|
-
return () => {
|
|
88
|
-
active = false;
|
|
89
|
-
if (tm !== null) {
|
|
90
|
-
clearTimeout(tm);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { SignedStatement, Statement } from '@polkadot-api/sdk-statement';
|
|
2
|
-
import type { ResultAsync } from 'neverthrow';
|
|
3
|
-
import type { Callback } from '../../types.js';
|
|
4
|
-
export type StatementsCallback = Callback<Statement[]>;
|
|
5
|
-
export type StatementAdapter = {
|
|
6
|
-
queryStatements(topics: Uint8Array[], destination?: Uint8Array): ResultAsync<Statement[], Error>;
|
|
7
|
-
subscribeStatements(topics: Uint8Array[], callback: StatementsCallback): VoidFunction;
|
|
8
|
-
submitStatement(statement: SignedStatement): ResultAsync<void, Error>;
|
|
9
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createNanoEvents } from 'nanoevents';
|
|
2
|
-
import { fromAsyncThrowable } from 'neverthrow';
|
|
3
|
-
import { toError } from '../../helpers/utils.js';
|
|
4
|
-
export function createLocalStorageAdapter(prefix) {
|
|
5
|
-
const events = createNanoEvents();
|
|
6
|
-
const withPrefix = (key) => `PAPP_${prefix}_${key}`;
|
|
7
|
-
return {
|
|
8
|
-
write: fromAsyncThrowable(async (key, value) => {
|
|
9
|
-
localStorage.setItem(withPrefix(key), value);
|
|
10
|
-
events.emit(key, value);
|
|
11
|
-
}, toError),
|
|
12
|
-
read: fromAsyncThrowable(async (key) => {
|
|
13
|
-
return localStorage.getItem(withPrefix(key));
|
|
14
|
-
}, toError),
|
|
15
|
-
clear: fromAsyncThrowable(async (key) => {
|
|
16
|
-
localStorage.removeItem(withPrefix(key));
|
|
17
|
-
events.emit(key, null);
|
|
18
|
-
}, toError),
|
|
19
|
-
subscribe(key, callback) {
|
|
20
|
-
const prefixedKey = withPrefix(key);
|
|
21
|
-
const unsubscribeLocalListener = events.on(prefixedKey, callback);
|
|
22
|
-
const externalListener = (event) => {
|
|
23
|
-
if (event.storageArea === localStorage && event.key === prefixedKey) {
|
|
24
|
-
callback(event.newValue);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
window.addEventListener('storage', externalListener);
|
|
28
|
-
return () => {
|
|
29
|
-
unsubscribeLocalListener();
|
|
30
|
-
window.removeEventListener('storage', externalListener);
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createNanoEvents } from 'nanoevents';
|
|
2
|
-
import { fromAsyncThrowable } from 'neverthrow';
|
|
3
|
-
export function createMemoryAdapter(external) {
|
|
4
|
-
const events = createNanoEvents();
|
|
5
|
-
const storage = external ? { ...external } : {};
|
|
6
|
-
return {
|
|
7
|
-
write: fromAsyncThrowable(async (key, value) => {
|
|
8
|
-
storage[key] = value;
|
|
9
|
-
events.emit(key, value);
|
|
10
|
-
}),
|
|
11
|
-
read: fromAsyncThrowable(async (key) => {
|
|
12
|
-
return storage[key] ?? null;
|
|
13
|
-
}),
|
|
14
|
-
clear: fromAsyncThrowable(async (key) => {
|
|
15
|
-
delete storage[key];
|
|
16
|
-
events.emit(key, null);
|
|
17
|
-
}),
|
|
18
|
-
subscribe(key, callback) {
|
|
19
|
-
return events.on(key, callback);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ResultAsync } from 'neverthrow';
|
|
2
|
-
export type StorageAdapter = {
|
|
3
|
-
write(key: string, value: string): ResultAsync<void, Error>;
|
|
4
|
-
read(key: string): ResultAsync<string | null, Error>;
|
|
5
|
-
clear(key: string): ResultAsync<void, Error>;
|
|
6
|
-
subscribe(key: string, callback: (value: string | null) => unknown): VoidFunction;
|
|
7
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { ResultAsync } from 'neverthrow';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createClient } from '@polkadot-api/raw-client';
|
|
2
|
-
import { createStatementSdk } from '@polkadot-api/sdk-statement';
|
|
3
|
-
import { FixedSizeBinary } from '@polkadot-api/substrate-bindings';
|
|
4
|
-
export function createRpcTransport(rpcProvider) {
|
|
5
|
-
const POLLING_INTERVAL = 1000;
|
|
6
|
-
const client = createClient(rpcProvider);
|
|
7
|
-
const sdk = createStatementSdk((method, params) => {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
client.request(method, params, {
|
|
10
|
-
onSuccess: resolve,
|
|
11
|
-
onError: reject,
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
const transportProvider = {
|
|
16
|
-
getStatements(topics) {
|
|
17
|
-
// @ts-expect-error lib versions mismatch
|
|
18
|
-
return sdk.getStatements({ topics: topics.map(topic => new FixedSizeBinary(topic)) });
|
|
19
|
-
},
|
|
20
|
-
subscribeStatements(topics, callback) {
|
|
21
|
-
return polling(POLLING_INTERVAL, () => transportProvider.getStatements(topics), callback);
|
|
22
|
-
},
|
|
23
|
-
submitStatement(statement) {
|
|
24
|
-
return sdk.submit(statement);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
return transportProvider;
|
|
28
|
-
}
|
|
29
|
-
function polling(interval, request, callback) {
|
|
30
|
-
let active = true;
|
|
31
|
-
let tm = null;
|
|
32
|
-
function createCycle() {
|
|
33
|
-
tm = setTimeout(() => {
|
|
34
|
-
if (!active) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
request()
|
|
38
|
-
.then(callback)
|
|
39
|
-
.finally(() => {
|
|
40
|
-
createCycle();
|
|
41
|
-
});
|
|
42
|
-
}, interval);
|
|
43
|
-
}
|
|
44
|
-
createCycle();
|
|
45
|
-
return () => {
|
|
46
|
-
active = false;
|
|
47
|
-
if (tm !== null) {
|
|
48
|
-
clearTimeout(tm);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { SignedStatement, Statement } from '@polkadot-api/sdk-statement';
|
|
2
|
-
export type Transport = {
|
|
3
|
-
getStatements(topics: Uint8Array[]): Promise<Statement[]>;
|
|
4
|
-
subscribeStatements(topics: Uint8Array[], callback: (response: Statement[]) => unknown): VoidFunction;
|
|
5
|
-
submitStatement(statement: SignedStatement): Promise<void>;
|
|
6
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const HandshakeData: import("scale-ts").Codec<{
|
|
2
|
-
tag: "V1";
|
|
3
|
-
value: [import("../../modules/crypto.js").SsPublicKey, import("../../modules/crypto.js").EncrPublicKey, string];
|
|
4
|
-
}>;
|
|
5
|
-
export declare const HandshakeResponsePayload: import("scale-ts").Codec<{
|
|
6
|
-
tag: "V1";
|
|
7
|
-
value: [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>];
|
|
8
|
-
}>;
|
|
9
|
-
export declare const HandshakeResponseSensitiveData: import("scale-ts").Codec<[Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Bytes, Enum, Tuple, str } from 'scale-ts';
|
|
2
|
-
import { EncrPubKey, SsPubKey } from '../../modules/crypto.js';
|
|
3
|
-
export const HandshakeData = Enum({
|
|
4
|
-
V1: Tuple(SsPubKey, EncrPubKey, str),
|
|
5
|
-
});
|
|
6
|
-
export const HandshakeResponsePayload = Enum({
|
|
7
|
-
// [encrypted, tmp_key]
|
|
8
|
-
V1: Tuple(Bytes(), Bytes(65)),
|
|
9
|
-
});
|
|
10
|
-
export const HandshakeResponseSensitiveData = Tuple(Bytes(65), Bytes(32));
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const HandshakeData: import("scale-ts").Codec<{
|
|
2
|
-
tag: "V1";
|
|
3
|
-
value: [import("../../modules/crypto.js").SsPublicKey, import("../../modules/crypto.js").EncrPublicKey, string];
|
|
4
|
-
}>;
|
|
5
|
-
export declare const HandshakeResponsePayload: import("scale-ts").Codec<{
|
|
6
|
-
tag: "V1";
|
|
7
|
-
value: [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>];
|
|
8
|
-
}>;
|
|
9
|
-
export declare const HandshakeResponseSensitiveData: import("scale-ts").Codec<[Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Bytes, Enum, Tuple, str } from 'scale-ts';
|
|
2
|
-
import { EncrPubKey, SsPubKey } from '../../modules/crypto.js';
|
|
3
|
-
export const HandshakeData = Enum({
|
|
4
|
-
V1: Tuple(SsPubKey, EncrPubKey, str),
|
|
5
|
-
});
|
|
6
|
-
export const HandshakeResponsePayload = Enum({
|
|
7
|
-
// [encrypted, tmp_key]
|
|
8
|
-
V1: Tuple(Bytes(), Bytes(65)),
|
|
9
|
-
});
|
|
10
|
-
export const HandshakeResponseSensitiveData = Tuple(Bytes(65), Bytes(32));
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ResultAsync } from 'neverthrow';
|
|
2
|
-
import type { Transport } from '../../modules/transport/transport.js';
|
|
3
|
-
import type { UserSession, UserSessionStorage } from '../user/userSessionStorage.js';
|
|
4
|
-
import type { AuthentificationStatus } from './types.js';
|
|
5
|
-
export type AuthComponent = ReturnType<typeof createAuthComponent>;
|
|
6
|
-
type Params = {
|
|
7
|
-
/**
|
|
8
|
-
* Host app Id.
|
|
9
|
-
* CAUTION! This value should be stable.
|
|
10
|
-
*/
|
|
11
|
-
appId: string;
|
|
12
|
-
/**
|
|
13
|
-
* URL for additional metadata that will be displayed during pairing process.
|
|
14
|
-
* Content of provided json shound be
|
|
15
|
-
* ```ts
|
|
16
|
-
* interface Metadata {
|
|
17
|
-
* name: string;
|
|
18
|
-
* icon: string; // url for icon. Icon should be a rasterized image with min size 256x256 px.
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
metadata: string;
|
|
23
|
-
transport: Transport;
|
|
24
|
-
userSessionStorage: UserSessionStorage;
|
|
25
|
-
};
|
|
26
|
-
export declare function createAuthComponent({ appId, metadata, transport, userSessionStorage }: Params): {
|
|
27
|
-
status: {
|
|
28
|
-
read: () => AuthentificationStatus;
|
|
29
|
-
subscribe: (fn: (value: AuthentificationStatus) => void) => () => void;
|
|
30
|
-
onFirstSubscribe: (callback: VoidFunction) => import("nanoevents").Unsubscribe;
|
|
31
|
-
onLastUnsubscribe: (callback: VoidFunction) => import("nanoevents").Unsubscribe;
|
|
32
|
-
};
|
|
33
|
-
authenticate(): ResultAsync<UserSession | null, Error>;
|
|
34
|
-
abortAuthentication(): void;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { toHex } from '@polkadot-api/utils';
|
|
2
|
-
import { err, errAsync, fromPromise, fromThrowable, ok } from 'neverthrow';
|
|
3
|
-
import { AbortError } from '../../helpers/abortError.js';
|
|
4
|
-
import { toError } from '../../helpers/utils.js';
|
|
5
|
-
import { ENCR_SECRET_SEED_SIZE, SS_SECRET_SEED_SIZE, createEncrSecret, createRandomSeed, createSharedSecret, createSsHardDerivation, createSsSecret, decrypt, getEncrPub, getSsPub, khash, mergeBytes, stringToBytes, } from '../../modules/crypto.js';
|
|
6
|
-
import { createAccount } from '../../modules/session/helpers.js';
|
|
7
|
-
import { createState, readonly } from '../../modules/state.js';
|
|
8
|
-
import { createUserSession } from '../../modules/statementStore.js';
|
|
9
|
-
import { HandshakeData, HandshakeResponsePayload, HandshakeResponseSensitiveData } from './codec.js';
|
|
10
|
-
export function createAuthComponent({ appId, metadata, transport, userSessionStorage }) {
|
|
11
|
-
const authStatus = createState({ step: 'none' });
|
|
12
|
-
let authResults = null;
|
|
13
|
-
let abort = null;
|
|
14
|
-
function handshake(signal) {
|
|
15
|
-
try {
|
|
16
|
-
authStatus.write({ step: 'initial' });
|
|
17
|
-
const { encrSecret, encrPublicKey, ssPublicKey } = getSecretKeys(appId);
|
|
18
|
-
const hostAccount = createAccount(ssPublicKey, encrPublicKey);
|
|
19
|
-
const handshakePayload = createHandshakePayloadV1({ ssPublicKey, encrPublicKey, metadata }).andTee(payload => authStatus.write({ step: 'pairing', payload: createDeeplink(payload) }));
|
|
20
|
-
const handshakeTopic = createHandshakeTopic(hostAccount);
|
|
21
|
-
const pappResponse = handshakePayload
|
|
22
|
-
.andThen(() => handshakeTopic)
|
|
23
|
-
.asyncAndThen(topic => waitForStatements(callback => transport.subscribeSession(topic, callback), signal, (statements, resolve) => {
|
|
24
|
-
for (const statement of [...statements].reverse()) {
|
|
25
|
-
if (!statement.data)
|
|
26
|
-
continue;
|
|
27
|
-
const session = retrieveSession({
|
|
28
|
-
hostAccount,
|
|
29
|
-
encrSecret,
|
|
30
|
-
payload: statement.data.asBytes(),
|
|
31
|
-
});
|
|
32
|
-
resolve(session);
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}));
|
|
36
|
-
const userCreated = pappResponse.andThen(userSessionStorage.add);
|
|
37
|
-
return userCreated
|
|
38
|
-
.orElse(e => (AbortError.isAbortError(e) ? ok(null) : err(toError(e))))
|
|
39
|
-
.andTee(session => {
|
|
40
|
-
if (session) {
|
|
41
|
-
authStatus.write({ step: 'finished', session });
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
authStatus.write({ step: 'none' });
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
.orTee(e => authStatus.write({ step: 'error', message: e.message }));
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
return errAsync(toError(e));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const authModule = {
|
|
54
|
-
status: readonly(authStatus),
|
|
55
|
-
authenticate() {
|
|
56
|
-
if (authResults) {
|
|
57
|
-
return authResults;
|
|
58
|
-
}
|
|
59
|
-
abort = new AbortController();
|
|
60
|
-
authResults = handshake(abort.signal);
|
|
61
|
-
return authResults;
|
|
62
|
-
},
|
|
63
|
-
abortAuthentication() {
|
|
64
|
-
if (abort) {
|
|
65
|
-
authResults = null;
|
|
66
|
-
authStatus.reset();
|
|
67
|
-
abort.abort(new AbortError('Aborted by user.'));
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
return authModule;
|
|
72
|
-
}
|
|
73
|
-
const createHandshakeTopic = fromThrowable((account) => khash(account.accountId, mergeBytes(account.publicKey, stringToBytes('topic'))), toError);
|
|
74
|
-
const createHandshakePayloadV1 = fromThrowable(({ encrPublicKey, ssPublicKey, metadata, }) => HandshakeData.enc({
|
|
75
|
-
tag: 'V1',
|
|
76
|
-
value: [ssPublicKey, encrPublicKey, metadata],
|
|
77
|
-
}), toError);
|
|
78
|
-
function parseHandshakePayload(payload) {
|
|
79
|
-
const decoded = HandshakeResponsePayload.dec(payload);
|
|
80
|
-
switch (decoded.tag) {
|
|
81
|
-
case 'V1':
|
|
82
|
-
return {
|
|
83
|
-
encrypted: decoded.value[0],
|
|
84
|
-
tmpKey: decoded.value[1],
|
|
85
|
-
};
|
|
86
|
-
default:
|
|
87
|
-
throw new Error('Unsupported handshake payload version');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function retrieveSession({ payload, encrSecret, hostAccount, }) {
|
|
91
|
-
const { encrypted, tmpKey } = parseHandshakePayload(payload);
|
|
92
|
-
const symmetricKey = createSharedSecret(encrSecret, tmpKey);
|
|
93
|
-
const decrypted = decrypt(symmetricKey, encrypted);
|
|
94
|
-
const [pappEncrPublicKey, pappAccountId] = HandshakeResponseSensitiveData.dec(decrypted);
|
|
95
|
-
const sharedSecret = createSharedSecret(encrSecret, pappEncrPublicKey);
|
|
96
|
-
const peerAccount = createAccount(pappAccountId, sharedSecret);
|
|
97
|
-
return createUserSession(hostAccount, peerAccount);
|
|
98
|
-
}
|
|
99
|
-
function getSsKeys(appId) {
|
|
100
|
-
const seed = createRandomSeed(appId, SS_SECRET_SEED_SIZE);
|
|
101
|
-
const ssSecret = createSsHardDerivation(createSsSecret(seed), '//wallet');
|
|
102
|
-
return {
|
|
103
|
-
ssSecret: ssSecret,
|
|
104
|
-
ssPublicKey: getSsPub(ssSecret),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function getEncrKeys(appId) {
|
|
108
|
-
const seed = createRandomSeed(appId, ENCR_SECRET_SEED_SIZE);
|
|
109
|
-
const encrSecret = createEncrSecret(seed);
|
|
110
|
-
return {
|
|
111
|
-
encrSecret,
|
|
112
|
-
encrPublicKey: getEncrPub(encrSecret),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function getSecretKeys(appId) {
|
|
116
|
-
const ss = getSsKeys(appId);
|
|
117
|
-
const encr = getEncrKeys(appId);
|
|
118
|
-
return {
|
|
119
|
-
...ss,
|
|
120
|
-
...encr,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function createDeeplink(payload) {
|
|
124
|
-
return `polkadotapp://pair?handshake=${toHex(payload)}`;
|
|
125
|
-
}
|
|
126
|
-
function waitForStatements(subscribe, abortSignal, callback) {
|
|
127
|
-
return fromPromise(new Promise((resolve, reject) => {
|
|
128
|
-
const unsubscribe = subscribe(statements => {
|
|
129
|
-
if (abortSignal?.aborted) {
|
|
130
|
-
unsubscribe();
|
|
131
|
-
try {
|
|
132
|
-
abortSignal.throwIfAborted();
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
reject(e);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
callback(statements, value => {
|
|
140
|
-
unsubscribe();
|
|
141
|
-
resolve(value);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
unsubscribe();
|
|
146
|
-
reject(e);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}), toError);
|
|
150
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { UserSession } from '../user/userSessionStorage.js';
|
|
2
|
-
export type AuthentificationStatus = {
|
|
3
|
-
step: 'none';
|
|
4
|
-
} | {
|
|
5
|
-
step: 'initial';
|
|
6
|
-
} | {
|
|
7
|
-
step: 'pairing';
|
|
8
|
-
payload: string;
|
|
9
|
-
} | {
|
|
10
|
-
step: 'error';
|
|
11
|
-
message: string;
|
|
12
|
-
} | {
|
|
13
|
-
step: 'finished';
|
|
14
|
-
session: UserSession;
|
|
15
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { CodecType } from 'scale-ts';
|
|
2
|
-
import type { StorageAdapter } from '../adapters/storage/types.js';
|
|
3
|
-
import type { Account } from '../modules/statementStore.js';
|
|
4
|
-
import type { Transport } from '../modules/transport/transport.js';
|
|
5
|
-
import type { Callback } from '../types.js';
|
|
6
|
-
export type Session<T> = {
|
|
7
|
-
subscribe(callback: Callback<T>): VoidFunction;
|
|
8
|
-
dispose(): void;
|
|
9
|
-
};
|
|
10
|
-
export declare const HostRemoteMessageCodec: import("scale-ts").Codec<{
|
|
11
|
-
messageId: string;
|
|
12
|
-
data: {
|
|
13
|
-
tag: "v1";
|
|
14
|
-
value: {
|
|
15
|
-
tag: "Disconnected";
|
|
16
|
-
value: undefined;
|
|
17
|
-
} | {
|
|
18
|
-
tag: "SigningRequest";
|
|
19
|
-
value: Uint8Array<ArrayBufferLike>;
|
|
20
|
-
} | {
|
|
21
|
-
tag: "SigningResponse";
|
|
22
|
-
value: Uint8Array<ArrayBufferLike>;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}>;
|
|
26
|
-
export type SSOSession = Session<CodecType<typeof HostRemoteMessageCodec>>;
|
|
27
|
-
type SsoSessionParams = {
|
|
28
|
-
ownAccount: Account;
|
|
29
|
-
peerAccount: Account;
|
|
30
|
-
transport: Transport;
|
|
31
|
-
storage: StorageAdapter;
|
|
32
|
-
};
|
|
33
|
-
export declare function createSSOSession({ ownAccount, peerAccount, transport, storage }: SsoSessionParams): SSOSession;
|
|
34
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { fromThrowable, okAsync } from 'neverthrow';
|
|
2
|
-
import { toHex } from 'polkadot-api/utils';
|
|
3
|
-
import { Bytes, Enum, Struct, _void, str } from 'scale-ts';
|
|
4
|
-
import { toError } from '../helpers/utils.js';
|
|
5
|
-
import { createSessionId } from '../modules/statementStore.js';
|
|
6
|
-
import { storageListView } from '../modules/storageView.js';
|
|
7
|
-
// SSO
|
|
8
|
-
export const HostRemoteMessageCodec = Struct({
|
|
9
|
-
messageId: str,
|
|
10
|
-
data: Enum({
|
|
11
|
-
v1: Enum({
|
|
12
|
-
Disconnected: _void,
|
|
13
|
-
// TODO implement
|
|
14
|
-
SigningRequest: Bytes(),
|
|
15
|
-
// TODO implement
|
|
16
|
-
SigningResponse: Bytes(),
|
|
17
|
-
}),
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
export function createSSOSession({ ownAccount, peerAccount, transport, storage }) {
|
|
21
|
-
const peerSession = createSessionId(peerAccount, ownAccount);
|
|
22
|
-
const processedStorage = storageListView({
|
|
23
|
-
key: `Session_Processed_${toHex(peerSession)}`,
|
|
24
|
-
storage,
|
|
25
|
-
initial: [],
|
|
26
|
-
from: JSON.parse,
|
|
27
|
-
to: JSON.stringify,
|
|
28
|
-
});
|
|
29
|
-
let subscriptions = [];
|
|
30
|
-
return {
|
|
31
|
-
subscribe(callback) {
|
|
32
|
-
const fn = fromThrowable(callback, toError);
|
|
33
|
-
const unsub = transport.handleRequest(ownAccount, peerAccount, HostRemoteMessageCodec, async (message) => {
|
|
34
|
-
processedStorage.read().andThen(processed => {
|
|
35
|
-
if (processed.includes(message.requestId)) {
|
|
36
|
-
return okAsync();
|
|
37
|
-
}
|
|
38
|
-
return fn(message.data).asyncAndThen(() => processedStorage.mutate(p => p.concat(message.requestId)));
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
subscriptions.push(unsub);
|
|
42
|
-
return () => {
|
|
43
|
-
unsub();
|
|
44
|
-
subscriptions = subscriptions.filter(x => x !== unsub);
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
dispose() {
|
|
48
|
-
for (const unsub of subscriptions) {
|
|
49
|
-
unsub();
|
|
50
|
-
}
|
|
51
|
-
subscriptions = [];
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Transport } from '@novasamatech/statement-store';
|
|
2
|
-
import type { ResultAsync } from 'neverthrow';
|
|
3
|
-
import type { UserSession, UserSessionStorage } from '../user/userSessionStorage.js';
|
|
4
|
-
import type { AuthentificationStatus } from './types.js';
|
|
5
|
-
export type AuthComponent = ReturnType<typeof createAuthComponent>;
|
|
6
|
-
type Params = {
|
|
7
|
-
/**
|
|
8
|
-
* Host app Id.
|
|
9
|
-
* CAUTION! This value should be stable.
|
|
10
|
-
*/
|
|
11
|
-
appId: string;
|
|
12
|
-
/**
|
|
13
|
-
* URL for additional metadata that will be displayed during pairing process.
|
|
14
|
-
* Content of provided json shound be
|
|
15
|
-
* ```ts
|
|
16
|
-
* interface Metadata {
|
|
17
|
-
* name: string;
|
|
18
|
-
* icon: string; // url for icon. Icon should be a rasterized image with min size 256x256 px.
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
metadata: string;
|
|
23
|
-
transport: Transport;
|
|
24
|
-
userSessionStorage: UserSessionStorage;
|
|
25
|
-
};
|
|
26
|
-
export declare function createAuthComponent({ appId, metadata, transport, userSessionStorage }: Params): {
|
|
27
|
-
status: {
|
|
28
|
-
read: () => AuthentificationStatus;
|
|
29
|
-
subscribe: (fn: (value: AuthentificationStatus) => void) => () => void;
|
|
30
|
-
onFirstSubscribe: (callback: VoidFunction) => import("nanoevents").Unsubscribe;
|
|
31
|
-
onLastUnsubscribe: (callback: VoidFunction) => import("nanoevents").Unsubscribe;
|
|
32
|
-
};
|
|
33
|
-
authenticate(): ResultAsync<UserSession | null, Error>;
|
|
34
|
-
abortAuthentication(): void;
|
|
35
|
-
};
|
|
36
|
-
export {};
|