@novasamatech/statement-store 0.9.2 → 0.9.4

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.
@@ -5,11 +5,14 @@ import { Struct, str } from 'scale-ts';
5
5
  import { describe, expect, it, vi } from 'vitest';
6
6
  import { createInMemoryStatementStore } from '../adapter/inMemory.js';
7
7
  import { AccountFullError, ExpiryTooLowError } from '../adapter/types.js';
8
+ import { createSr25519Secret } from '../crypto.js';
8
9
  import { createAccountId, createLocalSessionAccount, createRemoteSessionAccount } from '../model/sessionAccount.js';
9
10
  import { STATEMENT_OVERHEAD } from './core.js';
11
+ import { createEncryption } from './encyption.js';
10
12
  import { DecodingError, UnknownError } from './error.js';
11
13
  import { StatementData } from './scale/statementData.js';
12
14
  import { createSession } from './session.js';
15
+ import { createSr25519Prover } from './statementProver.js';
13
16
  // Real signature work belongs in statementProver tests; this stub stamps a
14
17
  // non-empty proof so submitted statements are well-formed.
15
18
  const mockProver = {
@@ -133,13 +136,17 @@ const localB = createLocalSessionAccount(createAccountId(new Uint8Array(32).fill
133
136
  const remoteB = createRemoteSessionAccount(createAccountId(new Uint8Array(32).fill(2)), new Uint8Array(32).fill(22));
134
137
  const RemoteMsg = Struct({ id: str, kind: str, respondingTo: str, body: str });
135
138
  const requestMsg = (id) => ({ id, kind: 'request', respondingTo: '', body: id });
139
+ // Real crypto on both halves: the pairwise secret is shared, so what one side
140
+ // encrypts and signs the other actually decrypts and verifies.
141
+ const PAIRWISE_SECRET = new Uint8Array(32).fill(0x5a);
142
+ const realProver = () => createSr25519Prover(createSr25519Secret(new Uint8Array(32).fill(0x5b)));
136
143
  function makeHost(adapter) {
137
144
  return createSession({
138
145
  localAccount: localA,
139
146
  remoteAccount: remoteB,
140
147
  statementStore: adapter,
141
- encryption: mockEncryption(),
142
- prover: mockProver,
148
+ encryption: createEncryption(PAIRWISE_SECRET),
149
+ prover: realProver(),
143
150
  sessionKey: SHARED_KEY,
144
151
  });
145
152
  }
@@ -148,8 +155,8 @@ function makeMobile(adapter) {
148
155
  localAccount: localB,
149
156
  remoteAccount: remoteA,
150
157
  statementStore: adapter,
151
- encryption: mockEncryption(),
152
- prover: mockProver,
158
+ encryption: createEncryption(PAIRWISE_SECRET),
159
+ prover: realProver(),
153
160
  sessionKey: SHARED_KEY,
154
161
  });
155
162
  }
@@ -868,7 +875,7 @@ describe('session', () => {
868
875
  await settle();
869
876
  const requests = store
870
877
  .currentStatements()
871
- .map(s => StatementData.dec(s.data))
878
+ .map(s => StatementData.dec(createEncryption(PAIRWISE_SECRET).decrypt(s.data)._unsafeUnwrap()))
872
879
  .filter(d => d.tag === 'request');
873
880
  expect(requests.some(d => d.tag === 'request' && d.value.data.length > 0)).toBe(false);
874
881
  expect(requests.some(d => d.tag === 'request' && d.value.data.length === 0)).toBe(true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/statement-store",
3
3
  "type": "module",
4
- "version": "0.9.2",
4
+ "version": "0.9.4",
5
5
  "description": "Statement store integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@novasamatech/scale": "0.9.2",
28
+ "@novasamatech/scale": "0.9.4",
29
29
  "@novasamatech/sdk-statement": "^0.6.0",
30
- "@novasamatech/substrate-slot-sr25519-wasm": "0.9.2",
30
+ "@novasamatech/substrate-slot-sr25519-wasm": "0.9.4",
31
31
  "@polkadot-api/substrate-bindings": "^0.20.3",
32
32
  "@polkadot-api/substrate-client": "^0.7.0",
33
33
  "@polkadot-labs/hdkd-helpers": "^0.0.31",