@novasamatech/product-sdk 0.7.9-0 → 0.7.9-2

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.
@@ -46,7 +46,7 @@ export declare const createAccountsProvider: (transport?: Transport) => {
46
46
  * The factory is async because `PolkadotSigner.publicKey` must be a synchronous
47
47
  * `Uint8Array` on the returned object — it is fetched up front via `host_account_get`.
48
48
  */
49
- getProductAccountSigner(account: ProductAccount): PolkadotSigner;
49
+ getProductAccountSigner(account: ProductAccount, signerType?: "signPayload" | "createTransaction"): PolkadotSigner;
50
50
  subscribeAccountConnectionStatus(callback: (status: AccountConnectionStatus) => void): Subscription<void>;
51
51
  getLegacyAccountSigner(account: LegacyAccount): PolkadotSigner;
52
52
  };
@@ -87,7 +87,7 @@ export declare const accounts: {
87
87
  * The factory is async because `PolkadotSigner.publicKey` must be a synchronous
88
88
  * `Uint8Array` on the returned object — it is fetched up front via `host_account_get`.
89
89
  */
90
- getProductAccountSigner(account: ProductAccount): PolkadotSigner;
90
+ getProductAccountSigner(account: ProductAccount, signerType?: "signPayload" | "createTransaction"): PolkadotSigner;
91
91
  subscribeAccountConnectionStatus(callback: (status: AccountConnectionStatus) => void): Subscription<void>;
92
92
  getLegacyAccountSigner(account: LegacyAccount): PolkadotSigner;
93
93
  };
package/dist/accounts.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CreateProofErr, GetUserIdErr, LoginErr, RequestCredentialsErr, RingLocation, SigningPayload, SigningPayloadWithoutAccount, SigningRawPayloadWithoutAccount, assertEnumVariant, createHostApi, enumValue, fromHex, isEnumVariant, toHex, } from '@novasamatech/host-api';
1
+ import { CreateProofErr, GetUserIdErr, LoginErr, RequestCredentialsErr, RingLocation, SigningPayload, SigningPayloadWithoutAccount, SigningRawPayload, SigningRawPayloadWithoutAccount, assertEnumVariant, createHostApi, enumValue, fromHex, isEnumVariant, toHex, } from '@novasamatech/host-api';
2
2
  import { decAnyMetadata, unifyMetadata } from '@polkadot-api/substrate-bindings';
3
3
  import { err, ok } from 'neverthrow';
4
4
  import { getPolkadotSignerFromPjs } from 'polkadot-api/pjs-signer';
@@ -89,9 +89,57 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
89
89
  * The factory is async because `PolkadotSigner.publicKey` must be a synchronous
90
90
  * `Uint8Array` on the returned object — it is fetched up front via `host_account_get`.
91
91
  */
92
- getProductAccountSigner(account) {
92
+ getProductAccountSigner(account, signerType = 'signPayload') {
93
93
  const hostApi = createHostApi(transport);
94
94
  const productAccountId = [account.dotNsIdentifier, account.derivationIndex];
95
+ /**
96
+ * @deprecated added for backward compatibility
97
+ */
98
+ if (signerType === 'signPayload') {
99
+ return getPolkadotSignerFromPjs(toHex(account.publicKey), async (payload) => {
100
+ const codecPayload = {
101
+ account: [account.dotNsIdentifier, account.derivationIndex],
102
+ payload: buildSigningPayloadFields(payload),
103
+ };
104
+ const response = await hostApi.signPayload(enumValue('v1', codecPayload));
105
+ return response.match(response => {
106
+ assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
107
+ return {
108
+ id: 0,
109
+ signature: response.value.signature,
110
+ signedTransaction: response.value.signedTransaction,
111
+ };
112
+ }, err => {
113
+ assertEnumVariant(err, 'v1', UNSUPPORTED_VERSION_ERROR);
114
+ throw err.value;
115
+ });
116
+ }, async (raw) => {
117
+ const payload = {
118
+ account: [account.dotNsIdentifier, account.derivationIndex],
119
+ payload: raw.type === 'bytes'
120
+ ? {
121
+ tag: 'Bytes',
122
+ value: fromHex(asHex(raw.data)),
123
+ }
124
+ : {
125
+ tag: 'Payload',
126
+ value: raw.data,
127
+ },
128
+ };
129
+ const response = await hostApi.signRaw(enumValue('v1', payload));
130
+ return response.match(response => {
131
+ assertEnumVariant(response, 'v1', UNSUPPORTED_VERSION_ERROR);
132
+ return {
133
+ id: 0,
134
+ signature: response.value.signature,
135
+ signedTransaction: response.value.signedTransaction,
136
+ };
137
+ }, err => {
138
+ assertEnumVariant(err, 'v1', UNSUPPORTED_VERSION_ERROR);
139
+ throw err.value;
140
+ });
141
+ });
142
+ }
95
143
  return {
96
144
  publicKey: account.publicKey,
97
145
  async signTx(callData, signedExtensions, metadata) {
@@ -99,8 +147,13 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
99
147
  const { version: versions } = decMeta.extrinsic;
100
148
  const latestVersion = versions.reduce((acc, v) => Math.max(acc, v), 0);
101
149
  const txExtVersion = latestVersion === 4 ? 0 : latestVersion;
150
+ const checkGenesis = signedExtensions['CheckGenesis'];
151
+ if (!checkGenesis) {
152
+ throw new Error("Can't find genesis hash on transaction");
153
+ }
102
154
  const txPayload = {
103
155
  signer: productAccountId,
156
+ genesisHash: checkGenesis.value,
104
157
  callData,
105
158
  extensions: Object.values(signedExtensions).map(({ identifier, value, additionalSigned }) => ({
106
159
  id: identifier,
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { ChatBotRegistrationResult, ChatCustomMessageRenderer, ChatCustomMe
8
8
  export { createProductChatManager, matchChatCustomRenderers } from './chat.js';
9
9
  export type { ProductAccountId, SignedStatement, Statement, StatementTopicFilter, StatementsPage, Topic, } from './statementStore.js';
10
10
  export { createStatementStore } from './statementStore.js';
11
- export type { AccountConnectionStatus, ProductAccount } from './accounts.js';
11
+ export type { AccountConnectionStatus, LegacyAccount, ProductAccount } from './accounts.js';
12
12
  export { accounts, createAccountsProvider } from './accounts.js';
13
13
  export type { ThemeMode } from './theme.js';
14
14
  export { createThemeProvider } from './theme.js';
@@ -108,9 +108,14 @@ export async function createLegacyExtensionEnableFactory(transport) {
108
108
  if (!signer) {
109
109
  throw new Error("Signer can't route transaction to the right account without signer hint.");
110
110
  }
111
+ const checkGenesis = payload.extensions.find(x => x.id === 'CheckGenesis');
112
+ if (!checkGenesis) {
113
+ throw new Error("Can't find genesis hash on transaction");
114
+ }
111
115
  const possibleAccountId = accountId.enc(signer);
112
116
  const response = await hostApi.createTransactionWithLegacyAccount(enumValue('v1', {
113
117
  signer: possibleAccountId,
118
+ genesisHash: fromHex(checkGenesis.extra),
114
119
  callData: fromHex(payload.callData),
115
120
  txExtVersion: payload.txExtVersion,
116
121
  extensions: payload.extensions.map(e => ({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/product-sdk",
3
3
  "type": "module",
4
- "version": "0.7.9-0",
4
+ "version": "0.7.9-2",
5
5
  "description": "Polkadot product SDK: integrate and run your product inside Polkadot browser.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "@polkadot/extension-inject": "^0.63.1",
29
29
  "@polkadot-api/json-rpc-provider-proxy": "^0.4.0",
30
30
  "@polkadot-api/substrate-bindings": "^0.20.2",
31
- "@novasamatech/host-api": "0.7.9-0",
31
+ "@novasamatech/host-api": "0.7.9-2",
32
32
  "polkadot-api": ">=2",
33
33
  "neverthrow": "^8.2.0"
34
34
  },