@novasamatech/host-papp 0.7.5 → 0.7.7
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/identity/impl.js +1 -1
- package/dist/sso/auth/attestationService.js +10 -8
- package/dist/sso/sessionManager/impl.js +13 -2
- package/dist/sso/sessionManager/scale/remoteMessage.d.ts +55 -2
- package/dist/sso/sessionManager/scale/remoteMessage.js +3 -0
- package/dist/sso/sessionManager/scale/resourceAllocation.d.ts +118 -0
- package/dist/sso/sessionManager/scale/resourceAllocation.js +40 -0
- package/dist/sso/sessionManager/scale/signingRequest.d.ts +4 -4
- package/dist/sso/sessionManager/scale/signingRequest.js +3 -2
- package/dist/sso/sessionManager/userSession.d.ts +2 -0
- package/dist/sso/sessionManager/userSession.js +29 -22
- package/package.json +5 -5
package/dist/identity/impl.js
CHANGED
|
@@ -159,18 +159,20 @@ function createPeopleSigner(verifier) {
|
|
|
159
159
|
publicKey: baseSigner.publicKey,
|
|
160
160
|
signBytes: baseSigner.signBytes,
|
|
161
161
|
signTx: async (callData, signedExtensions, metadata, atBlockNumber, hasher) => {
|
|
162
|
-
//
|
|
162
|
+
// polkadot-api auto-derives all signed extensions whose default state is encodable as
|
|
163
|
+
// a zero byte (Option::None, struct(Option<_>) = None, etc.). The People runtime's
|
|
164
|
+
// `pallet_verify_signature::VerifySignature` ({ Disabled, Signed }) extension uses
|
|
165
|
+
// identifier "VerifyMultiSignature" but has no built-in handler in polkadot-api, so it
|
|
166
|
+
// must be supplied manually. Value 0x00 = `Disabled` (passthrough — the standard
|
|
167
|
+
// extrinsic signature authenticates the call). Variant tag order was flipped in
|
|
168
|
+
// polkadot-sdk#11897 specifically so generic signers can encode the passthrough state
|
|
169
|
+
// as a single zero byte.
|
|
163
170
|
const extensionsWithCustom = {
|
|
164
171
|
...signedExtensions,
|
|
165
172
|
VerifyMultiSignature: {
|
|
166
173
|
identifier: 'VerifyMultiSignature',
|
|
167
|
-
value: new Uint8Array([
|
|
168
|
-
additionalSigned: new Uint8Array([]),
|
|
169
|
-
},
|
|
170
|
-
AsPerson: {
|
|
171
|
-
identifier: 'AsPerson',
|
|
172
|
-
value: new Uint8Array([0]), // 0u8 = Option::None
|
|
173
|
-
additionalSigned: new Uint8Array([]), // Empty additional data
|
|
174
|
+
value: new Uint8Array([0]),
|
|
175
|
+
additionalSigned: new Uint8Array([]),
|
|
174
176
|
},
|
|
175
177
|
};
|
|
176
178
|
return baseSigner.signTx(callData, extensionsWithCustom, metadata, atBlockNumber, hasher);
|
|
@@ -5,6 +5,11 @@ import { createSsoStatementProver } from '../ssoSessionProver.js';
|
|
|
5
5
|
import { createUserSession } from './userSession.js';
|
|
6
6
|
export function createSsoSessionManager({ ssoSessionRepository, userSecretRepository, statementStore, storage, }) {
|
|
7
7
|
const localSessions = createState({});
|
|
8
|
+
const sessionUnsubscribes = new Map();
|
|
9
|
+
const releaseSession = (id) => {
|
|
10
|
+
sessionUnsubscribes.get(id)?.();
|
|
11
|
+
sessionUnsubscribes.delete(id);
|
|
12
|
+
};
|
|
8
13
|
const disconnect = (session) => {
|
|
9
14
|
return ssoSessionRepository.filter(s => s.id !== session.id).map(() => undefined);
|
|
10
15
|
};
|
|
@@ -13,12 +18,12 @@ export function createSsoSessionManager({ ssoSessionRepository, userSecretReposi
|
|
|
13
18
|
const toRemove = new Set(Object.keys(activeSessions));
|
|
14
19
|
const toAdd = new Set();
|
|
15
20
|
for (const userSession of userSessions) {
|
|
21
|
+
toRemove.delete(userSession.id);
|
|
16
22
|
if (userSession.id in activeSessions)
|
|
17
23
|
continue;
|
|
18
24
|
const session = createSession(userSession, statementStore, storage, userSecretRepository);
|
|
19
|
-
toRemove.delete(userSession.id);
|
|
20
25
|
toAdd.add(session);
|
|
21
|
-
session.subscribe(message => {
|
|
26
|
+
const unsubscribe = session.subscribe(message => {
|
|
22
27
|
switch (message.data.tag) {
|
|
23
28
|
case 'v1': {
|
|
24
29
|
switch (message.data.value.tag) {
|
|
@@ -29,8 +34,13 @@ export function createSsoSessionManager({ ssoSessionRepository, userSecretReposi
|
|
|
29
34
|
}
|
|
30
35
|
return okAsync(false);
|
|
31
36
|
});
|
|
37
|
+
sessionUnsubscribes.set(session.id, unsubscribe);
|
|
32
38
|
}
|
|
33
39
|
if (toRemove.size > 0) {
|
|
40
|
+
for (const id of toRemove) {
|
|
41
|
+
releaseSession(id);
|
|
42
|
+
activeSessions[id]?.dispose();
|
|
43
|
+
}
|
|
34
44
|
localSessions.write(prev => {
|
|
35
45
|
return Object.fromEntries(Object.entries(prev).filter(([id]) => !toRemove.has(id)));
|
|
36
46
|
});
|
|
@@ -56,6 +66,7 @@ export function createSsoSessionManager({ ssoSessionRepository, userSecretReposi
|
|
|
56
66
|
},
|
|
57
67
|
dispose() {
|
|
58
68
|
for (const session of Object.values(localSessions.read())) {
|
|
69
|
+
releaseSession(session.id);
|
|
59
70
|
session.dispose();
|
|
60
71
|
}
|
|
61
72
|
},
|
|
@@ -12,7 +12,7 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
|
|
|
12
12
|
value: {
|
|
13
13
|
tag: "Payload";
|
|
14
14
|
value: {
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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,9 +119,31 @@ 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
|
-
processedMessages
|
|
144
|
+
processedMessages
|
|
145
|
+
.read()
|
|
146
|
+
.andThen(processed => {
|
|
143
147
|
const results = messages.map(message => {
|
|
144
148
|
if (message.type === 'request' && message.payload.status === 'parsed') {
|
|
145
149
|
const payload = message.payload;
|
|
@@ -163,6 +167,9 @@ export function createUserSession({ userSession, statementStore, encryption, sto
|
|
|
163
167
|
}
|
|
164
168
|
return okAsync();
|
|
165
169
|
});
|
|
170
|
+
})
|
|
171
|
+
.orTee(error => {
|
|
172
|
+
console.error('Error while updating processed sso messages:', error);
|
|
166
173
|
});
|
|
167
174
|
});
|
|
168
175
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-papp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.7",
|
|
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.
|
|
33
|
-
"@novasamatech/scale": "0.7.
|
|
34
|
-
"@novasamatech/statement-store": "0.7.
|
|
35
|
-
"@novasamatech/storage-adapter": "0.7.
|
|
32
|
+
"@novasamatech/host-api": "0.7.7",
|
|
33
|
+
"@novasamatech/scale": "0.7.7",
|
|
34
|
+
"@novasamatech/statement-store": "0.7.7",
|
|
35
|
+
"@novasamatech/storage-adapter": "0.7.7",
|
|
36
36
|
"@polkadot-labs/hdkd-helpers": "^0.0.30",
|
|
37
37
|
"nanoevents": "9.1.0",
|
|
38
38
|
"nanoid": "5.1.9",
|