@novasamatech/host-papp 0.5.5 → 0.6.1

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/crypto.d.ts CHANGED
@@ -18,7 +18,7 @@ export type DerivedSr25519Account = {
18
18
  sign(message: Uint8Array): Uint8Array;
19
19
  verify(message: Uint8Array, signature: Uint8Array): boolean;
20
20
  };
21
- export declare function deriveSr25519Account(mnemonic: string, derivation: string): DerivedSr25519Account;
21
+ export declare function deriveSr25519Account(mnemonic: string, derivation?: string): DerivedSr25519Account;
22
22
  export declare function createEncrSecret(entropy: Uint8Array): EncrSecret;
23
23
  export declare function getEncrPub(secret: EncrSecret): EncrPublicKey;
24
24
  export declare function createSharedSecret(secret: EncrSecret, publicKey: Uint8Array): SharedSecret;
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/signPayloadRequest.js';
9
- export type { SignPayloadResponse } from './sso/sessionManager/scale/signPayloadResponse.js';
8
+ export type { SignPayloadRequest } from './sso/sessionManager/scale/signingRequest.js';
9
+ export type { SignPayloadResponse } from './sso/sessionManager/scale/signingResponse.js';
@@ -10,22 +10,37 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
10
10
  } | {
11
11
  tag: "SignRequest";
12
12
  value: {
13
- address: string;
14
- blockHash: `0x${string}`;
15
- blockNumber: `0x${string}`;
16
- era: `0x${string}`;
17
- genesisHash: `0x${string}`;
18
- method: `0x${string}`;
19
- nonce: `0x${string}`;
20
- specVersion: `0x${string}`;
21
- tip: `0x${string}`;
22
- transactionVersion: `0x${string}`;
23
- signedExtensions: string[];
24
- version: number;
25
- assetId: `0x${string}` | undefined;
26
- metadataHash: `0x${string}` | undefined;
27
- mode: number | undefined;
28
- withSignedTransaction: boolean | undefined;
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";
26
+ value: {
27
+ address: string;
28
+ blockHash: `0x${string}`;
29
+ blockNumber: `0x${string}`;
30
+ era: `0x${string}`;
31
+ genesisHash: `0x${string}`;
32
+ method: `0x${string}`;
33
+ nonce: `0x${string}`;
34
+ specVersion: `0x${string}`;
35
+ tip: `0x${string}`;
36
+ transactionVersion: `0x${string}`;
37
+ signedExtensions: string[];
38
+ version: number;
39
+ assetId: `0x${string}` | undefined;
40
+ metadataHash: `0x${string}` | undefined;
41
+ mode: number | undefined;
42
+ withSignedTransaction: boolean | undefined;
43
+ };
29
44
  };
30
45
  } | {
31
46
  tag: "SignResponse";
@@ -1,13 +1,13 @@
1
1
  import { Enum, Struct, _void, str } from 'scale-ts';
2
- import { SignPayloadRequestCodec } from './signPayloadRequest.js';
3
- import { SignPayloadResponseCodec } from './signPayloadResponse.js';
2
+ import { SigningRequestCodec } from './signingRequest.js';
3
+ import { SigningResponseCodec } from './signingResponse.js';
4
4
  export const RemoteMessageCodec = Struct({
5
5
  messageId: str,
6
6
  data: Enum({
7
7
  v1: Enum({
8
8
  Disconnected: _void,
9
- SignRequest: SignPayloadRequestCodec,
10
- SignResponse: SignPayloadResponseCodec,
9
+ SignRequest: SigningRequestCodec,
10
+ SignResponse: SigningResponseCodec,
11
11
  }),
12
12
  }),
13
13
  });
@@ -0,0 +1,64 @@
1
+ import type { CodecType } from 'scale-ts';
2
+ export type SignPayloadRequest = CodecType<typeof SigningPayloadRequestCodec>;
3
+ export declare const SigningPayloadRequestCodec: import("scale-ts").Codec<{
4
+ address: string;
5
+ blockHash: `0x${string}`;
6
+ blockNumber: `0x${string}`;
7
+ era: `0x${string}`;
8
+ genesisHash: `0x${string}`;
9
+ method: `0x${string}`;
10
+ nonce: `0x${string}`;
11
+ specVersion: `0x${string}`;
12
+ tip: `0x${string}`;
13
+ transactionVersion: `0x${string}`;
14
+ signedExtensions: string[];
15
+ version: number;
16
+ assetId: `0x${string}` | undefined;
17
+ metadataHash: `0x${string}` | undefined;
18
+ mode: number | undefined;
19
+ withSignedTransaction: boolean | undefined;
20
+ }>;
21
+ export type SigningRawRequest = CodecType<typeof SigningRawRequestCodec>;
22
+ export declare const SigningRawRequestCodec: import("scale-ts").Codec<{
23
+ address: string;
24
+ data: {
25
+ tag: "Bytes";
26
+ value: Uint8Array<ArrayBufferLike>;
27
+ } | {
28
+ tag: "Payload";
29
+ value: string;
30
+ };
31
+ }>;
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";
46
+ value: {
47
+ address: string;
48
+ blockHash: `0x${string}`;
49
+ blockNumber: `0x${string}`;
50
+ era: `0x${string}`;
51
+ genesisHash: `0x${string}`;
52
+ method: `0x${string}`;
53
+ nonce: `0x${string}`;
54
+ specVersion: `0x${string}`;
55
+ tip: `0x${string}`;
56
+ transactionVersion: `0x${string}`;
57
+ signedExtensions: string[];
58
+ version: number;
59
+ assetId: `0x${string}` | undefined;
60
+ metadataHash: `0x${string}` | undefined;
61
+ mode: number | undefined;
62
+ withSignedTransaction: boolean | undefined;
63
+ };
64
+ }>;
@@ -0,0 +1,31 @@
1
+ import { Enum, Hex } from '@novasamatech/scale';
2
+ import { Bytes, Option, Struct, Vector, bool, str, u32 } from 'scale-ts';
3
+ export const SigningPayloadRequestCodec = Struct({
4
+ address: str,
5
+ blockHash: Hex(),
6
+ blockNumber: Hex(),
7
+ era: Hex(),
8
+ genesisHash: Hex(),
9
+ method: Hex(),
10
+ nonce: Hex(),
11
+ specVersion: Hex(),
12
+ tip: Hex(),
13
+ transactionVersion: Hex(),
14
+ signedExtensions: Vector(str),
15
+ version: u32,
16
+ assetId: Option(Hex()),
17
+ metadataHash: Option(Hex()),
18
+ mode: Option(u32),
19
+ withSignedTransaction: Option(bool),
20
+ });
21
+ export const SigningRawRequestCodec = Struct({
22
+ address: str,
23
+ data: Enum({
24
+ Bytes: Bytes(),
25
+ Payload: str,
26
+ }),
27
+ });
28
+ export const SigningRequestCodec = Enum({
29
+ payload: SigningPayloadRequestCodec,
30
+ raw: SigningRawRequestCodec,
31
+ });
@@ -0,0 +1,14 @@
1
+ import type { CodecType } from 'scale-ts';
2
+ export type SignPayloadResponseData = CodecType<typeof SignPayloadResponseDataCodec>;
3
+ export declare const SignPayloadResponseDataCodec: import("scale-ts").Codec<{
4
+ signature: Uint8Array<ArrayBufferLike>;
5
+ signedTransaction: Uint8Array<ArrayBufferLike> | undefined;
6
+ }>;
7
+ export type SignPayloadResponse = CodecType<typeof SigningResponseCodec>;
8
+ export declare const SigningResponseCodec: import("scale-ts").Codec<{
9
+ respondingTo: string;
10
+ payload: import("scale-ts").ResultPayload<{
11
+ signature: Uint8Array<ArrayBufferLike>;
12
+ signedTransaction: Uint8Array<ArrayBufferLike> | undefined;
13
+ }, string>;
14
+ }>;
@@ -0,0 +1,10 @@
1
+ import { Bytes, Option, Result, Struct, str } from 'scale-ts';
2
+ export const SignPayloadResponseDataCodec = Struct({
3
+ signature: Bytes(),
4
+ signedTransaction: Option(Bytes()),
5
+ });
6
+ export const SigningResponseCodec = Struct({
7
+ // referencing to RemoteMessage.messageId
8
+ respondingTo: str,
9
+ payload: Result(SignPayloadResponseDataCodec, str),
10
+ });
@@ -5,11 +5,12 @@ import type { CodecType } from 'scale-ts';
5
5
  import type { Callback } from '../../types.js';
6
6
  import type { StoredUserSession } from '../userSessionRepository.js';
7
7
  import { RemoteMessageCodec } from './scale/remoteMessage.js';
8
- import type { SignPayloadRequest } from './scale/signPayloadRequest.js';
9
- import type { SignPayloadResponseData } from './scale/signPayloadResponse.js';
8
+ import type { SignPayloadRequest, SigningRawRequest } from './scale/signingRequest.js';
9
+ import type { SignPayloadResponseData } from './scale/signingResponse.js';
10
10
  export type UserSession = StoredUserSession & {
11
11
  sendDisconnectMessage(): ResultAsync<void, Error>;
12
12
  signPayload(payload: SignPayloadRequest): ResultAsync<SignPayloadResponseData, Error>;
13
+ signRaw(payload: SigningRawRequest): ResultAsync<SignPayloadResponseData, Error>;
13
14
  subscribe(callback: Callback<CodecType<typeof RemoteMessageCodec>, ResultAsync<boolean, Error>>): VoidFunction;
14
15
  dispose(): void;
15
16
  };
@@ -32,7 +32,35 @@ export function createUserSession({ userSession, statementStore, encryption, sto
32
32
  const messageId = nanoid();
33
33
  const request = session.request(RemoteMessageCodec, {
34
34
  messageId,
35
- data: enumValue('v1', enumValue('SignRequest', payload)),
35
+ data: enumValue('v1', enumValue('SignRequest', enumValue('payload', payload))),
36
+ });
37
+ const responseFilter = (message) => {
38
+ if (message.data.tag === 'v1' &&
39
+ message.data.value.tag === 'SignResponse' &&
40
+ message.data.value.value.respondingTo === messageId) {
41
+ return message.data.value.value.payload;
42
+ }
43
+ };
44
+ return request
45
+ .andThen(() => session.waitForRequestMessage(RemoteMessageCodec, responseFilter))
46
+ .andThen(message => {
47
+ if (message.success) {
48
+ return ok(message.value);
49
+ }
50
+ else {
51
+ return err(new Error(message.value));
52
+ }
53
+ });
54
+ },
55
+ signRaw(payload) {
56
+ const accountId = AccountId();
57
+ if (toHex(accountId.enc(payload.address)) !== toHex(userSession.remoteAccount.accountId)) {
58
+ return errAsync(new Error(`Invalid address, got ${payload.address}`));
59
+ }
60
+ const messageId = nanoid();
61
+ const request = session.request(RemoteMessageCodec, {
62
+ messageId,
63
+ data: enumValue('v1', enumValue('SignRequest', enumValue('raw', payload))),
36
64
  });
37
65
  const responseFilter = (message) => {
38
66
  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.5.5",
4
+ "version": "0.6.1",
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.5.5",
32
- "@novasamatech/scale": "0.5.5",
33
- "@novasamatech/statement-store": "0.5.5",
34
- "@novasamatech/storage-adapter": "0.5.5",
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",
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",