@novasamatech/host-papp 0.6.1 → 0.6.3

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/dist/constants.js CHANGED
@@ -1,6 +1,3 @@
1
1
  export const SS_UNSTABLE_STAGE_ENDPOINTS = ['wss://pop-testnet.parity-lab.parity.io:443/9910'];
2
- export const SS_STABLE_STAGE_ENDPOINTS = [
3
- 'wss://pop3-testnet.parity-lab.parity.io:443/7911',
4
- 'wss://pop3-testnet.parity-lab.parity.io:443/7912',
5
- ];
2
+ export const SS_STABLE_STAGE_ENDPOINTS = ['wss://pop3-testnet.parity-lab.parity.io/people'];
6
3
  export const SS_PREVIEW_STAGE_ENDPOINTS = ['wss://previewnet.substrate.dev/people'];
package/dist/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export type { AttestationStatus, PairingStatus } from './sso/auth/types.js';
5
5
  export type { UserSession } from './sso/sessionManager/userSession.js';
6
6
  export type { StoredUserSession } from './sso/userSessionRepository.js';
7
7
  export type { Identity } from './identity/types.js';
8
- export type { SignPayloadRequest } from './sso/sessionManager/scale/signingRequest.js';
8
+ export type { SignPayloadRequest, SigningRawRequest } from './sso/sessionManager/scale/signingRequest.js';
9
9
  export type { SignPayloadResponse } from './sso/sessionManager/scale/signingResponse.js';
@@ -61,19 +61,18 @@ export function createAuth({ metadata, statementStore, ssoSessionRepository, use
61
61
  }
62
62
  }
63
63
  });
64
- const secretesSaved = pappResponse.andThen(({ id }) => {
65
- return userSecretRepository.write(id, {
64
+ const sessionWithSecretsPayload = pappResponse.map(session => ({
65
+ session,
66
+ secretsPayload: {
67
+ id: session.id,
66
68
  ssSecret: account.secret,
67
69
  encrSecret: encrKeys.secret,
68
70
  entropy: account.entropy,
69
- });
70
- });
71
- // secrets and sso session should be chained, or it can produce an incorrect state
72
- const userCreated = secretesSaved.andThen(() => pappResponse.andThen(ssoSessionRepository.add));
73
- const sessionReceived = ResultAsync.combine([userCreated, secretesSaved]).map(([session]) => session);
74
- return sessionReceived
75
- .andTee(session => {
76
- pairingStatus.write(session ? { step: 'finished', session } : { step: 'none' });
71
+ },
72
+ }));
73
+ return sessionWithSecretsPayload
74
+ .andTee(({ session }) => {
75
+ pairingStatus.write({ step: 'finished', session });
77
76
  })
78
77
  .orTee(e => {
79
78
  if (!(e instanceof AbortError)) {
@@ -92,7 +91,18 @@ export function createAuth({ metadata, statementStore, ssoSessionRepository, use
92
91
  abort = new AbortController();
93
92
  const account = deriveSr25519Account(generateMnemonic(), '//wallet//sso');
94
93
  authResult = ResultAsync.combine([handshake(account, abort.signal), attestAccount(account, abort.signal)])
95
- .map(([session]) => session)
94
+ .andThen(([handshakeResult]) => {
95
+ // Save secrets and sso session only after attestation has finished
96
+ const { session, secretsPayload } = handshakeResult;
97
+ return userSecretRepository
98
+ .write(secretsPayload.id, {
99
+ ssSecret: secretsPayload.ssSecret,
100
+ encrSecret: secretsPayload.encrSecret,
101
+ entropy: secretsPayload.entropy,
102
+ })
103
+ .andThen(() => ssoSessionRepository.add(session))
104
+ .map(() => session);
105
+ })
96
106
  .orElse(e => (e instanceof AbortError ? ok(null) : err(e)))
97
107
  .andTee(() => {
98
108
  abort = null;
@@ -10,19 +10,7 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
10
10
  } | {
11
11
  tag: "SignRequest";
12
12
  value: {
13
- tag: "raw";
14
- value: {
15
- address: string;
16
- data: {
17
- tag: "Bytes";
18
- value: Uint8Array<ArrayBufferLike>;
19
- } | {
20
- tag: "Payload";
21
- value: string;
22
- };
23
- };
24
- } | {
25
- tag: "payload";
13
+ tag: "Payload";
26
14
  value: {
27
15
  address: string;
28
16
  blockHash: `0x${string}`;
@@ -41,6 +29,18 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
41
29
  mode: number | undefined;
42
30
  withSignedTransaction: boolean | undefined;
43
31
  };
32
+ } | {
33
+ tag: "Raw";
34
+ value: {
35
+ address: string;
36
+ data: {
37
+ tag: "Bytes";
38
+ value: Uint8Array<ArrayBufferLike>;
39
+ } | {
40
+ tag: "Payload";
41
+ value: string;
42
+ };
43
+ };
44
44
  };
45
45
  } | {
46
46
  tag: "SignResponse";
@@ -30,19 +30,7 @@ export declare const SigningRawRequestCodec: import("scale-ts").Codec<{
30
30
  };
31
31
  }>;
32
32
  export declare const SigningRequestCodec: import("scale-ts").Codec<{
33
- tag: "raw";
34
- value: {
35
- address: string;
36
- data: {
37
- tag: "Bytes";
38
- value: Uint8Array<ArrayBufferLike>;
39
- } | {
40
- tag: "Payload";
41
- value: string;
42
- };
43
- };
44
- } | {
45
- tag: "payload";
33
+ tag: "Payload";
46
34
  value: {
47
35
  address: string;
48
36
  blockHash: `0x${string}`;
@@ -61,4 +49,16 @@ export declare const SigningRequestCodec: import("scale-ts").Codec<{
61
49
  mode: number | undefined;
62
50
  withSignedTransaction: boolean | undefined;
63
51
  };
52
+ } | {
53
+ tag: "Raw";
54
+ value: {
55
+ address: string;
56
+ data: {
57
+ tag: "Bytes";
58
+ value: Uint8Array<ArrayBufferLike>;
59
+ } | {
60
+ tag: "Payload";
61
+ value: string;
62
+ };
63
+ };
64
64
  }>;
@@ -26,6 +26,6 @@ export const SigningRawRequestCodec = Struct({
26
26
  }),
27
27
  });
28
28
  export const SigningRequestCodec = Enum({
29
- payload: SigningPayloadRequestCodec,
30
- raw: SigningRawRequestCodec,
29
+ Payload: SigningPayloadRequestCodec,
30
+ Raw: SigningRawRequestCodec,
31
31
  });
@@ -1,12 +1,12 @@
1
- import { enumValue } from '@novasamatech/scale';
1
+ import { enumValue, toHex } from '@novasamatech/scale';
2
2
  import { createSession } from '@novasamatech/statement-store';
3
3
  import { fieldListView } from '@novasamatech/storage-adapter';
4
4
  import { AccountId } from '@polkadot-api/substrate-bindings';
5
- import { toHex } from '@polkadot-api/utils';
6
5
  import { nanoid } from 'nanoid';
7
6
  import { ResultAsync, err, errAsync, ok, okAsync } from 'neverthrow';
8
7
  import { RemoteMessageCodec } from './scale/remoteMessage.js';
9
8
  export function createUserSession({ userSession, statementStore, encryption, storage, prover, }) {
9
+ const accountId = AccountId();
10
10
  const session = createSession({
11
11
  localAccount: userSession.localAccount,
12
12
  remoteAccount: userSession.remoteAccount,
@@ -20,19 +20,32 @@ export function createUserSession({ userSession, statementStore, encryption, sto
20
20
  from: JSON.parse,
21
21
  to: JSON.stringify,
22
22
  });
23
+ function toAccountId(address) {
24
+ // already account id
25
+ if (address.startsWith('0x') && address.length === 64 + 2) {
26
+ return address;
27
+ }
28
+ return toHex(accountId.enc(address));
29
+ }
30
+ function toAddress(account) {
31
+ return accountId.dec(account);
32
+ }
23
33
  return {
24
34
  id: userSession.id,
25
35
  localAccount: userSession.localAccount,
26
36
  remoteAccount: userSession.remoteAccount,
27
37
  signPayload(payload) {
28
- const accountId = AccountId();
29
- if (toHex(accountId.enc(payload.address)) !== toHex(userSession.remoteAccount.accountId)) {
38
+ const accountId = toAccountId(payload.address);
39
+ if (accountId !== toHex(userSession.remoteAccount.accountId)) {
30
40
  return errAsync(new Error(`Invalid address, got ${payload.address}`));
31
41
  }
32
42
  const messageId = nanoid();
33
43
  const request = session.request(RemoteMessageCodec, {
34
44
  messageId,
35
- data: enumValue('v1', enumValue('SignRequest', enumValue('payload', payload))),
45
+ data: enumValue('v1', enumValue('SignRequest', enumValue('Payload', {
46
+ ...payload,
47
+ address: toAddress(accountId),
48
+ }))),
36
49
  });
37
50
  const responseFilter = (message) => {
38
51
  if (message.data.tag === 'v1' &&
@@ -53,14 +66,17 @@ export function createUserSession({ userSession, statementStore, encryption, sto
53
66
  });
54
67
  },
55
68
  signRaw(payload) {
56
- const accountId = AccountId();
57
- if (toHex(accountId.enc(payload.address)) !== toHex(userSession.remoteAccount.accountId)) {
69
+ const accountId = toAccountId(payload.address);
70
+ if (accountId !== toHex(userSession.remoteAccount.accountId)) {
58
71
  return errAsync(new Error(`Invalid address, got ${payload.address}`));
59
72
  }
60
73
  const messageId = nanoid();
61
74
  const request = session.request(RemoteMessageCodec, {
62
75
  messageId,
63
- data: enumValue('v1', enumValue('SignRequest', enumValue('raw', payload))),
76
+ data: enumValue('v1', enumValue('SignRequest', enumValue('Raw', {
77
+ ...payload,
78
+ address: toAddress(accountId),
79
+ }))),
64
80
  });
65
81
  const responseFilter = (message) => {
66
82
  if (message.data.tag === 'v1' &&
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-papp",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.6.3",
5
5
  "description": "Polkadot app integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -28,10 +28,10 @@
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.6.1",
32
- "@novasamatech/scale": "0.6.1",
33
- "@novasamatech/statement-store": "0.6.1",
34
- "@novasamatech/storage-adapter": "0.6.1",
31
+ "@novasamatech/host-api": "0.6.3",
32
+ "@novasamatech/scale": "0.6.3",
33
+ "@novasamatech/statement-store": "0.6.3",
34
+ "@novasamatech/storage-adapter": "0.6.3",
35
35
  "@polkadot-api/utils": "0.2.0",
36
36
  "@polkadot-api/substrate-bindings": "^0.17.0",
37
37
  "@polkadot-labs/hdkd-helpers": "^0.0.27",