prividium 0.1.7 → 0.1.9
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
|
@@ -54,7 +54,7 @@ const prividium = createPrividiumChain({
|
|
|
54
54
|
chain: prividiumChain,
|
|
55
55
|
rpcUrl: 'https://rpc.prividium.io',
|
|
56
56
|
authBaseUrl: 'https://auth.prividium.io',
|
|
57
|
-
|
|
57
|
+
prividiumApiBaseUrl: 'https://permissions.prividium.io/api',
|
|
58
58
|
redirectUrl: window.location.origin + '/auth/callback',
|
|
59
59
|
onAuthExpiry: () => {
|
|
60
60
|
console.log('Authentication expired - please reconnect');
|
|
@@ -231,7 +231,7 @@ const prividium = createPrividiumChain({
|
|
|
231
231
|
chain: prividiumChain,
|
|
232
232
|
rpcUrl: 'https://rpc.prividium.io',
|
|
233
233
|
authBaseUrl: 'https://auth.prividium.io',
|
|
234
|
-
|
|
234
|
+
prividiumApiBaseUrl: 'https://permissions.prividium.io/api',
|
|
235
235
|
redirectUrl: window.location.origin + '/auth/callback',
|
|
236
236
|
onAuthExpiry: () => {
|
|
237
237
|
console.log('Authentication expired');
|
|
@@ -263,9 +263,8 @@ Creates a new Prividium™ SDK instance.
|
|
|
263
263
|
interface PrividiumConfig {
|
|
264
264
|
clientId: string; // OAuth client ID
|
|
265
265
|
chain: Chain; // Viem chain configuration (without rpcUrls)
|
|
266
|
-
rpcUrl: string; // Private RPC endpoint URL
|
|
267
266
|
authBaseUrl: string; // Authorization service base URL
|
|
268
|
-
|
|
267
|
+
prividiumApiBaseUrl: string; // Permissions API service base URL
|
|
269
268
|
redirectUrl: string; // OAuth redirect URL
|
|
270
269
|
storage?: Storage; // Custom storage implementation (optional)
|
|
271
270
|
onAuthExpiry?: () => void; // Called when authentication expires (optional)
|
|
@@ -397,7 +396,7 @@ const testnetPrividium = createPrividiumChain({
|
|
|
397
396
|
chain: testnetChain,
|
|
398
397
|
rpcUrl: 'https://testnet-rpc.prividium.io',
|
|
399
398
|
authBaseUrl: 'https://testnet-auth.prividium.io',
|
|
400
|
-
|
|
399
|
+
prividiumApiBaseUrl: 'https://testnet-permissions.prividium.io/api',
|
|
401
400
|
redirectUrl: window.location.origin + '/auth/callback'
|
|
402
401
|
});
|
|
403
402
|
|
|
@@ -406,7 +405,7 @@ const mainnetPrividium = createPrividiumChain({
|
|
|
406
405
|
chain: mainnetChain,
|
|
407
406
|
rpcUrl: 'https://mainnet-rpc.prividium.io',
|
|
408
407
|
authBaseUrl: 'https://mainnet-auth.prividium.io',
|
|
409
|
-
|
|
408
|
+
prividiumApiBaseUrl: 'https://mainnet-permissions.prividium.io/api',
|
|
410
409
|
redirectUrl: window.location.origin + '/auth/callback'
|
|
411
410
|
});
|
|
412
411
|
```
|
|
@@ -28,7 +28,7 @@ function checkHostAndPortWarnings(host, port, allowExternalAccess) {
|
|
|
28
28
|
}
|
|
29
29
|
async function startServer(opts) {
|
|
30
30
|
const config = new ConfigFile(opts.configPath);
|
|
31
|
-
const workflow = new CreationWorkflow(config);
|
|
31
|
+
const workflow = new CreationWorkflow(config, opts.host, opts.port);
|
|
32
32
|
workflow.start();
|
|
33
33
|
const configConfig = config.read();
|
|
34
34
|
const env = envSchema.parse(process.env);
|
|
@@ -48,11 +48,11 @@ async function startServer(opts) {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
checkHostAndPortWarnings(opts.host, opts.port, opts.allowExternalAccess);
|
|
51
|
-
|
|
51
|
+
await app.listen({
|
|
52
52
|
port: opts.port,
|
|
53
53
|
host: opts.host
|
|
54
54
|
});
|
|
55
|
-
await workflow.waitForAuthentication(
|
|
55
|
+
await workflow.waitForAuthentication(`http://${opts.host}:${opts.port}`);
|
|
56
56
|
}
|
|
57
57
|
export const addProxy = (cli) => {
|
|
58
58
|
return cli.command('proxy', 'Starts authenticated rpc proxy server', (yargs) => yargs
|
|
@@ -12,9 +12,13 @@ _____________|__|__ _|__| __| _/|__|__ __ _____ ____ | | |__|
|
|
|
12
12
|
export class CreationWorkflow {
|
|
13
13
|
config;
|
|
14
14
|
submitCallback;
|
|
15
|
-
|
|
15
|
+
host;
|
|
16
|
+
port;
|
|
17
|
+
constructor(config, host, port) {
|
|
16
18
|
this.config = config;
|
|
17
19
|
this.submitCallback = undefined;
|
|
20
|
+
this.host = host;
|
|
21
|
+
this.port = port;
|
|
18
22
|
}
|
|
19
23
|
start() {
|
|
20
24
|
console.log(color.blue(HEADER));
|
|
@@ -96,7 +100,7 @@ export class CreationWorkflow {
|
|
|
96
100
|
this.submitCallback('Authentication successful!');
|
|
97
101
|
await setTimeout(100);
|
|
98
102
|
}
|
|
99
|
-
log.info(`Your proxy rpc is ready! 🚀: \n\n${color.bold(
|
|
103
|
+
log.info(`Your proxy rpc is ready! 🚀: \n\n${color.bold(`http://${this.host}:${this.port}/rpc`)}\n`);
|
|
100
104
|
log.info('Waiting for logs...');
|
|
101
105
|
}
|
|
102
106
|
onMessage(msg) {
|
|
@@ -16,6 +16,7 @@ const rpcCallSchema = z.object({ method: z.string() });
|
|
|
16
16
|
const rpcReqSchema = z.union([rpcCallSchema, rpcCallSchema.array()]);
|
|
17
17
|
export function buildServer(config) {
|
|
18
18
|
const app = fastifyApp();
|
|
19
|
+
const validHosts = config.host === 'localhost' || config.host === '127.0.0.1' ? ['localhost', '127.0.0.1'] : [config.host];
|
|
19
20
|
app.setValidatorCompiler(validatorCompiler);
|
|
20
21
|
const state = randomStateString();
|
|
21
22
|
let accessToken = '';
|
|
@@ -79,9 +80,9 @@ export function buildServer(config) {
|
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
const portStr = config.port !== 80 ? `:${config.port}` : '';
|
|
82
|
-
const
|
|
83
|
-
if (req.headers.host && req.headers.host
|
|
84
|
-
log.error(`Expected host ${
|
|
83
|
+
const fullHosts = validHosts.map((host) => `${host}${portStr}`);
|
|
84
|
+
if (req.headers.host && !fullHosts.some((host) => req.headers.host === host)) {
|
|
85
|
+
log.error(`Expected host to by any of ${fullHosts.join(', ')} but got ${req.headers.host}`);
|
|
85
86
|
reply.status(403).send("host doesn't match");
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
@@ -3,7 +3,16 @@ import { mainnet } from 'viem/chains';
|
|
|
3
3
|
import { LocalStorage, TokenManager } from './storage.js';
|
|
4
4
|
import { PopupAuth } from './popup-auth.js';
|
|
5
5
|
import { hasPrividiumUnauthorizedError } from './error-utils.js';
|
|
6
|
+
function rpcUrl(apiUrl) {
|
|
7
|
+
return new URL('/rpc', apiUrl).toString();
|
|
8
|
+
}
|
|
9
|
+
function walletRpcUrl(apiUrl, token) {
|
|
10
|
+
return new URL(`/rpc/wallet/${token}`, apiUrl).toString();
|
|
11
|
+
}
|
|
6
12
|
export function createPrividiumChain(config) {
|
|
13
|
+
if (config.permissionsApiBaseUrl !== undefined) {
|
|
14
|
+
throw new Error('"permissionsApiBaseUrl" was deprecated. Please use "prividiumApiBaseUrl" instead.');
|
|
15
|
+
}
|
|
7
16
|
const storage = config.storage || new LocalStorage();
|
|
8
17
|
const tokenManager = new TokenManager(storage, config.chain.id);
|
|
9
18
|
const popupAuth = new PopupAuth({
|
|
@@ -23,7 +32,7 @@ export function createPrividiumChain(config) {
|
|
|
23
32
|
return null;
|
|
24
33
|
};
|
|
25
34
|
// Create transport with auth integration using viem callbacks
|
|
26
|
-
const transport = http(config.
|
|
35
|
+
const transport = http(rpcUrl(config.prividiumApiBaseUrl), {
|
|
27
36
|
batch: false,
|
|
28
37
|
fetchOptions: {
|
|
29
38
|
headers: getAuthHeaders() || {}
|
|
@@ -51,7 +60,7 @@ export function createPrividiumChain(config) {
|
|
|
51
60
|
...config.chain.contracts,
|
|
52
61
|
multicall3: undefined // Prividium™ doesn't support multicall yet
|
|
53
62
|
},
|
|
54
|
-
rpcUrls: { default: { http: [config.
|
|
63
|
+
rpcUrls: { default: { http: [rpcUrl(config.prividiumApiBaseUrl)] } },
|
|
55
64
|
blockExplorers: config.chain.blockExplorers
|
|
56
65
|
},
|
|
57
66
|
transport,
|
|
@@ -70,7 +79,7 @@ export function createPrividiumChain(config) {
|
|
|
70
79
|
if (!headers) {
|
|
71
80
|
throw new Error('Authentication required. Please call authorize() first.');
|
|
72
81
|
}
|
|
73
|
-
const response = await fetch(`${config.
|
|
82
|
+
const response = await fetch(`${config.prividiumApiBaseUrl}/api/profiles/me`, {
|
|
74
83
|
method: 'GET',
|
|
75
84
|
headers: {
|
|
76
85
|
'Content-Type': 'application/json',
|
|
@@ -100,7 +109,7 @@ export function createPrividiumChain(config) {
|
|
|
100
109
|
if (!headers) {
|
|
101
110
|
throw new Error('Authentication required. Please call authorize() first.');
|
|
102
111
|
}
|
|
103
|
-
const response = await fetch(`${config.
|
|
112
|
+
const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/personal-rpc-token`, {
|
|
104
113
|
method: 'GET',
|
|
105
114
|
headers: {
|
|
106
115
|
'Content-Type': 'application/json',
|
|
@@ -120,16 +129,14 @@ export function createPrividiumChain(config) {
|
|
|
120
129
|
},
|
|
121
130
|
async getWalletRpcUrl() {
|
|
122
131
|
const walletToken = await this.getWalletToken();
|
|
123
|
-
|
|
124
|
-
const baseUrl = config.rpcUrl.replace(/\/rpc.*$/, '');
|
|
125
|
-
return `${baseUrl}/wallet/${walletToken}`;
|
|
132
|
+
return walletRpcUrl(config.prividiumApiBaseUrl, walletToken);
|
|
126
133
|
},
|
|
127
134
|
async invalidateWalletToken() {
|
|
128
135
|
const headers = getAuthHeaders();
|
|
129
136
|
if (!headers) {
|
|
130
137
|
throw new Error('Authentication required. Please call authorize() first.');
|
|
131
138
|
}
|
|
132
|
-
const response = await fetch(`${config.
|
|
139
|
+
const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/invalidate`, {
|
|
133
140
|
method: 'POST',
|
|
134
141
|
headers: {
|
|
135
142
|
'Content-Type': 'application/json',
|
|
@@ -147,7 +154,7 @@ export function createPrividiumChain(config) {
|
|
|
147
154
|
if (!headers) {
|
|
148
155
|
throw new Error('Authentication required. Please call authorize() first.');
|
|
149
156
|
}
|
|
150
|
-
const response = await fetch(`${config.
|
|
157
|
+
const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/transaction-authorization`, {
|
|
151
158
|
method: 'POST',
|
|
152
159
|
headers: {
|
|
153
160
|
'Content-Type': 'application/json',
|
package/dist/sdk/types.d.ts
CHANGED
|
@@ -8,10 +8,13 @@ export interface Storage {
|
|
|
8
8
|
export interface PrividiumConfig {
|
|
9
9
|
clientId: string;
|
|
10
10
|
chain: Omit<Chain, 'rpcUrls'>;
|
|
11
|
-
rpcUrl: string;
|
|
12
11
|
authBaseUrl: string;
|
|
13
12
|
redirectUrl: string;
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use the `prividiumApiBaseUrl` field instead
|
|
15
|
+
*/
|
|
16
|
+
permissionsApiBaseUrl?: string;
|
|
17
|
+
prividiumApiBaseUrl: string;
|
|
15
18
|
storage?: Storage;
|
|
16
19
|
onAuthExpiry?: () => void;
|
|
17
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prividium",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"bin": {
|
|
5
5
|
"prividium": "./bin/cli.js"
|
|
6
6
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc -b &&
|
|
21
|
+
"build": "tsc -b && pnpm copy-static-files",
|
|
22
22
|
"copy-static-files": "cp -r cli/static dist/cli",
|
|
23
23
|
"dev": "tsc -b --watch",
|
|
24
24
|
"lint": "eslint . --ignore-path ../../.gitignore --max-warnings 0 --cache --cache-strategy content --cache-location ../../.eslint-cache/prividium-sdk",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@fastify/http-proxy": "^11.3.0",
|
|
35
35
|
"@fastify/static": "^8.3.0",
|
|
36
36
|
"appdirsjs": "^1.2.7",
|
|
37
|
-
"fastify": "^5.
|
|
37
|
+
"fastify": "^5.7.1",
|
|
38
38
|
"fastify-type-provider-zod": "^6.1.0",
|
|
39
39
|
"kleur": "^4.1.5",
|
|
40
40
|
"open": "^10.1.0",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@repo/eslint-config": "workspace:*",
|
|
49
49
|
"@types/node": "^22.8.6",
|
|
50
50
|
"@types/yargs": "^17.0.34",
|
|
51
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
51
52
|
"eslint": "^8",
|
|
52
53
|
"jsdom": "^25.0.0",
|
|
53
54
|
"tsx": "^4.20.6",
|