@novasamatech/host-api-wrapper 0.8.10 → 0.8.12

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/README.md CHANGED
@@ -250,11 +250,48 @@ if (accountResult.isOk()) {
250
250
  console.log('Public key:', account.publicKey);
251
251
  }
252
252
 
253
- // Get account alias
254
- const aliasResult = await accounts.getProductAccountAlias('product.dot', 0);
253
+ // Ring VRF: a contextual alias and a proof are addressed by a product-scoped
254
+ // `context` (`[productId, suffix]`) and a `ring` location on a chain (RFC 0004).
255
+ const context: [string, string] = ['product.dot', '0x00']; // [productId, 0x-hex suffix]
256
+ const ring = {
257
+ chainId: '0x…', // 32-byte chain genesis hash
258
+ junctions: [{ tag: 'PalletInstance', value: 42 }],
259
+ };
260
+
261
+ // Get the contextual alias for that (context, ring).
262
+ const aliasResult = await accounts.getContextualAlias(context, ring);
255
263
 
256
264
  if (aliasResult.isOk()) {
257
- console.log('Alias:', aliasResult.value);
265
+ const { context: contextBytes, alias } = aliasResult.value;
266
+ console.log('Alias:', alias);
267
+ }
268
+
269
+ // Create a ring VRF proof binding `message`; the host selects the member key.
270
+ const proofResult = await accounts.createRingVRFProof(context, ring, new Uint8Array([0x48, 0x69]));
271
+
272
+ if (proofResult.isOk()) {
273
+ const { proof, contextualAlias, ringIndex, ringRevision } = proofResult.value;
274
+ console.log('Proof:', proof, 'at ring index', ringIndex, 'revision', ringRevision);
275
+ }
276
+
277
+ // sr25519 VRF signature over a product account (RFC-0023). The transcript is a
278
+ // recipe — a root label plus ordered `(label, value)` items — that the host
279
+ // replays verbatim (`Transcript::new(label)` then one `append_message` per item)
280
+ // and signs. It never injects a `signer` item; pass the account's public key
281
+ // yourself if the transcript needs one.
282
+ import type { VrfTranscriptItem } from '@novasamatech/host-api-wrapper';
283
+
284
+ const transcriptLabel = new TextEncoder().encode('my-product-lottery');
285
+ const items: VrfTranscriptItem[] = [{ label: new TextEncoder().encode('round'), value: new Uint8Array([7]) }];
286
+
287
+ const vrfResult = await accounts.signVrf('product.dot', 0, transcriptLabel, items);
288
+
289
+ if (vrfResult.isOk()) {
290
+ const { preOutput, proof } = vrfResult.value; // 32-byte VRFPreOut, 64-byte VRFProof
291
+ console.log('VRF pre-output:', preOutput, 'proof:', proof);
292
+ } else {
293
+ // err.tag: 'NotConnected' | 'Rejected' | 'Unknown'
294
+ console.error('signVrf failed:', vrfResult.error.tag);
258
295
  }
259
296
 
260
297
  // Get legacy accounts (external wallets)
@@ -1,5 +1,5 @@
1
- import type { AccountConnectionStatus as AccountConnectionStatusCodec, CodecType, LegacyAccount as LegacyAccountCodec, ProductAccountId as ProductAccountIdCodec, Subscription, Transport } from '@novasamatech/host-api';
2
- import { RingLocation } from '@novasamatech/host-api';
1
+ import type { AccountConnectionStatus as AccountConnectionStatusCodec, CodecType, LegacyAccount as LegacyAccountCodec, ProductAccountId as ProductAccountIdCodec, Subscription, Transport, VrfTranscriptItem as VrfTranscriptItemCodec } from '@novasamatech/host-api';
2
+ import { ProductProofContext, RingLocation } from '@novasamatech/host-api';
3
3
  import type { PolkadotSigner } from 'polkadot-api';
4
4
  export type ProductAccountId = CodecType<typeof ProductAccountIdCodec>;
5
5
  export type ProductAccount = {
@@ -9,6 +9,8 @@ export type ProductAccount = {
9
9
  };
10
10
  export type LegacyAccount = CodecType<typeof LegacyAccountCodec>;
11
11
  export type AccountConnectionStatus = CodecType<typeof AccountConnectionStatusCodec>;
12
+ /** One `transcript.append_message(label, value)` call replayed by the host (RFC-0023). */
13
+ export type VrfTranscriptItem = CodecType<typeof VrfTranscriptItemCodec>;
12
14
  export declare const createAccountsProvider: (transport?: Transport) => {
13
15
  getUserId(): import("neverthrow").ResultAsync<{
14
16
  primaryUsername: string;
@@ -25,21 +27,43 @@ export declare const createAccountsProvider: (transport?: Transport) => {
25
27
  }, import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
26
28
  reason: string;
27
29
  }, "RequestCredentialsErr::Unknown">>;
28
- getProductAccountAlias(dotNsIdentifier: string, derivationIndex?: number): import("neverthrow").ResultAsync<{
30
+ getContextualAlias(context: CodecType<typeof ProductProofContext>, ring: CodecType<typeof RingLocation>): import("neverthrow").ResultAsync<{
29
31
  context: Uint8Array<ArrayBufferLike>;
30
32
  alias: Uint8Array<ArrayBufferLike>;
31
- }, import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
33
+ }, import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::Rejected"> | import("@novasamatech/scale").CodecError<{
32
34
  reason: string;
33
- }, "RequestCredentialsErr::Unknown">>;
35
+ }, "GetAliasErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::RingNotFound"> | import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::NotMember">>;
34
36
  getLegacyAccounts(): import("neverthrow").ResultAsync<{
35
37
  publicKey: Uint8Array<ArrayBufferLike>;
36
38
  name: string | undefined;
37
39
  }[], import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
38
40
  reason: string;
39
41
  }, "RequestCredentialsErr::Unknown">>;
40
- createRingVRFProof(dotNsIdentifier: string, derivationIndex: number | undefined, location: CodecType<typeof RingLocation>, message: Uint8Array): import("neverthrow").ResultAsync<Uint8Array<ArrayBufferLike>, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
42
+ createRingVRFProof(context: CodecType<typeof ProductProofContext>, ring: CodecType<typeof RingLocation>, message: Uint8Array): import("neverthrow").ResultAsync<{
43
+ proof: Uint8Array<ArrayBufferLike>;
44
+ contextualAlias: {
45
+ context: Uint8Array<ArrayBufferLike>;
46
+ alias: Uint8Array<ArrayBufferLike>;
47
+ };
48
+ ringIndex: number;
49
+ ringRevision: number;
50
+ }, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
51
+ reason: string;
52
+ }, "CreateProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::RingNotFound"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::NotMember">>;
53
+ /**
54
+ * Produces an sr25519 (schnorrkel) VRF signature from a product account (RFC-0023).
55
+ *
56
+ * The host replays `transcriptLabel` and `items` into a Merlin transcript verbatim —
57
+ * `Transcript::new(transcriptLabel)` then one `append_message(label, value)` per item,
58
+ * in order — and signs it. Callers that need a `signer` item must pass their own public
59
+ * key (from `getProductAccount`); the host never injects it.
60
+ */
61
+ signVrf(dotNsIdentifier: string, derivationIndex: number, transcriptLabel: Uint8Array, items: VrfTranscriptItem[]): import("neverthrow").ResultAsync<{
62
+ preOutput: Uint8Array<ArrayBufferLike>;
63
+ proof: Uint8Array<ArrayBufferLike>;
64
+ }, import("@novasamatech/scale").CodecError<undefined, "SignVrfErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "SignVrfErr::Rejected"> | import("@novasamatech/scale").CodecError<{
41
65
  reason: string;
42
- }, "CreateProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::RingNotFound">>;
66
+ }, "SignVrfErr::Unknown">>;
43
67
  /**
44
68
  * Builds a `PolkadotSigner` that delegates to the host via `host_create_transaction`.
45
69
  *
@@ -66,21 +90,43 @@ export declare const accounts: {
66
90
  }, import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
67
91
  reason: string;
68
92
  }, "RequestCredentialsErr::Unknown">>;
69
- getProductAccountAlias(dotNsIdentifier: string, derivationIndex?: number): import("neverthrow").ResultAsync<{
93
+ getContextualAlias(context: CodecType<typeof ProductProofContext>, ring: CodecType<typeof RingLocation>): import("neverthrow").ResultAsync<{
70
94
  context: Uint8Array<ArrayBufferLike>;
71
95
  alias: Uint8Array<ArrayBufferLike>;
72
- }, import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
96
+ }, import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::Rejected"> | import("@novasamatech/scale").CodecError<{
73
97
  reason: string;
74
- }, "RequestCredentialsErr::Unknown">>;
98
+ }, "GetAliasErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::RingNotFound"> | import("@novasamatech/scale").CodecError<undefined, "GetAliasErr::NotMember">>;
75
99
  getLegacyAccounts(): import("neverthrow").ResultAsync<{
76
100
  publicKey: Uint8Array<ArrayBufferLike>;
77
101
  name: string | undefined;
78
102
  }[], import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::Rejected"> | import("@novasamatech/scale").CodecError<undefined, "RequestCredentialsErr::DomainNotValid"> | import("@novasamatech/scale").CodecError<{
79
103
  reason: string;
80
104
  }, "RequestCredentialsErr::Unknown">>;
81
- createRingVRFProof(dotNsIdentifier: string, derivationIndex: number | undefined, location: CodecType<typeof RingLocation>, message: Uint8Array): import("neverthrow").ResultAsync<Uint8Array<ArrayBufferLike>, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
105
+ createRingVRFProof(context: CodecType<typeof ProductProofContext>, ring: CodecType<typeof RingLocation>, message: Uint8Array): import("neverthrow").ResultAsync<{
106
+ proof: Uint8Array<ArrayBufferLike>;
107
+ contextualAlias: {
108
+ context: Uint8Array<ArrayBufferLike>;
109
+ alias: Uint8Array<ArrayBufferLike>;
110
+ };
111
+ ringIndex: number;
112
+ ringRevision: number;
113
+ }, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
114
+ reason: string;
115
+ }, "CreateProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::RingNotFound"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::NotMember">>;
116
+ /**
117
+ * Produces an sr25519 (schnorrkel) VRF signature from a product account (RFC-0023).
118
+ *
119
+ * The host replays `transcriptLabel` and `items` into a Merlin transcript verbatim —
120
+ * `Transcript::new(transcriptLabel)` then one `append_message(label, value)` per item,
121
+ * in order — and signs it. Callers that need a `signer` item must pass their own public
122
+ * key (from `getProductAccount`); the host never injects it.
123
+ */
124
+ signVrf(dotNsIdentifier: string, derivationIndex: number, transcriptLabel: Uint8Array, items: VrfTranscriptItem[]): import("neverthrow").ResultAsync<{
125
+ preOutput: Uint8Array<ArrayBufferLike>;
126
+ proof: Uint8Array<ArrayBufferLike>;
127
+ }, import("@novasamatech/scale").CodecError<undefined, "SignVrfErr::NotConnected"> | import("@novasamatech/scale").CodecError<undefined, "SignVrfErr::Rejected"> | import("@novasamatech/scale").CodecError<{
82
128
  reason: string;
83
- }, "CreateProofErr::Unknown"> | import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::RingNotFound">>;
129
+ }, "SignVrfErr::Unknown">>;
84
130
  /**
85
131
  * Builds a `PolkadotSigner` that delegates to the host via `host_create_transaction`.
86
132
  *
package/dist/accounts.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CreateProofErr, GetUserIdErr, LoginErr, RequestCredentialsErr, RingLocation, SigningPayload, SigningPayloadWithoutAccount, SigningRawPayload, SigningRawPayloadWithoutAccount, assertEnumVariant, createHostApi, enumValue, fromHex, isEnumVariant, toHex, } from '@novasamatech/host-api';
1
+ import { CreateProofErr, GetAliasErr, GetUserIdErr, LoginErr, ProductProofContext, RequestCredentialsErr, RingLocation, SignVrfErr, 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 { AccountId } from 'polkadot-api';
@@ -48,16 +48,16 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
48
48
  return err(new RequestCredentialsErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
49
49
  });
50
50
  },
51
- getProductAccountAlias(dotNsIdentifier, derivationIndex = 0) {
51
+ getContextualAlias(context, ring) {
52
52
  return hostApi
53
- .accountGetAlias(enumValue('v1', [dotNsIdentifier, derivationIndex]))
53
+ .accountGetAlias(enumValue('v1', [context, ring]))
54
54
  .mapErr(e => e.value)
55
55
  .andThen(response => {
56
56
  if (isEnumVariant(response, 'v1')) {
57
57
  return ok(response.value);
58
58
  }
59
59
  // @ts-expect-error response.tag is never here
60
- return err(new RequestCredentialsErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
60
+ return err(new GetAliasErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
61
61
  });
62
62
  },
63
63
  getLegacyAccounts() {
@@ -72,9 +72,9 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
72
72
  return err(new RequestCredentialsErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
73
73
  });
74
74
  },
75
- createRingVRFProof(dotNsIdentifier, derivationIndex = 0, location, message) {
75
+ createRingVRFProof(context, ring, message) {
76
76
  return hostApi
77
- .accountCreateProof(enumValue('v1', [[dotNsIdentifier, derivationIndex], location, message]))
77
+ .accountCreateProof(enumValue('v1', [context, ring, message]))
78
78
  .mapErr(e => e.value)
79
79
  .andThen(response => {
80
80
  if (isEnumVariant(response, 'v1')) {
@@ -84,6 +84,26 @@ export const createAccountsProvider = (transport = sandboxTransport) => {
84
84
  return err(new CreateProofErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
85
85
  });
86
86
  },
87
+ /**
88
+ * Produces an sr25519 (schnorrkel) VRF signature from a product account (RFC-0023).
89
+ *
90
+ * The host replays `transcriptLabel` and `items` into a Merlin transcript verbatim —
91
+ * `Transcript::new(transcriptLabel)` then one `append_message(label, value)` per item,
92
+ * in order — and signs it. Callers that need a `signer` item must pass their own public
93
+ * key (from `getProductAccount`); the host never injects it.
94
+ */
95
+ signVrf(dotNsIdentifier, derivationIndex, transcriptLabel, items) {
96
+ return hostApi
97
+ .accountSignVrf(enumValue('v1', { account: [dotNsIdentifier, derivationIndex], transcriptLabel, items }))
98
+ .mapErr(e => e.value)
99
+ .andThen(response => {
100
+ if (isEnumVariant(response, 'v1')) {
101
+ return ok(response.value);
102
+ }
103
+ // @ts-expect-error response.tag is never here
104
+ return err(new SignVrfErr.Unknown({ reason: `Unsupported response version ${response.tag}` }));
105
+ });
106
+ },
87
107
  /**
88
108
  * Builds a `PolkadotSigner` that delegates to the host via `host_create_transaction`.
89
109
  *
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, LegacyAccount, ProductAccount } from './accounts.js';
11
+ export type { AccountConnectionStatus, LegacyAccount, ProductAccount, VrfTranscriptItem } 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';
@@ -32,9 +32,10 @@ export const createLocalStorage = (transport = sandboxTransport) => {
32
32
  return writeBytes(key, textEncoder.encode(value));
33
33
  },
34
34
  async readJSON(key) {
35
- return readBytes(key)
36
- .then(bytes => textDecoder.decode(bytes))
37
- .then(JSON.parse);
35
+ const bytes = await readBytes(key);
36
+ if (bytes === undefined || bytes.length === 0)
37
+ return undefined;
38
+ return JSON.parse(textDecoder.decode(bytes));
38
39
  },
39
40
  async writeJSON(key, value) {
40
41
  return writeBytes(key, textEncoder.encode(JSON.stringify(value)));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-api-wrapper",
3
3
  "type": "module",
4
- "version": "0.8.10",
4
+ "version": "0.8.12",
5
5
  "description": "Host API wrapper: 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.3",
31
- "@novasamatech/host-api": "0.8.10",
31
+ "@novasamatech/host-api": "0.8.12",
32
32
  "polkadot-api": ">=2",
33
33
  "neverthrow": "^8.2.0"
34
34
  },