@novasamatech/host-papp 0.5.0-18 → 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/sso/auth/attestationService.js +1 -1
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"cliVersion":"0.18.0","whitelist":null,"chains":{"people_lite":"0x50b8c73c2a3438eeddf39175bda7d60b"}}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createAccountId } from '@novasamatech/statement-store';
|
|
2
|
-
import { AccountId, Binary } from '@polkadot-api/substrate-bindings';
|
|
3
2
|
import { mergeUint8 } from '@polkadot-api/utils';
|
|
4
3
|
import { blake2b256 } from '@polkadot-labs/hdkd-helpers';
|
|
5
4
|
import { customAlphabet } from 'nanoid';
|
|
6
5
|
import { errAsync, fromAsyncThrowable, fromPromise, okAsync } from 'neverthrow';
|
|
6
|
+
import { AccountId, Binary } from 'polkadot-api';
|
|
7
7
|
import { getPolkadotSigner } from 'polkadot-api/signer';
|
|
8
8
|
import { Bytes, Option, Tuple, str } from 'scale-ts';
|
|
9
9
|
import { member_from_entropy, sign } from 'verifiablejs/bundler';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-papp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.0-
|
|
4
|
+
"version": "0.5.0-19",
|
|
5
5
|
"description": "Polkadot app integration",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"@noble/ciphers": "2.1.1",
|
|
29
29
|
"@noble/curves": "2.0.1",
|
|
30
30
|
"@noble/hashes": "2.0.1",
|
|
31
|
-
"@novasamatech/host-api": "0.5.0-
|
|
32
|
-
"@novasamatech/statement-store": "0.5.0-
|
|
33
|
-
"@novasamatech/storage-adapter": "0.5.0-
|
|
31
|
+
"@novasamatech/host-api": "0.5.0-19",
|
|
32
|
+
"@novasamatech/statement-store": "0.5.0-19",
|
|
33
|
+
"@novasamatech/storage-adapter": "0.5.0-19",
|
|
34
34
|
"@polkadot-api/substrate-bindings": "^0.16.5",
|
|
35
35
|
"@polkadot-labs/hdkd-helpers": "^0.0.27",
|
|
36
36
|
"@scure/sr25519": "1.0.0",
|
|
37
37
|
"nanoevents": "9.1.0",
|
|
38
38
|
"nanoid": "5.1.6",
|
|
39
39
|
"neverthrow": "^8.2.0",
|
|
40
|
-
"polkadot-api": "^1.23.
|
|
40
|
+
"polkadot-api": "^1.23.2",
|
|
41
41
|
"scale-ts": "1.6.1",
|
|
42
42
|
"verifiablejs": "1.1.0"
|
|
43
43
|
},
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { LazyClient } from '@novasamatech/statement-store';
|
|
2
|
-
import type { StorageAdapter } from '@novasamatech/storage-adapter';
|
|
3
|
-
import { ResultAsync } from 'neverthrow';
|
|
4
|
-
import type { Identity, IdentityAdapter } from './types.js';
|
|
5
|
-
export declare function createCachedIdentityRequester(storage: StorageAdapter, getKey: (accountId: string) => string, request: (accounts: string[]) => ResultAsync<(Identity | null)[], Error>): (accounts: string[]) => ResultAsync<Record<string, Identity | null>, Error>;
|
|
6
|
-
export declare function createIdentityRpcAdapter(lazyClient: LazyClient, storage: StorageAdapter): IdentityAdapter;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Result, ResultAsync, err, errAsync, fromPromise, ok, okAsync } from 'neverthrow';
|
|
2
|
-
import { AccountId } from 'polkadot-api';
|
|
3
|
-
import { toError } from '../../helpers/utils.js';
|
|
4
|
-
function zipWith(arrays, iteratee) {
|
|
5
|
-
if (arrays.length === 0)
|
|
6
|
-
return [];
|
|
7
|
-
const minLength = Math.min(...arrays.map(arr => arr.length));
|
|
8
|
-
const result = [];
|
|
9
|
-
for (let i = 0; i < minLength; i++) {
|
|
10
|
-
const values = arrays.map(arr => arr[i]);
|
|
11
|
-
result.push(iteratee(values));
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
export function createCachedIdentityRequester(storage, getKey, request) {
|
|
16
|
-
function readSingleCacheRecord(accountId) {
|
|
17
|
-
return storage.read(getKey(accountId)).andThen(raw => {
|
|
18
|
-
if (!raw) {
|
|
19
|
-
return ok(null);
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
return ok(JSON.parse(raw));
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
return err(toError(e));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function writeSingleCacheRecord(accountId, identity) {
|
|
30
|
-
if (identity === null) {
|
|
31
|
-
return okAsync(undefined);
|
|
32
|
-
}
|
|
33
|
-
return storage.write(getKey(accountId), JSON.stringify(identity));
|
|
34
|
-
}
|
|
35
|
-
function readCache(accounts) {
|
|
36
|
-
if (accounts.length === 0) {
|
|
37
|
-
return okAsync({});
|
|
38
|
-
}
|
|
39
|
-
const identities = ResultAsync.combine(accounts.map(readSingleCacheRecord));
|
|
40
|
-
return identities.map(identities => {
|
|
41
|
-
return Object.fromEntries(identities.map((x, i) => {
|
|
42
|
-
const accountId = accounts.at(i);
|
|
43
|
-
if (!accountId) {
|
|
44
|
-
throw new Error(`Identity not found`);
|
|
45
|
-
}
|
|
46
|
-
return [accountId, x];
|
|
47
|
-
}));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function writeCache(identities) {
|
|
51
|
-
return ResultAsync.combine(Object.entries(identities).map(args => writeSingleCacheRecord(...args))).map(() => identities);
|
|
52
|
-
}
|
|
53
|
-
return (accounts) => {
|
|
54
|
-
return readCache(accounts).andThen(existing => {
|
|
55
|
-
const emptyIdentities = Object.entries(existing)
|
|
56
|
-
.filter(([, identity]) => identity === null)
|
|
57
|
-
.map(([accountId]) => accountId);
|
|
58
|
-
if (emptyIdentities.length === 0) {
|
|
59
|
-
return okAsync(existing);
|
|
60
|
-
}
|
|
61
|
-
return request(accounts)
|
|
62
|
-
.map(response => Object.fromEntries(zipWith([accounts, response], x => x)))
|
|
63
|
-
.andThen(writeCache)
|
|
64
|
-
.map(fetched => ({
|
|
65
|
-
...existing,
|
|
66
|
-
...fetched,
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export function createIdentityRpcAdapter(lazyClient, storage) {
|
|
72
|
-
const requester = createCachedIdentityRequester(storage, (accountId) => `identity_${accountId}`, accounts => {
|
|
73
|
-
const client = lazyClient.getClient();
|
|
74
|
-
const unsafeApi = client.getUnsafeApi();
|
|
75
|
-
const method = unsafeApi.query.Resources?.Consumers;
|
|
76
|
-
if (!method) {
|
|
77
|
-
return errAsync(new Error('Method Resources:Consumers not found'));
|
|
78
|
-
}
|
|
79
|
-
const results = fromPromise(method.getValues([accounts.map(accCodec.dec)]), toError);
|
|
80
|
-
return results.andThen(results => {
|
|
81
|
-
if (!results) {
|
|
82
|
-
return ok(accounts.map(() => null));
|
|
83
|
-
}
|
|
84
|
-
return ok(zipWith([accounts, results], x => x).map(([accountId, raw]) => {
|
|
85
|
-
if (!raw) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
accountId: accountId,
|
|
90
|
-
fullUsername: raw.full_username ? raw.full_username.asText() : null,
|
|
91
|
-
liteUsername: raw.lite_username ? raw.lite_username.asText() : null,
|
|
92
|
-
credibility: raw.credibility.type,
|
|
93
|
-
};
|
|
94
|
-
}));
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
const accCodec = AccountId();
|
|
98
|
-
return {
|
|
99
|
-
readIdentities: requester,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ResultAsync } from 'neverthrow';
|
|
2
|
-
export type Identity = {
|
|
3
|
-
accountId: string;
|
|
4
|
-
fullUsername: string | null;
|
|
5
|
-
liteUsername: string;
|
|
6
|
-
credibility: string;
|
|
7
|
-
};
|
|
8
|
-
export type IdentityAdapter = {
|
|
9
|
-
readIdentities(accounts: string[]): ResultAsync<Record<string, Identity | null>, Error>;
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createClient } from 'polkadot-api';
|
|
2
|
-
export const createPapiLazyClient = (provider) => {
|
|
3
|
-
let client = null;
|
|
4
|
-
return {
|
|
5
|
-
getClient() {
|
|
6
|
-
if (!client) {
|
|
7
|
-
client = createClient(provider);
|
|
8
|
-
}
|
|
9
|
-
return client;
|
|
10
|
-
},
|
|
11
|
-
disconnect() {
|
|
12
|
-
if (client) {
|
|
13
|
-
client.destroy();
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -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 {};
|