@novasamatech/host-papp 0.7.5 → 0.7.6

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.
@@ -12,7 +12,7 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
12
12
  value: {
13
13
  tag: "Payload";
14
14
  value: {
15
- address: string;
15
+ productAccountId: [string, number];
16
16
  blockHash: `0x${string}`;
17
17
  blockNumber: `0x${string}`;
18
18
  era: `0x${string}`;
@@ -32,7 +32,7 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
32
32
  } | {
33
33
  tag: "Raw";
34
34
  value: {
35
- address: string;
35
+ productAccountId: [string, number];
36
36
  data: {
37
37
  tag: "Bytes";
38
38
  value: Uint8Array<ArrayBufferLike>;
@@ -66,6 +66,59 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
66
66
  alias: Uint8Array<ArrayBufferLike>;
67
67
  }, string>;
68
68
  };
69
+ } | {
70
+ tag: "ResourceAllocationRequest";
71
+ value: {
72
+ callingProductId: string;
73
+ resources: ({
74
+ tag: "StatementStoreAllowance";
75
+ value: undefined;
76
+ } | {
77
+ tag: "BulletInAllowance";
78
+ value: undefined;
79
+ } | {
80
+ tag: "SmartContractAllowance";
81
+ value: number;
82
+ } | {
83
+ tag: "AutoSigning";
84
+ value: undefined;
85
+ })[];
86
+ onExisting: "Ignore" | "Increase";
87
+ };
88
+ } | {
89
+ tag: "ResourceAllocationResponse";
90
+ value: {
91
+ respondingTo: string;
92
+ payload: import("scale-ts").ResultPayload<({
93
+ tag: "Rejected";
94
+ value: undefined;
95
+ } | {
96
+ tag: "Allocated";
97
+ value: {
98
+ tag: "StatementStoreAllowance";
99
+ value: {
100
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
101
+ };
102
+ } | {
103
+ tag: "BulletInAllowance";
104
+ value: {
105
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
106
+ };
107
+ } | {
108
+ tag: "SmartContractAllowance";
109
+ value: undefined;
110
+ } | {
111
+ tag: "AutoSigning";
112
+ value: {
113
+ productDerivationSecret: string;
114
+ productRootPrivateKey: Uint8Array<ArrayBufferLike>;
115
+ };
116
+ };
117
+ } | {
118
+ tag: "NotAvailable";
119
+ value: undefined;
120
+ })[], string>;
121
+ };
69
122
  };
70
123
  };
71
124
  }>;
@@ -1,4 +1,5 @@
1
1
  import { Enum, Struct, _void, str } from 'scale-ts';
2
+ import { ResourceAllocationRequestCodec, ResourceAllocationResponseCodec } from './resourceAllocation.js';
2
3
  import { RingVrfAliasRequestCodec, RingVrfAliasResponseCodec } from './ringVrf.js';
3
4
  import { SigningRequestCodec } from './signingRequest.js';
4
5
  import { SigningResponseCodec } from './signingResponse.js';
@@ -11,6 +12,8 @@ export const RemoteMessageCodec = Struct({
11
12
  SignResponse: SigningResponseCodec,
12
13
  RingVrfAliasRequest: RingVrfAliasRequestCodec,
13
14
  RingVrfAliasResponse: RingVrfAliasResponseCodec,
15
+ ResourceAllocationRequest: ResourceAllocationRequestCodec,
16
+ ResourceAllocationResponse: ResourceAllocationResponseCodec,
14
17
  }),
15
18
  }),
16
19
  });
@@ -0,0 +1,118 @@
1
+ import type { CodecType } from 'scale-ts';
2
+ export type ApAllocatableResource = CodecType<typeof ApAllocatableResourceCodec>;
3
+ export declare const ApAllocatableResourceCodec: import("scale-ts").Codec<{
4
+ tag: "StatementStoreAllowance";
5
+ value: undefined;
6
+ } | {
7
+ tag: "BulletInAllowance";
8
+ value: undefined;
9
+ } | {
10
+ tag: "SmartContractAllowance";
11
+ value: number;
12
+ } | {
13
+ tag: "AutoSigning";
14
+ value: undefined;
15
+ }>;
16
+ export type ApAllocatedResource = CodecType<typeof ApAllocatedResourceCodec>;
17
+ export declare const ApAllocatedResourceCodec: import("scale-ts").Codec<{
18
+ tag: "StatementStoreAllowance";
19
+ value: {
20
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
21
+ };
22
+ } | {
23
+ tag: "BulletInAllowance";
24
+ value: {
25
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
26
+ };
27
+ } | {
28
+ tag: "SmartContractAllowance";
29
+ value: undefined;
30
+ } | {
31
+ tag: "AutoSigning";
32
+ value: {
33
+ productDerivationSecret: string;
34
+ productRootPrivateKey: Uint8Array<ArrayBufferLike>;
35
+ };
36
+ }>;
37
+ export type ApAllocationOutcome = CodecType<typeof ApAllocationOutcomeCodec>;
38
+ export declare const ApAllocationOutcomeCodec: import("scale-ts").Codec<{
39
+ tag: "Rejected";
40
+ value: undefined;
41
+ } | {
42
+ tag: "Allocated";
43
+ value: {
44
+ tag: "StatementStoreAllowance";
45
+ value: {
46
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
47
+ };
48
+ } | {
49
+ tag: "BulletInAllowance";
50
+ value: {
51
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
52
+ };
53
+ } | {
54
+ tag: "SmartContractAllowance";
55
+ value: undefined;
56
+ } | {
57
+ tag: "AutoSigning";
58
+ value: {
59
+ productDerivationSecret: string;
60
+ productRootPrivateKey: Uint8Array<ArrayBufferLike>;
61
+ };
62
+ };
63
+ } | {
64
+ tag: "NotAvailable";
65
+ value: undefined;
66
+ }>;
67
+ export declare const OnExistingAllowancePolicyCodec: import("scale-ts").Codec<"Ignore" | "Increase">;
68
+ export type ResourceAllocationRequest = CodecType<typeof ResourceAllocationRequestCodec>;
69
+ export declare const ResourceAllocationRequestCodec: import("scale-ts").Codec<{
70
+ callingProductId: string;
71
+ resources: ({
72
+ tag: "StatementStoreAllowance";
73
+ value: undefined;
74
+ } | {
75
+ tag: "BulletInAllowance";
76
+ value: undefined;
77
+ } | {
78
+ tag: "SmartContractAllowance";
79
+ value: number;
80
+ } | {
81
+ tag: "AutoSigning";
82
+ value: undefined;
83
+ })[];
84
+ onExisting: "Ignore" | "Increase";
85
+ }>;
86
+ export type ResourceAllocationResponse = CodecType<typeof ResourceAllocationResponseCodec>;
87
+ export declare const ResourceAllocationResponseCodec: import("scale-ts").Codec<{
88
+ respondingTo: string;
89
+ payload: import("scale-ts").ResultPayload<({
90
+ tag: "Rejected";
91
+ value: undefined;
92
+ } | {
93
+ tag: "Allocated";
94
+ value: {
95
+ tag: "StatementStoreAllowance";
96
+ value: {
97
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
98
+ };
99
+ } | {
100
+ tag: "BulletInAllowance";
101
+ value: {
102
+ slotAccountKey: Uint8Array<ArrayBufferLike>;
103
+ };
104
+ } | {
105
+ tag: "SmartContractAllowance";
106
+ value: undefined;
107
+ } | {
108
+ tag: "AutoSigning";
109
+ value: {
110
+ productDerivationSecret: string;
111
+ productRootPrivateKey: Uint8Array<ArrayBufferLike>;
112
+ };
113
+ };
114
+ } | {
115
+ tag: "NotAvailable";
116
+ value: undefined;
117
+ })[], string>;
118
+ }>;
@@ -0,0 +1,40 @@
1
+ import { DerivationIndex, DotNsIdentifier } from '@novasamatech/host-api';
2
+ import { Status } from '@novasamatech/scale';
3
+ import { Bytes, Enum, Result, Struct, Vector, _void, str } from 'scale-ts';
4
+ export const ApAllocatableResourceCodec = Enum({
5
+ StatementStoreAllowance: _void,
6
+ BulletInAllowance: _void,
7
+ SmartContractAllowance: DerivationIndex,
8
+ AutoSigning: _void,
9
+ });
10
+ export const ApAllocatedResourceCodec = Enum({
11
+ StatementStoreAllowance: Struct({
12
+ slotAccountKey: Bytes(),
13
+ }),
14
+ BulletInAllowance: Struct({
15
+ slotAccountKey: Bytes(),
16
+ }),
17
+ SmartContractAllowance: _void,
18
+ AutoSigning: Struct({
19
+ productDerivationSecret: str,
20
+ productRootPrivateKey: Bytes(),
21
+ }),
22
+ });
23
+ export const ApAllocationOutcomeCodec = Enum({
24
+ Allocated: ApAllocatedResourceCodec,
25
+ Rejected: _void,
26
+ NotAvailable: _void,
27
+ });
28
+ // Behavior when the requested resource already has an active allocation
29
+ // for this (user, product) pair on the Account Holder side.
30
+ export const OnExistingAllowancePolicyCodec = Status('Ignore', 'Increase');
31
+ export const ResourceAllocationRequestCodec = Struct({
32
+ callingProductId: DotNsIdentifier,
33
+ resources: Vector(ApAllocatableResourceCodec),
34
+ onExisting: OnExistingAllowancePolicyCodec,
35
+ });
36
+ export const ResourceAllocationResponseCodec = Struct({
37
+ // referencing to RemoteMessage.messageId
38
+ respondingTo: str,
39
+ payload: Result(Vector(ApAllocationOutcomeCodec), str),
40
+ });
@@ -1,7 +1,7 @@
1
1
  import type { CodecType } from 'scale-ts';
2
2
  export type SigningPayloadRequest = CodecType<typeof SigningPayloadRequestCodec>;
3
3
  export declare const SigningPayloadRequestCodec: import("scale-ts").Codec<{
4
- address: string;
4
+ productAccountId: [string, number];
5
5
  blockHash: `0x${string}`;
6
6
  blockNumber: `0x${string}`;
7
7
  era: `0x${string}`;
@@ -20,7 +20,7 @@ export declare const SigningPayloadRequestCodec: import("scale-ts").Codec<{
20
20
  }>;
21
21
  export type SigningRawRequest = CodecType<typeof SigningRawRequestCodec>;
22
22
  export declare const SigningRawRequestCodec: import("scale-ts").Codec<{
23
- address: string;
23
+ productAccountId: [string, number];
24
24
  data: {
25
25
  tag: "Bytes";
26
26
  value: Uint8Array<ArrayBufferLike>;
@@ -33,7 +33,7 @@ export type SigningRequest = CodecType<typeof SigningRequestCodec>;
33
33
  export declare const SigningRequestCodec: import("scale-ts").Codec<{
34
34
  tag: "Payload";
35
35
  value: {
36
- address: string;
36
+ productAccountId: [string, number];
37
37
  blockHash: `0x${string}`;
38
38
  blockNumber: `0x${string}`;
39
39
  era: `0x${string}`;
@@ -53,7 +53,7 @@ export declare const SigningRequestCodec: import("scale-ts").Codec<{
53
53
  } | {
54
54
  tag: "Raw";
55
55
  value: {
56
- address: string;
56
+ productAccountId: [string, number];
57
57
  data: {
58
58
  tag: "Bytes";
59
59
  value: Uint8Array<ArrayBufferLike>;
@@ -1,7 +1,8 @@
1
+ import { ProductAccountId } from '@novasamatech/host-api';
1
2
  import { Enum, Hex, OptionBool } from '@novasamatech/scale';
2
3
  import { Bytes, Option, Struct, Vector, str, u32 } from 'scale-ts';
3
4
  export const SigningPayloadRequestCodec = Struct({
4
- address: str,
5
+ productAccountId: ProductAccountId,
5
6
  blockHash: Hex(),
6
7
  blockNumber: Hex(),
7
8
  era: Hex(),
@@ -19,7 +20,7 @@ export const SigningPayloadRequestCodec = Struct({
19
20
  withSignedTransaction: OptionBool,
20
21
  });
21
22
  export const SigningRawRequestCodec = Struct({
22
- address: str,
23
+ productAccountId: ProductAccountId,
23
24
  data: Enum({
24
25
  Bytes: Bytes(),
25
26
  Payload: str,
@@ -6,6 +6,7 @@ import type { CodecType } from 'scale-ts';
6
6
  import type { Callback } from '../../types.js';
7
7
  import type { StoredUserSession } from '../userSessionRepository.js';
8
8
  import { RemoteMessageCodec } from './scale/remoteMessage.js';
9
+ import type { ApAllocationOutcome, ResourceAllocationRequest } from './scale/resourceAllocation.js';
9
10
  import type { SigningPayloadRequest, SigningRawRequest } from './scale/signingRequest.js';
10
11
  import type { SigningPayloadResponseData } from './scale/signingResponse.js';
11
12
  export type UserSession = StoredUserSession & {
@@ -13,6 +14,7 @@ export type UserSession = StoredUserSession & {
13
14
  signPayload(payload: SigningPayloadRequest): ResultAsync<SigningPayloadResponseData, Error>;
14
15
  signRaw(payload: SigningRawRequest): ResultAsync<SigningPayloadResponseData, Error>;
15
16
  getRingVrfAlias(productAccountId: CodecType<typeof ProductAccountId>, productId: string): ResultAsync<CodecType<typeof ContextualAlias>, Error>;
17
+ requestResourceAllocation(request: ResourceAllocationRequest): ResultAsync<ApAllocationOutcome[], Error>;
16
18
  subscribe(callback: Callback<CodecType<typeof RemoteMessageCodec>, ResultAsync<boolean, Error>>): VoidFunction;
17
19
  dispose(): void;
18
20
  };
@@ -1,10 +1,9 @@
1
1
  import { ContextualAlias, ProductAccountId } from '@novasamatech/host-api';
2
- import { enumValue, toHex } from '@novasamatech/scale';
2
+ import { enumValue } from '@novasamatech/scale';
3
3
  import { createSession } from '@novasamatech/statement-store';
4
4
  import { fieldListView } from '@novasamatech/storage-adapter';
5
5
  import { nanoid } from 'nanoid';
6
6
  import { ResultAsync, err, ok, okAsync } from 'neverthrow';
7
- import { AccountId } from 'polkadot-api';
8
7
  import { createAsyncTaskPool } from '../../helpers/createAsyncTaskPool.js';
9
8
  import { toError } from '../../helpers/utils.js';
10
9
  import { RemoteMessageCodec } from './scale/remoteMessage.js';
@@ -18,7 +17,6 @@ function withQueueTimeout(resultAsync, label) {
18
17
  return ResultAsync.fromPromise(Promise.race([resultAsync, timeoutPromise]), toError).andThen(r => r);
19
18
  }
20
19
  export function createUserSession({ userSession, statementStore, encryption, storage, prover, }) {
21
- const accountId = AccountId();
22
20
  const requestQueue = createAsyncTaskPool({ poolSize: 1, retryCount: 0, retryDelay: 0 });
23
21
  const session = createSession({
24
22
  localAccount: userSession.localAccount,
@@ -33,16 +31,6 @@ export function createUserSession({ userSession, statementStore, encryption, sto
33
31
  from: JSON.parse,
34
32
  to: JSON.stringify,
35
33
  });
36
- function toAccountId(address) {
37
- // already an account id
38
- if (address.startsWith('0x') && address.length === 64 + 2) {
39
- return address;
40
- }
41
- return toHex(accountId.enc(address));
42
- }
43
- function toAddress(account) {
44
- return accountId.dec(account);
45
- }
46
34
  return {
47
35
  id: userSession.id,
48
36
  localAccount: userSession.localAccount,
@@ -52,10 +40,7 @@ export function createUserSession({ userSession, statementStore, encryption, sto
52
40
  const messageId = nanoid();
53
41
  const request = session.request(RemoteMessageCodec, {
54
42
  messageId,
55
- data: enumValue('v1', enumValue('SignRequest', enumValue('Payload', {
56
- ...payload,
57
- address: toAddress(toAccountId(payload.address)),
58
- }))),
43
+ data: enumValue('v1', enumValue('SignRequest', enumValue('Payload', payload))),
59
44
  });
60
45
  const responseFilter = (message) => {
61
46
  if (message.data.tag === 'v1' &&
@@ -82,10 +67,7 @@ export function createUserSession({ userSession, statementStore, encryption, sto
82
67
  const messageId = nanoid();
83
68
  const request = session.request(RemoteMessageCodec, {
84
69
  messageId,
85
- data: enumValue('v1', enumValue('SignRequest', enumValue('Raw', {
86
- ...payload,
87
- address: toAddress(toAccountId(payload.address)),
88
- }))),
70
+ data: enumValue('v1', enumValue('SignRequest', enumValue('Raw', payload))),
89
71
  });
90
72
  const responseFilter = (message) => {
91
73
  if (message.data.tag === 'v1' &&
@@ -137,6 +119,26 @@ export function createUserSession({ userSession, statementStore, encryption, sto
137
119
  .andThen(result => (result.success ? ok(result.value) : err(new Error(result.value))));
138
120
  });
139
121
  },
122
+ requestResourceAllocation(request) {
123
+ return requestQueue.call(() => {
124
+ const messageId = nanoid();
125
+ const sendRequest = session.request(RemoteMessageCodec, {
126
+ messageId,
127
+ data: enumValue('v1', enumValue('ResourceAllocationRequest', request)),
128
+ });
129
+ const responseFilter = (message) => {
130
+ if (message.data.tag === 'v1' &&
131
+ message.data.value.tag === 'ResourceAllocationResponse' &&
132
+ message.data.value.value.respondingTo === messageId) {
133
+ return message.data.value.value.payload;
134
+ }
135
+ };
136
+ const inner = sendRequest
137
+ .andThen(() => session.waitForRequestMessage(RemoteMessageCodec, responseFilter))
138
+ .andThen(result => (result.success ? ok(result.value) : err(new Error(result.value))));
139
+ return withQueueTimeout(inner, 'requestResourceAllocation');
140
+ });
141
+ },
140
142
  subscribe(callback) {
141
143
  return session.subscribe(RemoteMessageCodec, messages => {
142
144
  processedMessages.read().andThen(processed => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-papp",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.6",
5
5
  "description": "Polkadot app integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -29,10 +29,10 @@
29
29
  "@noble/ciphers": "2.2.0",
30
30
  "@noble/curves": "2.2.0",
31
31
  "@noble/hashes": "2.2.0",
32
- "@novasamatech/host-api": "0.7.5",
33
- "@novasamatech/scale": "0.7.5",
34
- "@novasamatech/statement-store": "0.7.5",
35
- "@novasamatech/storage-adapter": "0.7.5",
32
+ "@novasamatech/host-api": "0.7.6",
33
+ "@novasamatech/scale": "0.7.6",
34
+ "@novasamatech/statement-store": "0.7.6",
35
+ "@novasamatech/storage-adapter": "0.7.6",
36
36
  "@polkadot-labs/hdkd-helpers": "^0.0.30",
37
37
  "nanoevents": "9.1.0",
38
38
  "nanoid": "5.1.9",