@novasamatech/host-papp 0.6.0 → 0.6.2-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.
- package/dist/index.d.ts +1 -1
- package/dist/sso/auth/attestationService.js +1 -1
- package/dist/sso/sessionManager/scale/remoteMessage.d.ts +13 -13
- package/dist/sso/sessionManager/scale/signingRequest.d.ts +13 -13
- package/dist/sso/sessionManager/scale/signingRequest.js +2 -2
- package/dist/sso/sessionManager/userSession.js +24 -8
- package/package.json +5 -5
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';
|
|
@@ -6,7 +6,7 @@ import { errAsync, fromAsyncThrowable, fromPromise, okAsync } from 'neverthrow';
|
|
|
6
6
|
import { AccountId, Binary } from 'polkadot-api';
|
|
7
7
|
import { getPolkadotSigner } from 'polkadot-api/signer';
|
|
8
8
|
import { Bytes, Option, Tuple, str } from 'scale-ts';
|
|
9
|
-
import { member_from_entropy, sign } from 'verifiablejs/
|
|
9
|
+
import { member_from_entropy, sign } from 'verifiablejs/bundler';
|
|
10
10
|
import { deriveSr25519Account, getEncrPub, stringToBytes } from '../../crypto.js';
|
|
11
11
|
import { toError } from '../../helpers/utils.js';
|
|
12
12
|
const accountId = AccountId();
|
|
@@ -10,19 +10,7 @@ export declare const RemoteMessageCodec: import("scale-ts").Codec<{
|
|
|
10
10
|
} | {
|
|
11
11
|
tag: "SignRequest";
|
|
12
12
|
value: {
|
|
13
|
-
tag: "
|
|
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: "
|
|
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
|
}>;
|
|
@@ -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 =
|
|
29
|
-
if (
|
|
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('
|
|
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 =
|
|
57
|
-
if (
|
|
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('
|
|
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.0",
|
|
4
|
+
"version": "0.6.2-0",
|
|
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.0",
|
|
32
|
-
"@novasamatech/scale": "0.6.0",
|
|
33
|
-
"@novasamatech/statement-store": "0.6.0",
|
|
34
|
-
"@novasamatech/storage-adapter": "0.6.0",
|
|
31
|
+
"@novasamatech/host-api": "0.6.2-0",
|
|
32
|
+
"@novasamatech/scale": "0.6.2-0",
|
|
33
|
+
"@novasamatech/statement-store": "0.6.2-0",
|
|
34
|
+
"@novasamatech/storage-adapter": "0.6.2-0",
|
|
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",
|