@parity/product-sdk-terminal 0.12.0 → 0.13.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/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { cacheFilePath, withFileLock, loadJsonCache, saveJsonCache } from './chunk-EORPX5XL.js';
2
- export { requestResourceAllocation, sendResourceAllocation } from './chunk-EORPX5XL.js';
3
- import { createNodeStorageAdapter, sanitizeKey } from './chunk-GHOFKVUG.js';
4
- export { createNodeStorageAdapter } from './chunk-GHOFKVUG.js';
1
+ import { cacheFilePath, withFileLock, loadJsonCache, saveJsonCache } from './chunk-L75TTEEA.js';
2
+ export { requestResourceAllocation, sendResourceAllocation } from './chunk-L75TTEEA.js';
3
+ import { createNodeStorageAdapter, sanitizeKey } from './chunk-I3KMQJLW.js';
4
+ export { createNodeStorageAdapter } from './chunk-I3KMQJLW.js';
5
5
  import { SS_PREVIEW_STAGE_ENDPOINTS, createPappAdapter, AllowanceError } from '@novasamatech/host-papp';
6
6
  export { AllowanceError, SS_STABLE_STAGE_ENDPOINTS } from '@novasamatech/host-papp';
7
7
  import { createLazyClient, createPapiStatementStoreAdapter, NoAllowanceError } from '@novasamatech/statement-store';
@@ -10,6 +10,7 @@ import { getWsProvider } from '@polkadot-api/ws-provider';
10
10
  import { deriveProductAccountPublicKey } from '@parity/product-sdk-keys';
11
11
  import { AllowanceExpiredError } from '@parity/product-sdk-signer/errors';
12
12
  export { AllowanceExpiredError, SignerError } from '@parity/product-sdk-signer/errors';
13
+ import { createHostTxCreator } from '@parity/product-sdk-host/tx-creator';
13
14
  import { toHex, fromHex } from '@polkadot-api/utils';
14
15
  import { gcm } from '@noble/ciphers/aes.js';
15
16
  import { blake2b } from '@noble/hashes/blake2.js';
@@ -197,30 +198,20 @@ function toAllowanceExpiredError(error) {
197
198
  function toProductAccountId(ref) {
198
199
  return [ref.productId, { tag: "Index", value: ref.derivationIndex }];
199
200
  }
200
- function buildCreateTransactionRequest(productAccountId, callData, signedExtensions, txExtVersion) {
201
- const checkGenesis = signedExtensions.CheckGenesis;
202
- if (!checkGenesis) {
203
- throw new Error(
204
- "Cannot build transaction: chain did not provide the CheckGenesis signed extension"
205
- );
206
- }
201
+ function buildCreateTransactionRequest(productAccountId, request) {
207
202
  return {
208
203
  payload: {
209
204
  tag: "v1",
210
205
  value: {
211
206
  signer: productAccountId,
212
- // CheckGenesis carries the genesis hash as its additionalSigned (implicit) data.
213
- // `toHex` is typed `string`; the codec wants the 0x literal type.
214
- genesisHash: toHex(checkGenesis.additionalSigned),
215
- callData,
216
- extensions: Object.values(signedExtensions).map(
217
- ({ identifier, value, additionalSigned }) => ({
218
- id: identifier,
219
- extra: value,
220
- additionalSigned
221
- })
222
- ),
223
- txExtVersion
207
+ genesisHash: request.genesisHash,
208
+ callData: fromHex(request.callData),
209
+ extensions: request.extensions.map(({ id, extra, additionalSigned }) => ({
210
+ id,
211
+ extra: fromHex(extra),
212
+ additionalSigned: fromHex(additionalSigned)
213
+ })),
214
+ txExtVersion: request.txExtVersion
224
215
  }
225
216
  }
226
217
  };
@@ -234,17 +225,6 @@ async function requestSignedTransaction(session, request) {
234
225
  }
235
226
  return result.value;
236
227
  }
237
- function makeTxSignTx(session, productAccountId, txExtVersion) {
238
- return async (callData, signedExtensions) => requestSignedTransaction(
239
- session,
240
- buildCreateTransactionRequest(
241
- productAccountId,
242
- callData,
243
- signedExtensions,
244
- txExtVersion
245
- )
246
- );
247
- }
248
228
  function makeRawBytesSignCallback(session, productAccountId) {
249
229
  return async (data) => {
250
230
  const result = await session.signRaw({
@@ -275,17 +255,17 @@ async function deriveProductPublicKey(session, ref, options) {
275
255
  async function buildSessionSigner(session, ref, options) {
276
256
  const productAccountId = toProductAccountId(ref);
277
257
  const publicKey = ref.publicKey ?? await deriveProductPublicKey(session, ref, options);
278
- return {
258
+ return createHostTxCreator(
279
259
  publicKey,
280
- // Transaction signing → host-papp `createTransaction`: the wallet builds
281
- // and signs the extrinsic, so it can show a decoded tx (no `<Bytes>`
282
- // envelope) and unknown signed extensions (e.g. `AsPgas`) survive.
283
- signTx: makeTxSignTx(session, productAccountId, options?.txExtVersion ?? 0),
284
- // Arbitrary-byte signing keeps the `Bytes` tag so the wallet applies the
285
- // `<Bytes>...</Bytes>` anti-phishing envelope exactly once on its side
286
- // (correct for non-extrinsic user data).
287
- signBytes: makeRawBytesSignCallback(session, productAccountId)
288
- };
260
+ async (request) => toHex(
261
+ await requestSignedTransaction(
262
+ session,
263
+ buildCreateTransactionRequest(productAccountId, request)
264
+ )
265
+ ),
266
+ makeRawBytesSignCallback(session, productAccountId),
267
+ options?.txExtVersion ?? 0
268
+ );
289
269
  }
290
270
  function createSessionSigner(session, adapter, publicKey, options) {
291
271
  return buildSessionSigner(
@@ -347,6 +327,8 @@ function resolveSessionId(adapter, sessionId) {
347
327
  async function getBulletinSigner(adapter, productId, sessionId) {
348
328
  const resolvedSessionId = resolveSessionId(adapter, sessionId);
349
329
  return adapter.allowance.getBulletinSigner(resolvedSessionId, productId).match(
330
+ // host-papp 0.12 builds this with `getTxCreator`, so it carries
331
+ // `publicKey` and `signBytes`, but its declared type is plain `TxCreator`.
350
332
  (signer) => signer,
351
333
  (err) => {
352
334
  throw err;