@novasamatech/host-papp 0.5.0-8 → 0.5.0

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.
Files changed (152) hide show
  1. package/.papi/descriptors/dist/common-types.d.ts +8667 -0
  2. package/.papi/descriptors/dist/common.d.ts +1 -0
  3. package/.papi/descriptors/dist/descriptors-UUEW32EL.mjs +27 -0
  4. package/.papi/descriptors/dist/descriptors.d.ts +1 -0
  5. package/.papi/descriptors/dist/index.d.ts +10 -0
  6. package/.papi/descriptors/dist/index.js +237 -0
  7. package/.papi/descriptors/dist/index.mjs +148 -0
  8. package/.papi/descriptors/dist/metadataTypes-E4AQJDJR.mjs +6 -0
  9. package/.papi/descriptors/dist/metadataTypes.d.ts +2 -0
  10. package/.papi/descriptors/dist/people_lite.d.ts +7757 -0
  11. package/.papi/descriptors/dist/people_lite_metadata-EIVHV27X.mjs +6 -0
  12. package/.papi/descriptors/dist/people_lite_metadata.d.ts +2 -0
  13. package/.papi/descriptors/generated.json +1 -0
  14. package/.papi/descriptors/package.json +24 -0
  15. package/.papi/metadata/people_lite.scale +0 -0
  16. package/.papi/polkadot-api.json +15 -0
  17. package/dist/constants.d.ts +2 -2
  18. package/dist/constants.js +2 -2
  19. package/dist/{modules/crypto.d.ts → crypto.d.ts} +14 -12
  20. package/dist/crypto.js +87 -0
  21. package/dist/helpers/abortError.d.ts +0 -1
  22. package/dist/helpers/abortError.js +0 -3
  23. package/dist/{modules → helpers}/state.d.ts +1 -1
  24. package/dist/{modules → helpers}/state.js +5 -4
  25. package/dist/helpers/zipWith.d.ts +4 -0
  26. package/dist/helpers/zipWith.js +11 -0
  27. package/dist/identity/impl.d.ts +6 -0
  28. package/dist/identity/impl.js +68 -0
  29. package/dist/identity/rpcAdapter.d.ts +3 -0
  30. package/dist/identity/rpcAdapter.js +46 -0
  31. package/dist/identity/types.d.ts +21 -0
  32. package/dist/index.d.ts +7 -4
  33. package/dist/index.js +2 -7
  34. package/dist/papp.d.ts +24 -13
  35. package/dist/papp.js +19 -38
  36. package/dist/sso/auth/attestationService.d.ts +18 -0
  37. package/dist/sso/auth/attestationService.js +171 -0
  38. package/dist/sso/auth/impl.d.ts +79 -0
  39. package/dist/sso/auth/impl.js +186 -0
  40. package/dist/{components/auth/codec.d.ts → sso/auth/scale/handshake.d.ts} +3 -3
  41. package/dist/{components/auth/codec.js → sso/auth/scale/handshake.js} +3 -3
  42. package/dist/sso/auth/types.d.ts +28 -0
  43. package/dist/sso/sessionManager/impl.d.ts +22 -0
  44. package/dist/sso/sessionManager/impl.js +71 -0
  45. package/dist/sso/sessionManager/scale/hex.d.ts +1 -0
  46. package/dist/sso/sessionManager/scale/hex.js +3 -0
  47. package/dist/sso/sessionManager/scale/remoteMessage.d.ts +41 -0
  48. package/dist/sso/sessionManager/scale/remoteMessage.js +13 -0
  49. package/dist/sso/sessionManager/scale/signPayloadRequest.d.ts +20 -0
  50. package/dist/sso/sessionManager/scale/signPayloadRequest.js +20 -0
  51. package/dist/sso/sessionManager/scale/signPayloadResponse.d.ts +14 -0
  52. package/dist/sso/sessionManager/scale/signPayloadResponse.js +10 -0
  53. package/dist/{components/user → sso/sessionManager}/types.d.ts +1 -1
  54. package/dist/sso/sessionManager/userSession.d.ts +22 -0
  55. package/dist/sso/sessionManager/userSession.js +116 -0
  56. package/dist/sso/ssoSessionProver.d.ts +4 -0
  57. package/dist/sso/ssoSessionProver.js +35 -0
  58. package/dist/sso/userSecretRepository.d.ts +17 -0
  59. package/dist/sso/userSecretRepository.js +45 -0
  60. package/dist/sso/userSessionRepository.d.ts +18 -0
  61. package/dist/sso/userSessionRepository.js +26 -0
  62. package/package.json +13 -8
  63. package/dist/adapters/identity/rpc.d.ts +0 -6
  64. package/dist/adapters/identity/rpc.js +0 -101
  65. package/dist/adapters/identity/types.d.ts +0 -10
  66. package/dist/adapters/lazyClient/papi.d.ts +0 -3
  67. package/dist/adapters/lazyClient/papi.js +0 -17
  68. package/dist/adapters/lazyClient/types.d.ts +0 -5
  69. package/dist/adapters/statement/rpc.d.ts +0 -3
  70. package/dist/adapters/statement/rpc.js +0 -93
  71. package/dist/adapters/statement/types.d.ts +0 -9
  72. package/dist/adapters/storage/localStorage.d.ts +0 -2
  73. package/dist/adapters/storage/localStorage.js +0 -34
  74. package/dist/adapters/storage/memory.d.ts +0 -2
  75. package/dist/adapters/storage/memory.js +0 -22
  76. package/dist/adapters/storage/types.d.ts +0 -7
  77. package/dist/adapters/storage/types.js +0 -1
  78. package/dist/adapters/transport/rpc.d.ts +0 -3
  79. package/dist/adapters/transport/rpc.js +0 -51
  80. package/dist/adapters/transport/types.d.ts +0 -6
  81. package/dist/adapters/transport/types.js +0 -1
  82. package/dist/components/auth/codecs.d.ts +0 -9
  83. package/dist/components/auth/codecs.js +0 -10
  84. package/dist/components/auth/index.d.ts +0 -36
  85. package/dist/components/auth/index.js +0 -150
  86. package/dist/components/auth/types.d.ts +0 -15
  87. package/dist/components/auth/types.js +0 -1
  88. package/dist/components/session.d.ts +0 -34
  89. package/dist/components/session.js +0 -54
  90. package/dist/components/transport.d.ts +0 -27
  91. package/dist/components/transport.js +0 -57
  92. package/dist/components/user/codec.d.ts +0 -16
  93. package/dist/components/user/codec.js +0 -13
  94. package/dist/components/user/index.d.ts +0 -22
  95. package/dist/components/user/index.js +0 -58
  96. package/dist/components/user/ssoMessageStream.d.ts +0 -10
  97. package/dist/components/user/ssoMessageStream.js +0 -8
  98. package/dist/components/user/ssoSession.d.ts +0 -5
  99. package/dist/components/user/ssoSession.js +0 -5
  100. package/dist/components/user/storage.d.ts +0 -27
  101. package/dist/components/user/storage.js +0 -143
  102. package/dist/components/user/types.js +0 -1
  103. package/dist/components/user/userSessionStorage.d.ts +0 -20
  104. package/dist/components/user/userSessionStorage.js +0 -24
  105. package/dist/components/user.d.ts +0 -74
  106. package/dist/components/user.js +0 -188
  107. package/dist/helpers/result.d.ts +0 -12
  108. package/dist/helpers/result.js +0 -15
  109. package/dist/helpers/result.spec.d.ts +0 -1
  110. package/dist/helpers/result.spec.js +0 -23
  111. package/dist/helpers.d.ts +0 -1
  112. package/dist/helpers.js +0 -3
  113. package/dist/modules/accounts.d.ts +0 -1
  114. package/dist/modules/accounts.js +0 -2
  115. package/dist/modules/crypto.js +0 -84
  116. package/dist/modules/secretStorage.d.ts +0 -12
  117. package/dist/modules/secretStorage.js +0 -40
  118. package/dist/modules/session/helpers.d.ts +0 -5
  119. package/dist/modules/session/helpers.js +0 -29
  120. package/dist/modules/session/session.d.ts +0 -12
  121. package/dist/modules/session/session.js +0 -46
  122. package/dist/modules/session/types.d.ts +0 -12
  123. package/dist/modules/session/types.js +0 -1
  124. package/dist/modules/signIn.d.ts +0 -67
  125. package/dist/modules/signIn.js +0 -188
  126. package/dist/modules/statementStore.d.ts +0 -12
  127. package/dist/modules/statementStore.js +0 -20
  128. package/dist/modules/statementTopic.d.ts +0 -34
  129. package/dist/modules/statementTopic.js +0 -46
  130. package/dist/modules/storageView.d.ts +0 -25
  131. package/dist/modules/storageView.js +0 -51
  132. package/dist/modules/syncStorage.d.ts +0 -25
  133. package/dist/modules/syncStorage.js +0 -76
  134. package/dist/modules/transport/codec.d.ts +0 -24
  135. package/dist/modules/transport/codec.js +0 -36
  136. package/dist/modules/transport/crypto.d.ts +0 -2
  137. package/dist/modules/transport/crypto.js +0 -18
  138. package/dist/modules/transport/transport.d.ts +0 -27
  139. package/dist/modules/transport/transport.js +0 -56
  140. package/dist/modules/user.d.ts +0 -67
  141. package/dist/modules/user.js +0 -188
  142. package/dist/modules/userManager.d.ts +0 -15
  143. package/dist/modules/userManager.js +0 -105
  144. package/dist/modules/userStorage.d.ts +0 -19
  145. package/dist/modules/userStorage.js +0 -108
  146. package/dist/modules/userStore.d.ts +0 -15
  147. package/dist/modules/userStore.js +0 -105
  148. package/dist/structs.d.ts +0 -24
  149. package/dist/structs.js +0 -36
  150. /package/dist/{adapters/identity → identity}/types.js +0 -0
  151. /package/dist/{adapters/lazyClient → sso/auth}/types.js +0 -0
  152. /package/dist/{adapters/statement → sso/sessionManager}/types.js +0 -0
@@ -0,0 +1,2 @@
1
+ declare const binMeta: string;
2
+ export default binMeta;
@@ -0,0 +1 @@
1
+ {"cliVersion":"0.18.0","whitelist":null,"chains":{"people_lite":"0x50b8c73c2a3438eeddf39175bda7d60b"}}
@@ -0,0 +1,24 @@
1
+ {
2
+ "version": "0.1.0-autogenerated.16231069504393689218",
3
+ "name": "@polkadot-api/descriptors",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "module": "./dist/index.mjs",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.mjs",
18
+ "browser": "./dist/index.mjs",
19
+ "types": "./dist/index.d.ts",
20
+ "sideEffects": false,
21
+ "peerDependencies": {
22
+ "polkadot-api": ">=1.21.0"
23
+ }
24
+ }
Binary file
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": 0,
3
+ "descriptorPath": ".papi/descriptors",
4
+ "options": {
5
+ "noDescriptorsPackage": true
6
+ },
7
+ "entries": {
8
+ "people_lite": {
9
+ "wsUrl": "wss://pop3-testnet.parity-lab.parity.io:443/7912",
10
+ "metadata": ".papi/metadata/people_lite.scale",
11
+ "genesis": "0x41412e46623c200d788ab7ef1c507c43490fda2ca7b48c19f86ea9a46cf9caa8",
12
+ "codeHash": "0xe6895843ad86452552f9ec62c9793f457e04ab0c23ca1be6e8837c8b4b6d6be9"
13
+ }
14
+ }
15
+ }
@@ -1,2 +1,2 @@
1
- export declare const SS_DEV_ENDPOINTS: string[];
2
- export declare const SS_PROD_ENDPOINTS: string[];
1
+ export declare const SS_UNSTABLE_STAGE_ENDPOINTS: string[];
2
+ export declare const SS_STABLE_STAGE_ENDPOINTS: string[];
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
- export const SS_DEV_ENDPOINTS = ['wss://pop-testnet.parity-lab.parity.io:443/9910'];
2
- export const SS_PROD_ENDPOINTS = [
1
+ export const SS_UNSTABLE_STAGE_ENDPOINTS = ['wss://pop-testnet.parity-lab.parity.io:443/9910'];
2
+ export const SS_STABLE_STAGE_ENDPOINTS = [
3
3
  'wss://pop3-testnet.parity-lab.parity.io:443/7911',
4
4
  'wss://pop3-testnet.parity-lab.parity.io:443/7912',
5
5
  ];
@@ -1,27 +1,29 @@
1
1
  import type { Codec } from 'scale-ts';
2
- import type { Branded } from '../types.js';
2
+ import type { Branded } from './types.js';
3
3
  export type SsPublicKey = Branded<Uint8Array, 'SsPublicKey'>;
4
4
  export type SsSecret = Branded<Uint8Array, 'SsSecret'>;
5
5
  export type EncrPublicKey = Branded<Uint8Array, 'EncrPublicKey'>;
6
6
  export type EncrSecret = Branded<Uint8Array, 'EncrSecret'>;
7
7
  export type SharedSecret = Branded<Uint8Array, 'SharedSecret'>;
8
8
  export type SharedSession = Branded<Uint8Array, 'SharedSession'>;
9
+ export declare function BrandedBytesCodec<T extends Uint8Array>(length?: number): Codec<T>;
9
10
  export declare const SsPubKey: Codec<SsPublicKey>;
10
11
  export declare const EncrPubKey: Codec<EncrPublicKey>;
11
12
  export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
12
13
  export declare function bytesToString(bytes: Uint8Array): string;
13
- export declare function mergeBytes(...bytes: Uint8Array[]): Uint8Array<ArrayBuffer>;
14
- export declare const SS_SECRET_SEED_SIZE = 32;
15
- export declare function createSsSecret(seed: Uint8Array): SsSecret;
16
- export declare function createSsHardDerivation(secret: SsSecret, derivation: string | number): SsSecret;
14
+ export declare function createSsSecret(entropy: Uint8Array): SsSecret;
15
+ export declare function createSsDerivation(secret: SsSecret, derivation: string): SsSecret;
17
16
  export declare function getSsPub(secret: SsSecret): SsPublicKey;
18
17
  export declare function signWithSsSecret(secret: SsSecret, message: Uint8Array): Uint8Array<ArrayBufferLike>;
19
- export declare const ENCR_SECRET_SEED_SIZE = 48;
20
- export declare function createEncrSecret(seed: Uint8Array): EncrSecret;
18
+ export declare function verifyWithSsSecret(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
19
+ export type DerivedSr25519Account = {
20
+ secret: SsSecret;
21
+ publicKey: SsPublicKey;
22
+ entropy: Uint8Array;
23
+ sign(message: Uint8Array): Uint8Array;
24
+ verify(message: Uint8Array, signature: Uint8Array): boolean;
25
+ };
26
+ export declare function deriveSr25519Account(mnemonic: string, derivation: string): DerivedSr25519Account;
27
+ export declare function createEncrSecret(entropy: Uint8Array): EncrSecret;
21
28
  export declare function getEncrPub(secret: EncrSecret): EncrPublicKey;
22
- export declare function createRandomSeed(suffix: string, size: number): Uint8Array<ArrayBufferLike>;
23
- export declare function createStableSeed(value: string, size: number): Uint8Array<ArrayBufferLike>;
24
- export declare function khash(secret: Uint8Array, message: Uint8Array): Uint8Array<ArrayBufferLike>;
25
29
  export declare function createSharedSecret(secret: EncrSecret, publicKey: Uint8Array): SharedSecret;
26
- export declare function encrypt(secret: Uint8Array, cipherText: Uint8Array): Uint8Array<ArrayBufferLike>;
27
- export declare function decrypt(secret: Uint8Array, message: Uint8Array): Uint8Array<ArrayBufferLike>;
package/dist/crypto.js ADDED
@@ -0,0 +1,87 @@
1
+ import { p256 } from '@noble/curves/nist.js';
2
+ import { entropyToMiniSecret, mnemonicToEntropy } from '@polkadot-labs/hdkd-helpers';
3
+ import { HDKD as sr25519HDKD, getPublicKey as sr25519GetPublicKey, secretFromSeed as sr25519SecretFromSeed, sign as sr25519Sign, verify as sr25519Verify, } from '@scure/sr25519';
4
+ import { Bytes, str } from 'scale-ts';
5
+ // schemas
6
+ export function BrandedBytesCodec(length) {
7
+ return Bytes(length);
8
+ }
9
+ export const SsPubKey = BrandedBytesCodec(32);
10
+ export const EncrPubKey = BrandedBytesCodec(65);
11
+ // helpers
12
+ const textEncoder = new TextEncoder();
13
+ const textDecoder = new TextDecoder();
14
+ export function stringToBytes(str) {
15
+ return textEncoder.encode(str);
16
+ }
17
+ export function bytesToString(bytes) {
18
+ return textDecoder.decode(bytes);
19
+ }
20
+ function parseDerivations(derivationsStr) {
21
+ const DERIVATION_RE = /(\/{1,2})([^/]+)/g;
22
+ const derivations = [];
23
+ for (const [, type, code] of derivationsStr.matchAll(DERIVATION_RE)) {
24
+ if (code) {
25
+ derivations.push([type === '//' ? 'hard' : 'soft', code]);
26
+ }
27
+ }
28
+ return derivations;
29
+ }
30
+ function createChainCode(derivation) {
31
+ const chainCode = new Uint8Array(32);
32
+ chainCode.set(str.enc(derivation));
33
+ return chainCode;
34
+ }
35
+ // statement store key pair
36
+ export function createSsSecret(entropy) {
37
+ const miniSecret = entropyToMiniSecret(entropy);
38
+ return sr25519SecretFromSeed(miniSecret);
39
+ }
40
+ export function createSsDerivation(secret, derivation) {
41
+ const derivations = parseDerivations(derivation);
42
+ return derivations.reduce((secret, [type, derivation]) => {
43
+ const chainCode = createChainCode(derivation);
44
+ switch (type) {
45
+ case 'hard':
46
+ return sr25519HDKD.secretHard(secret, chainCode);
47
+ case 'soft':
48
+ return sr25519HDKD.secretSoft(secret, chainCode);
49
+ }
50
+ }, secret);
51
+ }
52
+ export function getSsPub(secret) {
53
+ return sr25519GetPublicKey(secret);
54
+ }
55
+ export function signWithSsSecret(secret, message) {
56
+ return sr25519Sign(secret, message);
57
+ }
58
+ export function verifyWithSsSecret(message, signature, publicKey) {
59
+ return sr25519Verify(message, signature, publicKey);
60
+ }
61
+ export function deriveSr25519Account(mnemonic, derivation) {
62
+ const entropy = mnemonicToEntropy(mnemonic);
63
+ const secret = createSsDerivation(createSsSecret(entropy), derivation);
64
+ const publicKey = getSsPub(secret);
65
+ return {
66
+ secret,
67
+ publicKey,
68
+ entropy,
69
+ sign: message => signWithSsSecret(secret, message),
70
+ verify: (message, signature) => verifyWithSsSecret(message, signature, publicKey),
71
+ };
72
+ }
73
+ // encryption key pair
74
+ export function createEncrSecret(entropy) {
75
+ const miniSecret = entropyToMiniSecret(entropy);
76
+ const seed = new Uint8Array(48);
77
+ seed.set(miniSecret);
78
+ const { secretKey } = p256.keygen(seed);
79
+ return secretKey;
80
+ }
81
+ export function getEncrPub(secret) {
82
+ return p256.getPublicKey(secret, false);
83
+ }
84
+ export function createSharedSecret(secret, publicKey) {
85
+ // slicing first byte: @noble/curves adds y offset at the start
86
+ return p256.getSharedSecret(secret, publicKey).slice(1, 33);
87
+ }
@@ -1,4 +1,3 @@
1
1
  export declare class AbortError extends Error {
2
2
  constructor(message?: string);
3
- static isAbortError(err: unknown): err is AbortError;
4
3
  }
@@ -2,7 +2,4 @@ export class AbortError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
4
  }
5
- static isAbortError(err) {
6
- return err instanceof AbortError;
7
- }
8
5
  }
@@ -1,7 +1,7 @@
1
1
  type State<T> = ReturnType<typeof createState<T>>;
2
2
  export declare function createState<T>(initial: T): {
3
3
  read(): T;
4
- write(value: T): T;
4
+ write(value: T | ((prev: T) => T)): T;
5
5
  reset(): void;
6
6
  subscribe(fn: (value: T) => void): () => void;
7
7
  onFirstSubscribe(callback: VoidFunction): import("nanoevents").Unsubscribe;
@@ -7,11 +7,12 @@ export function createState(initial) {
7
7
  return currentValue;
8
8
  },
9
9
  write(value) {
10
- if (currentValue !== value) {
11
- currentValue = value;
12
- events.emit('value', value);
10
+ const actialValue = typeof value === 'function' ? value(currentValue) : value;
11
+ if (currentValue !== actialValue) {
12
+ currentValue = actialValue;
13
+ events.emit('value', actialValue);
13
14
  }
14
- return value;
15
+ return actialValue;
15
16
  },
16
17
  reset() {
17
18
  if (currentValue !== initial) {
@@ -0,0 +1,4 @@
1
+ type InferArrayItem<T> = T extends Array<infer U> ? U : never;
2
+ type InferArgs<Args extends unknown[][]> = Args extends [infer Head, ...infer Tail extends unknown[][]] ? [InferArrayItem<Head>, ...InferArgs<Tail>] : [];
3
+ export declare function zipWith<const Args extends unknown[][], R>(arrays: Args, iteratee: (values: InferArgs<Args>) => R): R[];
4
+ export {};
@@ -0,0 +1,11 @@
1
+ export function zipWith(arrays, iteratee) {
2
+ if (arrays.length === 0)
3
+ return [];
4
+ const minLength = Math.min(...arrays.map(arr => arr.length));
5
+ const result = [];
6
+ for (let i = 0; i < minLength; i++) {
7
+ const values = arrays.map(arr => arr[i]);
8
+ result.push(iteratee(values));
9
+ }
10
+ return result;
11
+ }
@@ -0,0 +1,6 @@
1
+ import type { StorageAdapter } from '@novasamatech/storage-adapter';
2
+ import type { IdentityAdapter, IdentityRepository } from './types.js';
3
+ export declare function createIdentityRepository({ adapter, storage, }: {
4
+ adapter: IdentityAdapter;
5
+ storage: StorageAdapter;
6
+ }): IdentityRepository;
@@ -0,0 +1,68 @@
1
+ import { Result, ResultAsync, err, ok, okAsync } from 'neverthrow';
2
+ import { toError } from '../helpers/utils.js';
3
+ export function createIdentityRepository({ adapter, storage, }) {
4
+ const cachedRequester = createCachedIdentityRequester(storage, accountId => `identity_${accountId}`);
5
+ return {
6
+ getIdentity(accountId) {
7
+ return cachedRequester([accountId], adapter.readIdentities).map(map => map[accountId] ?? null);
8
+ },
9
+ getIdentities(accounts) {
10
+ return cachedRequester(accounts, adapter.readIdentities);
11
+ },
12
+ };
13
+ }
14
+ function createCachedIdentityRequester(storage, getKey) {
15
+ function readSingleCacheRecord(accountId) {
16
+ return storage.read(getKey(accountId)).andThen(raw => {
17
+ if (!raw) {
18
+ return ok(null);
19
+ }
20
+ try {
21
+ return ok(JSON.parse(raw));
22
+ }
23
+ catch (e) {
24
+ return err(toError(e));
25
+ }
26
+ });
27
+ }
28
+ function writeSingleCacheRecord(accountId, identity) {
29
+ if (identity === null) {
30
+ return okAsync(undefined);
31
+ }
32
+ return storage.write(getKey(accountId), JSON.stringify(identity));
33
+ }
34
+ function readCache(accounts) {
35
+ if (accounts.length === 0) {
36
+ return okAsync({});
37
+ }
38
+ const identities = ResultAsync.combine(accounts.map(readSingleCacheRecord));
39
+ return identities.map(identities => {
40
+ return Object.fromEntries(identities.map((x, i) => {
41
+ const accountId = accounts.at(i);
42
+ if (!accountId) {
43
+ throw new Error(`Identity not found`);
44
+ }
45
+ return [accountId, x];
46
+ }));
47
+ });
48
+ }
49
+ function writeCache(identities) {
50
+ return ResultAsync.combine(Object.entries(identities).map(args => writeSingleCacheRecord(...args))).map(() => identities);
51
+ }
52
+ return (accounts, request) => {
53
+ return readCache(accounts).andThen(existing => {
54
+ const emptyIdentities = Object.entries(existing)
55
+ .filter(([, identity]) => identity === null)
56
+ .map(([accountId]) => accountId);
57
+ if (emptyIdentities.length === 0) {
58
+ return okAsync(existing);
59
+ }
60
+ return request(accounts)
61
+ .andThen(writeCache)
62
+ .map(fetched => ({
63
+ ...existing,
64
+ ...fetched,
65
+ }));
66
+ });
67
+ };
68
+ }
@@ -0,0 +1,3 @@
1
+ import type { LazyClient } from '@novasamatech/statement-store';
2
+ import type { IdentityAdapter } from './types.js';
3
+ export declare function createIdentityRpcAdapter(lazyClient: LazyClient): IdentityAdapter;
@@ -0,0 +1,46 @@
1
+ import { AccountId } from '@polkadot-api/substrate-bindings';
2
+ import { errAsync, fromPromise, ok } from 'neverthrow';
3
+ import { toError } from '../helpers/utils.js';
4
+ import { zipWith } from '../helpers/zipWith.js';
5
+ export function createIdentityRpcAdapter(lazyClient) {
6
+ const accCodec = AccountId();
7
+ return {
8
+ readIdentities(accounts) {
9
+ const client = lazyClient.getClient();
10
+ const unsafeApi = client.getUnsafeApi();
11
+ const method = unsafeApi.query.Resources.Consumers;
12
+ if (!method) {
13
+ return errAsync(new Error('Method Resources.Consumers not found'));
14
+ }
15
+ const results = fromPromise(method.getValues(accounts.map(x => [accCodec.dec(x)])), toError);
16
+ return results.andThen(results => {
17
+ if (!results) {
18
+ return ok({});
19
+ }
20
+ return ok(Object.fromEntries(zipWith([accounts, results], x => x).map(([accountId, raw]) => {
21
+ if (!raw) {
22
+ return [accountId, null];
23
+ }
24
+ const credibility = raw.credibility.type == 'Lite'
25
+ ? {
26
+ type: 'Lite',
27
+ }
28
+ : {
29
+ type: 'Person',
30
+ alias: raw.credibility.value.alias.asHex(),
31
+ lastUpdate: raw.credibility.value.last_update.toString(),
32
+ };
33
+ return [
34
+ accountId,
35
+ {
36
+ accountId: accountId,
37
+ fullUsername: raw.full_username ? raw.full_username.asText() : null,
38
+ liteUsername: raw.lite_username.asText(),
39
+ credibility,
40
+ },
41
+ ];
42
+ })));
43
+ });
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,21 @@
1
+ import type { ResultAsync } from 'neverthrow';
2
+ export type Credibility = {
3
+ type: 'Lite';
4
+ } | {
5
+ type: 'Person';
6
+ alias: `0x${string}`;
7
+ lastUpdate: string;
8
+ };
9
+ export type Identity = {
10
+ accountId: string;
11
+ fullUsername: string | null;
12
+ liteUsername: string;
13
+ credibility: Credibility;
14
+ };
15
+ export type IdentityAdapter = {
16
+ readIdentities(accounts: string[]): ResultAsync<Record<string, Identity | null>, Error>;
17
+ };
18
+ export type IdentityRepository = {
19
+ getIdentity(accountId: string): ResultAsync<Identity | null, Error>;
20
+ getIdentities(accounts: string[]): ResultAsync<Record<string, Identity | null>, Error>;
21
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ export { SS_STABLE_STAGE_ENDPOINTS, SS_UNSTABLE_STAGE_ENDPOINTS } from './constants.js';
1
2
  export type { PappAdapter } from './papp.js';
2
- export type { AuthentificationStatus } from './components/auth/types.js';
3
- export type { UserSession } from './components/user/userSessionStorage.js';
4
- export type { Identity } from './adapters/identity/types.js';
5
- export declare function createPappHostAdapter(appId: string, metadata: string): import("./papp.js").PappAdapter;
3
+ export { createPappAdapter } from './papp.js';
4
+ export type { AttestationStatus, PairingStatus } from './sso/auth/types.js';
5
+ export type { UserSession } from './sso/sessionManager/userSession.js';
6
+ export type { Identity } from './identity/types.js';
7
+ export type { SignPayloadRequest } from './sso/sessionManager/scale/signPayloadRequest.js';
8
+ export type { SignPayloadResponse } from './sso/sessionManager/scale/signPayloadResponse.js';
package/dist/index.js CHANGED
@@ -1,7 +1,2 @@
1
- import { createPappAdapter } from './papp.js';
2
- export function createPappHostAdapter(appId, metadata) {
3
- return createPappAdapter({
4
- appId,
5
- metadata,
6
- });
7
- }
1
+ export { SS_STABLE_STAGE_ENDPOINTS, SS_UNSTABLE_STAGE_ENDPOINTS } from './constants.js';
2
+ export { createPappAdapter } from './papp.js';
package/dist/papp.d.ts CHANGED
@@ -1,26 +1,37 @@
1
- import type { ResultAsync } from 'neverthrow';
2
- import type { Identity, IdentityAdapter } from './adapters/identity/types.js';
3
- import type { StatementAdapter } from './adapters/statement/types.js';
4
- import type { StorageAdapter } from './adapters/storage/types.js';
5
- import type { AuthComponent } from './components/auth/index.js';
6
- import type { UserSessionsComponent } from './components/user/index.js';
1
+ import type { LazyClient, StatementStoreAdapter } from '@novasamatech/statement-store';
2
+ import type { StorageAdapter } from '@novasamatech/storage-adapter';
3
+ import type { IdentityAdapter, IdentityRepository } from './identity/types.js';
4
+ import type { AuthComponent } from './sso/auth/impl.js';
5
+ import type { SsoSessionManager } from './sso/sessionManager/impl.js';
7
6
  export type PappAdapter = {
8
7
  sso: AuthComponent;
9
- sessions: UserSessionsComponent;
10
- identity: {
11
- getIdentity(accountId: string): ResultAsync<Identity | null, Error>;
12
- getIdentities(accounts: string[]): ResultAsync<Record<string, Identity | null>, Error>;
13
- };
8
+ sessions: SsoSessionManager;
9
+ identity: IdentityRepository;
14
10
  };
15
11
  type Adapters = {
16
- statements: StatementAdapter;
12
+ statementStore: StatementStoreAdapter;
17
13
  identities: IdentityAdapter;
18
14
  storage: StorageAdapter;
15
+ lazyClient: LazyClient;
19
16
  };
20
17
  type Params = {
18
+ /**
19
+ * Host app Id.
20
+ * CAUTION! This value should be stable.
21
+ */
21
22
  appId: string;
23
+ /**
24
+ * URL for additional metadata that will be displayed during pairing process.
25
+ * Content of provided json shound be
26
+ * ```ts
27
+ * interface Metadata {
28
+ * name: string;
29
+ * icon: string; // url for icon. Icon should be a rasterized image with min size 256x256 px.
30
+ * }
31
+ * ```
32
+ */
22
33
  metadata: string;
23
- adapters?: Adapters;
34
+ adapters?: Partial<Adapters>;
24
35
  };
25
36
  export declare function createPappAdapter({ appId, metadata, adapters }: Params): PappAdapter;
26
37
  export {};
package/dist/papp.js CHANGED
@@ -1,42 +1,23 @@
1
+ import { createLazyClient, createPapiStatementStoreAdapter } from '@novasamatech/statement-store';
2
+ import { createLocalStorageAdapter } from '@novasamatech/storage-adapter';
1
3
  import { getWsProvider } from '@polkadot-api/ws-provider';
2
- import { createIdentityRpcAdapter } from './adapters/identity/rpc.js';
3
- import { createPapiLazyClient } from './adapters/lazyClient/papi.js';
4
- import { createPapiStatementAdapter } from './adapters/statement/rpc.js';
5
- import { createLocalStorageAdapter } from './adapters/storage/localStorage.js';
6
- import { createAuthComponent } from './components/auth/index.js';
7
- import { createUserSessionsComponent } from './components/user/index.js';
8
- import { createUserSessionStorage } from './components/user/userSessionStorage.js';
9
- import { SS_PROD_ENDPOINTS } from './constants.js';
10
- import { createTransport } from './modules/transport/transport.js';
4
+ import { SS_STABLE_STAGE_ENDPOINTS } from './constants.js';
5
+ import { createIdentityRepository } from './identity/impl.js';
6
+ import { createIdentityRpcAdapter } from './identity/rpcAdapter.js';
7
+ import { createAuth } from './sso/auth/impl.js';
8
+ import { createSsoSessionManager } from './sso/sessionManager/impl.js';
9
+ import { createUserSecretRepository } from './sso/userSecretRepository.js';
10
+ import { createUserSessionRepository } from './sso/userSessionRepository.js';
11
11
  export function createPappAdapter({ appId, metadata, adapters }) {
12
- let statements;
13
- let identities;
14
- let storage;
15
- if (adapters) {
16
- statements = adapters.statements;
17
- identities = adapters.identities;
18
- storage = adapters.storage;
19
- }
20
- else {
21
- const lazyPapiAdapter = createPapiLazyClient(getWsProvider(SS_PROD_ENDPOINTS));
22
- storage = createLocalStorageAdapter(appId);
23
- identities = createIdentityRpcAdapter(lazyPapiAdapter, storage);
24
- statements = createPapiStatementAdapter(lazyPapiAdapter);
25
- }
26
- const transport = createTransport({ adapter: statements });
27
- const userSessionStorage = createUserSessionStorage({ storage });
28
- const identityComponent = {
29
- getIdentity(accountId) {
30
- return identities.readIdentities([accountId]).map(map => map[accountId] ?? null);
31
- },
32
- getIdentities(accounts) {
33
- return identities.readIdentities(accounts);
34
- },
12
+ const lazyClient = adapters?.lazyClient ?? createLazyClient(getWsProvider(SS_STABLE_STAGE_ENDPOINTS));
13
+ const statementStore = adapters?.statementStore ?? createPapiStatementStoreAdapter(lazyClient);
14
+ const identities = adapters?.identities ?? createIdentityRpcAdapter(lazyClient);
15
+ const storage = adapters?.storage ?? createLocalStorageAdapter(appId);
16
+ const ssoSessionRepository = createUserSessionRepository(storage);
17
+ const userSecretRepository = createUserSecretRepository(appId, storage);
18
+ return {
19
+ sso: createAuth({ metadata, statementStore, ssoSessionRepository, userSecretRepository, lazyClient }),
20
+ sessions: createSsoSessionManager({ storage, statementStore, ssoSessionRepository, userSecretRepository }),
21
+ identity: createIdentityRepository({ adapter: identities, storage }),
35
22
  };
36
- const papp = {
37
- sso: createAuthComponent({ appId, metadata, transport, userSessionStorage }),
38
- sessions: createUserSessionsComponent({ transport, storage, userSessionStorage }),
39
- identity: identityComponent,
40
- };
41
- return papp;
42
23
  }
@@ -0,0 +1,18 @@
1
+ import type { LazyClient } from '@novasamatech/statement-store';
2
+ import type { ResultAsync } from 'neverthrow';
3
+ import type { DerivedSr25519Account } from '../../crypto.js';
4
+ export declare function createAliceVerifier(): DerivedSr25519Account;
5
+ export declare const createAttestationService: (lazyClient: LazyClient) => {
6
+ claimUsername(): string;
7
+ grantVerifierAllowance(verifier: DerivedSr25519Account): ResultAsync<void, Error>;
8
+ getRingRfKey(candidate: DerivedSr25519Account): Uint8Array<ArrayBufferLike>;
9
+ getProofMessage(candidate: DerivedSr25519Account, ringVrfKey: Uint8Array): Uint8Array<ArrayBufferLike>;
10
+ deriveAttestationParams(username: string, candidate: DerivedSr25519Account, verifier: DerivedSr25519Account): ResultAsync<{
11
+ candidateSignature: Uint8Array<ArrayBufferLike>;
12
+ ringVrfKey: Uint8Array<ArrayBufferLike>;
13
+ proofOfOwnership: Uint8Array<ArrayBufferLike>;
14
+ identifierKey: import("../../crypto.js").EncrPublicKey;
15
+ consumerRegistrationSignature: Uint8Array<ArrayBufferLike>;
16
+ }, never>;
17
+ registerLitePerson(username: string, candidate: DerivedSr25519Account, verifier: DerivedSr25519Account): ResultAsync<void, Error>;
18
+ };