@novasamatech/host-api-wrapper 0.8.11 → 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 +20 -0
- package/dist/accounts.d.ts +31 -1
- package/dist/accounts.js +21 -1
- package/dist/index.d.ts +1 -1
- package/dist/localStorage.js +4 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -274,6 +274,26 @@ if (proofResult.isOk()) {
|
|
|
274
274
|
console.log('Proof:', proof, 'at ring index', ringIndex, 'revision', ringRevision);
|
|
275
275
|
}
|
|
276
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);
|
|
295
|
+
}
|
|
296
|
+
|
|
277
297
|
// Get legacy accounts (external wallets)
|
|
278
298
|
const legacyAccountsResult = await accounts.getLegacyAccounts();
|
|
279
299
|
|
package/dist/accounts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountConnectionStatus as AccountConnectionStatusCodec, CodecType, LegacyAccount as LegacyAccountCodec, ProductAccountId as ProductAccountIdCodec, Subscription, Transport } 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
2
|
import { ProductProofContext, RingLocation } from '@novasamatech/host-api';
|
|
3
3
|
import type { PolkadotSigner } from 'polkadot-api';
|
|
4
4
|
export type ProductAccountId = CodecType<typeof ProductAccountIdCodec>;
|
|
@@ -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;
|
|
@@ -48,6 +50,20 @@ export declare const createAccountsProvider: (transport?: Transport) => {
|
|
|
48
50
|
}, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
49
51
|
reason: string;
|
|
50
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<{
|
|
65
|
+
reason: string;
|
|
66
|
+
}, "SignVrfErr::Unknown">>;
|
|
51
67
|
/**
|
|
52
68
|
* Builds a `PolkadotSigner` that delegates to the host via `host_create_transaction`.
|
|
53
69
|
*
|
|
@@ -97,6 +113,20 @@ export declare const accounts: {
|
|
|
97
113
|
}, import("@novasamatech/scale").CodecError<undefined, "CreateProofErr::Rejected"> | import("@novasamatech/scale").CodecError<{
|
|
98
114
|
reason: string;
|
|
99
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<{
|
|
128
|
+
reason: string;
|
|
129
|
+
}, "SignVrfErr::Unknown">>;
|
|
100
130
|
/**
|
|
101
131
|
* Builds a `PolkadotSigner` that delegates to the host via `host_create_transaction`.
|
|
102
132
|
*
|
package/dist/accounts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateProofErr, GetAliasErr, GetUserIdErr, LoginErr, ProductProofContext, 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';
|
|
@@ -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';
|
package/dist/localStorage.js
CHANGED
|
@@ -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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
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.
|
|
31
|
+
"@novasamatech/host-api": "0.8.12",
|
|
32
32
|
"polkadot-api": ">=2",
|
|
33
33
|
"neverthrow": "^8.2.0"
|
|
34
34
|
},
|