Skip to content

Commit 8f51a3b

Browse files
committed
fix(contracts): add browser stub for custom-network-signatures export
1 parent cf14f19 commit 8f51a3b

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
const UNSUPPORTED_MESSAGE = "@lit-protocol/contracts/custom-network-signatures is not supported in browser environments. Please pre-generate contract signatures in a Node.js process and ship the artifacts instead.";
3+
function throwBrowserUnsupported() {
4+
throw new Error(UNSUPPORTED_MESSAGE);
5+
}
6+
function buildSignaturesFromContext(_options) {
7+
return throwBrowserUnsupported();
8+
}
9+
async function generateSignaturesFromContext(_options) {
10+
throwBrowserUnsupported();
11+
}
12+
module.exports = {
13+
buildSignaturesFromContext,
14+
generateSignaturesFromContext
15+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Browser stub for @lit-protocol/contracts/custom-network-signatures.
3+
* These utilities require Node.js filesystem access and cannot run in the browser.
4+
*/
5+
const UNSUPPORTED_MESSAGE = "@lit-protocol/contracts/custom-network-signatures is not supported in browser environments. Please pre-generate contract signatures in a Node.js process and ship the artifacts instead.";
6+
function throwBrowserUnsupported() {
7+
throw new Error(UNSUPPORTED_MESSAGE);
8+
}
9+
function buildSignaturesFromContext(_options) {
10+
return throwBrowserUnsupported();
11+
}
12+
async function generateSignaturesFromContext(_options) {
13+
throwBrowserUnsupported();
14+
}
15+
export {
16+
buildSignaturesFromContext,
17+
generateSignaturesFromContext
18+
};

packages/contracts/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
"types": "./dist/signatures/develop.d.ts"
9595
},
9696
"./custom-network-signatures": {
97+
"browser": {
98+
"import": "./dist/custom-network-signatures.browser.js",
99+
"require": "./dist/custom-network-signatures.browser.cjs"
100+
},
97101
"import": "./dist/custom-network-signatures.js",
98102
"require": "./dist/custom-network-signatures.cjs",
99103
"types": "./dist/custom-network-signatures.d.ts"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type {
2+
BuildSignaturesFromContextOptions,
3+
BuildSignaturesFromContextResult,
4+
GenerateSignaturesOptions,
5+
} from './custom-network-signatures';
6+
7+
const UNSUPPORTED_MESSAGE =
8+
'@lit-protocol/contracts/custom-network-signatures is not supported in browser environments. ' +
9+
'Please generate contract signatures ahead of time in a Node.js process and ship the artifacts instead.';
10+
11+
function throwBrowserUnsupported(): never {
12+
throw new Error(UNSUPPORTED_MESSAGE);
13+
}
14+
15+
export function buildSignaturesFromContext(
16+
_options: BuildSignaturesFromContextOptions
17+
): BuildSignaturesFromContextResult {
18+
return throwBrowserUnsupported();
19+
}
20+
21+
export async function generateSignaturesFromContext(
22+
_options: GenerateSignaturesOptions
23+
): Promise<never> {
24+
throwBrowserUnsupported();
25+
}
26+
27+
export type {
28+
BuildSignaturesFromContextOptions,
29+
BuildSignaturesFromContextResult,
30+
GenerateSignaturesOptions,
31+
} from './custom-network-signatures';

0 commit comments

Comments
 (0)