@getpara/rest-sdk 2.32.0
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 +175 -0
- package/dist/cjs/ethers/index.js +193 -0
- package/dist/cjs/index.js +339 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/solana/index.js +246 -0
- package/dist/cjs/viem/index.js +178 -0
- package/dist/esm/ethers/index.js +168 -0
- package/dist/esm/index.js +312 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/solana/index.js +225 -0
- package/dist/esm/viem/index.js +157 -0
- package/dist/types/ethers/index.d.ts +23 -0
- package/dist/types/index.d.ts +292 -0
- package/dist/types/solana/index.d.ts +12 -0
- package/dist/types/viem/index.d.ts +11 -0
- package/package.json +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @getpara/rest-sdk
|
|
2
|
+
|
|
3
|
+
Typed REST client for Para server-to-server wallet operations.
|
|
4
|
+
|
|
5
|
+
Use this package when your backend owns the workflow and signs with Para REST API keys. Do not ship it to browsers,
|
|
6
|
+
React apps, mobile apps, wallets, or any other user-controlled runtime. It sends `X-API-Key` on every request.
|
|
7
|
+
|
|
8
|
+
Use `@getpara/rest-sdk` for API-key-backed pregen or programmatic wallets. Use `@getpara/server-sdk` when you need
|
|
9
|
+
Para's share-backed server SDK flows, imported user sessions, or core SDK behavior. Use Web, React, React Native,
|
|
10
|
+
Swift, or Flutter SDKs for user-facing authentication and wallet UX.
|
|
11
|
+
|
|
12
|
+
The core client covers Para's public REST wallet surface:
|
|
13
|
+
|
|
14
|
+
- wallet creation, listing, lookup, and identifier updates
|
|
15
|
+
- SDK pregen share migration and enclave public-key lookup
|
|
16
|
+
- balances, signing, transfers, fee estimation, faucet requests, and REST transaction history
|
|
17
|
+
- REST-specific headers and behavior: `X-API-Key`, `X-Request-Id`, caller-supplied `Idempotency-Key`, `AbortSignal`,
|
|
18
|
+
environment selection, fetch injection, JSON serialization errors, validation errors, and HTTP error mapping
|
|
19
|
+
|
|
20
|
+
The adapter subpaths expose the signing subset through ethers v6, viem v2, and Solana v2 signer interfaces.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
yarn add @getpara/rest-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Install only the peer dependencies for the adapters you use:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn add ethers
|
|
32
|
+
yarn add viem
|
|
33
|
+
yarn add @solana/addresses @solana/keys @solana/signers @solana/transactions
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The core client expects Node.js 18+ or an injected `fetch`.
|
|
37
|
+
|
|
38
|
+
## Client
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { ParaRestClient, ParaRestError } from '@getpara/rest-sdk';
|
|
42
|
+
|
|
43
|
+
const para = new ParaRestClient({
|
|
44
|
+
apiKey: process.env.PARA_API_KEY!,
|
|
45
|
+
env: 'BETA',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const wallet = await para.createWallet({
|
|
49
|
+
type: 'EVM',
|
|
50
|
+
userIdentifier: 'user@test.getpara.com',
|
|
51
|
+
userIdentifierType: 'EMAIL',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const signature = await para.signMessage(wallet.id, { message: 'hello' });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`env` accepts `PROD`, `BETA`, `SANDBOX`, or `{ baseUrl }`. Pass `fetch` to inject your runtime's fetch implementation,
|
|
58
|
+
pass `requestIdGenerator` if you want to control `X-Request-Id` values, and pass `AbortSignal` in call options to
|
|
59
|
+
cancel in-flight requests.
|
|
60
|
+
|
|
61
|
+
`ParaRestError` is thrown for non-2xx HTTP responses and includes `status`, `code`, `requestId`, and the parsed response
|
|
62
|
+
body. `ParaRestValidationError` is thrown before `fetch` for missing local required values. `ParaRestSerializationError`
|
|
63
|
+
is thrown before `fetch` when a request body cannot be JSON serialized.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
try {
|
|
67
|
+
await para.getWallet(wallet.id, { signal: AbortSignal.timeout(10_000) });
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof ParaRestError) {
|
|
70
|
+
console.error(error.status, error.code, error.requestId, error.body);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Signing Behavior
|
|
76
|
+
|
|
77
|
+
EVM message and typed-data signing send unhashed payloads to REST. Para hashes EIP-191 and EIP-712 payloads server-side
|
|
78
|
+
before signing. The ethers adapter follows ethers' own typed-data behavior and omits any caller-provided `EIP712Domain`
|
|
79
|
+
entry from `types` before forwarding to REST.
|
|
80
|
+
|
|
81
|
+
The viem adapter follows viem's `signMessage` split: string messages are forwarded to REST `sign-message`, while
|
|
82
|
+
byte-like messages are hashed locally and forwarded to REST `sign-raw`. Pass `{ raw: bytes }` when a `0x...` string
|
|
83
|
+
should be treated as bytes instead of text.
|
|
84
|
+
|
|
85
|
+
EVM transaction signing returns the REST API's signed transaction response. The SDK normalizes the caller's transaction
|
|
86
|
+
request before sending it, but does not re-derive the signed payload locally or diff every returned field against the
|
|
87
|
+
request. REST EVM transaction signing supports ordinary legacy and EIP-1559 sends only; contract deployments, access
|
|
88
|
+
lists, blob transactions, authorization-list transactions, and custom viem serializers are rejected before calling REST.
|
|
89
|
+
|
|
90
|
+
The Solana adapter implements the Solana v2 signer traits by signing message bytes through `sign-raw`. It returns
|
|
91
|
+
signature dictionaries and can merge signatures into Solana v2 message and transaction objects. Use
|
|
92
|
+
`para.signTransaction(..., { broadcast: true })` or `para.transfer(...)` when your backend wants REST to submit a
|
|
93
|
+
transaction and return a `transactionId`.
|
|
94
|
+
|
|
95
|
+
`Idempotency-Key` is caller-supplied per request:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
await para.createWallet(
|
|
99
|
+
{
|
|
100
|
+
type: 'EVM',
|
|
101
|
+
userIdentifier: 'user@test.getpara.com',
|
|
102
|
+
userIdentifierType: 'EMAIL',
|
|
103
|
+
},
|
|
104
|
+
{ idempotencyKey: crypto.randomUUID() },
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use an idempotency key when a retry could create duplicate state or submit duplicate signing/broadcast work. The SDK
|
|
109
|
+
does not generate one for you because it does not retry requests internally.
|
|
110
|
+
|
|
111
|
+
## Transaction History
|
|
112
|
+
|
|
113
|
+
When REST broadcasts a transaction, `signTransaction(..., { broadcast: true })` and `transfer(...)` return a
|
|
114
|
+
`transactionId`. Store that id with your own order, payout, or job record so you can reconcile the broadcast later.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const result = await para.signTransaction(wallet.id, {
|
|
118
|
+
transaction,
|
|
119
|
+
broadcast: true,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (result.transactionId) {
|
|
123
|
+
const record = await para.getRestTransaction(wallet.id, result.transactionId);
|
|
124
|
+
console.log(record.status, record.hash);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const recent = await para.listRestTransactions(wallet.id, {
|
|
128
|
+
status: 'confirmed',
|
|
129
|
+
limit: 10,
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Webhooks are the preferred way to receive asynchronous status changes after a broadcast. Treat the REST SDK history
|
|
134
|
+
methods as the read model: fetch the record immediately after a broadcast, backfill missed webhook deliveries, or
|
|
135
|
+
reconcile your database against Para's persisted transaction state. See the Para webhook docs for signature
|
|
136
|
+
verification and `rest.transaction.confirmed` / `rest.transaction.failed` payload examples.
|
|
137
|
+
|
|
138
|
+
## Adapters
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { createParaRestEthersSigner } from '@getpara/rest-sdk/ethers';
|
|
142
|
+
import { createParaRestViemAccount } from '@getpara/rest-sdk/viem';
|
|
143
|
+
import { createParaRestSolanaSigner } from '@getpara/rest-sdk/solana';
|
|
144
|
+
|
|
145
|
+
const ethersSigner = createParaRestEthersSigner({
|
|
146
|
+
client: para,
|
|
147
|
+
walletId,
|
|
148
|
+
address,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const viemAccount = createParaRestViemAccount({
|
|
152
|
+
client: para,
|
|
153
|
+
walletId,
|
|
154
|
+
address: address as `0x${string}`,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const solanaSigner = createParaRestSolanaSigner({
|
|
158
|
+
client: para,
|
|
159
|
+
walletId: solanaWalletId,
|
|
160
|
+
address: solanaAddress,
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Unsupported Surfaces
|
|
165
|
+
|
|
166
|
+
This package intentionally does not include browser connectors, React hooks, wagmi or RainbowKit connectors, mobile
|
|
167
|
+
auth, user session flows, account creation UI, MPC share storage, share-migration encryption helpers, legacy adapters,
|
|
168
|
+
or automatic retries. Use `@getpara/server-sdk` for `migrateWalletShare`. Keep API keys on your backend and expose
|
|
169
|
+
only your own application-specific routes to clients.
|
|
170
|
+
|
|
171
|
+
## Sandbox Probe Fixture
|
|
172
|
+
|
|
173
|
+
`scripts/probe-signature-format.ts` can probe sandbox signature formats when `PARA_API_KEY` is available. The sanitized
|
|
174
|
+
fixture in `src/__fixtures__/signature-formats.json` documents observed behavior for regression tests. It is not a
|
|
175
|
+
replacement for the OpenAPI contract or the live REST router behavior.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var ethers_exports = {};
|
|
39
|
+
__export(ethers_exports, {
|
|
40
|
+
ParaRestEthersSigner: () => ParaRestEthersSigner,
|
|
41
|
+
createParaRestEthersSigner: () => createParaRestEthersSigner,
|
|
42
|
+
normalizeEvmSignature: () => normalizeEvmSignature
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(ethers_exports);
|
|
45
|
+
var import_ethers = require("ethers");
|
|
46
|
+
var import__ = require("../index.js");
|
|
47
|
+
class ParaRestEthersSigner extends import_ethers.ethers.AbstractSigner {
|
|
48
|
+
constructor({ client, walletId, address, provider }) {
|
|
49
|
+
super(provider);
|
|
50
|
+
if (!client) {
|
|
51
|
+
throw new import__.ParaRestValidationError("client is required");
|
|
52
|
+
}
|
|
53
|
+
if (!walletId) {
|
|
54
|
+
throw new import__.ParaRestValidationError("walletId is required");
|
|
55
|
+
}
|
|
56
|
+
this.client = client;
|
|
57
|
+
this.walletId = walletId;
|
|
58
|
+
this.initialAddress = address;
|
|
59
|
+
}
|
|
60
|
+
connect(provider) {
|
|
61
|
+
return new ParaRestEthersSigner({
|
|
62
|
+
client: this.client,
|
|
63
|
+
walletId: this.walletId,
|
|
64
|
+
address: this.initialAddress,
|
|
65
|
+
provider
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getAddress() {
|
|
69
|
+
return __async(this, null, function* () {
|
|
70
|
+
if (this.initialAddress) {
|
|
71
|
+
return import_ethers.ethers.getAddress(this.initialAddress);
|
|
72
|
+
}
|
|
73
|
+
if (!this.cachedWallet) {
|
|
74
|
+
this.cachedWallet = yield this.client.getWallet(this.walletId);
|
|
75
|
+
}
|
|
76
|
+
if (!this.cachedWallet.address) {
|
|
77
|
+
throw new import__.ParaRestValidationError("wallet address is not available");
|
|
78
|
+
}
|
|
79
|
+
return import_ethers.ethers.getAddress(this.cachedWallet.address);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
signMessage(message) {
|
|
83
|
+
return __async(this, null, function* () {
|
|
84
|
+
if (typeof message === "string") {
|
|
85
|
+
const res2 = yield this.client.signMessage(this.walletId, { message });
|
|
86
|
+
return normalizeEvmSignature(res2.signature);
|
|
87
|
+
}
|
|
88
|
+
const digest = import_ethers.ethers.hashMessage(message);
|
|
89
|
+
const res = yield this.client.signRaw(this.walletId, { data: digest, walletType: "EVM" });
|
|
90
|
+
return normalizeEvmSignature(res.signature);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
signTransaction(tx) {
|
|
94
|
+
return __async(this, null, function* () {
|
|
95
|
+
const transaction = yield this.toRestTransaction(tx);
|
|
96
|
+
const res = yield this.client.signTransaction(this.walletId, { transaction });
|
|
97
|
+
return res.signedTransaction;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
signTypedData(domain, types, value) {
|
|
101
|
+
return __async(this, null, function* () {
|
|
102
|
+
const populated = yield import_ethers.ethers.TypedDataEncoder.resolveNames(domain, types, value, (name) => __async(this, null, function* () {
|
|
103
|
+
import_ethers.ethers.assert(this.provider != null, "cannot resolve ENS names without a provider", "UNSUPPORTED_OPERATION", {
|
|
104
|
+
operation: "resolveName",
|
|
105
|
+
info: { name }
|
|
106
|
+
});
|
|
107
|
+
const address = yield this.provider.resolveName(name);
|
|
108
|
+
import_ethers.ethers.assert(address != null, "unconfigured ENS name", "UNCONFIGURED_NAME", {
|
|
109
|
+
value: name
|
|
110
|
+
});
|
|
111
|
+
return address;
|
|
112
|
+
}));
|
|
113
|
+
const typesWithoutDomain = stripEip712Domain(types);
|
|
114
|
+
const typedData = {
|
|
115
|
+
domain: populated.domain,
|
|
116
|
+
message: populated.value,
|
|
117
|
+
primaryType: import_ethers.ethers.TypedDataEncoder.from(typesWithoutDomain).primaryType,
|
|
118
|
+
types: typesWithoutDomain
|
|
119
|
+
};
|
|
120
|
+
const res = yield this.client.signTypedData(this.walletId, { typedData });
|
|
121
|
+
return normalizeEvmSignature(res.signature);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
toRestTransaction(tx) {
|
|
125
|
+
return __async(this, null, function* () {
|
|
126
|
+
const resolved = yield import_ethers.ethers.resolveProperties(tx);
|
|
127
|
+
const to = resolved.to ? yield import_ethers.ethers.resolveAddress(resolved.to, this.provider) : void 0;
|
|
128
|
+
const from = resolved.from ? yield import_ethers.ethers.resolveAddress(resolved.from, this.provider) : void 0;
|
|
129
|
+
if (!to) {
|
|
130
|
+
throw new import__.ParaRestValidationError("transaction.to is required");
|
|
131
|
+
}
|
|
132
|
+
if (from && import_ethers.ethers.getAddress(from) !== import_ethers.ethers.getAddress(yield this.getAddress())) {
|
|
133
|
+
throw new import__.ParaRestValidationError("transaction from address mismatch");
|
|
134
|
+
}
|
|
135
|
+
if (resolved.chainId == null) {
|
|
136
|
+
throw new import__.ParaRestValidationError("transaction.chainId is required");
|
|
137
|
+
}
|
|
138
|
+
if (resolved.accessList != null) {
|
|
139
|
+
throw new import__.ParaRestValidationError("transaction.accessList is not supported by the REST signer");
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
to,
|
|
143
|
+
value: quantityToDecimalString(resolved.value),
|
|
144
|
+
chainId: quantityToDecimalString(resolved.chainId),
|
|
145
|
+
data: resolved.data ? import_ethers.ethers.hexlify(resolved.data) : void 0,
|
|
146
|
+
nonce: resolved.nonce == null ? void 0 : Number(resolved.nonce),
|
|
147
|
+
gasLimit: quantityToDecimalString(resolved.gasLimit),
|
|
148
|
+
maxFeePerGas: quantityToDecimalString(resolved.maxFeePerGas),
|
|
149
|
+
maxPriorityFeePerGas: quantityToDecimalString(resolved.maxPriorityFeePerGas),
|
|
150
|
+
gasPrice: quantityToDecimalString(resolved.gasPrice),
|
|
151
|
+
type: normalizeTransactionType(resolved.type, resolved.gasPrice)
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function createParaRestEthersSigner(options) {
|
|
157
|
+
return new ParaRestEthersSigner(options);
|
|
158
|
+
}
|
|
159
|
+
function normalizeEvmSignature(signature) {
|
|
160
|
+
const prefixed = signature.startsWith("0x") ? signature : `0x${signature}`;
|
|
161
|
+
const parsed = import_ethers.ethers.Signature.from(prefixed);
|
|
162
|
+
return parsed.serialized;
|
|
163
|
+
}
|
|
164
|
+
function quantityToDecimalString(value) {
|
|
165
|
+
if (value == null) {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
return import_ethers.ethers.toBigInt(value).toString(10);
|
|
169
|
+
}
|
|
170
|
+
function normalizeTransactionType(type, gasPrice) {
|
|
171
|
+
if (type == null) {
|
|
172
|
+
return gasPrice == null ? 2 : 0;
|
|
173
|
+
}
|
|
174
|
+
const numericType = Number(type);
|
|
175
|
+
if (numericType !== 0 && numericType !== 2) {
|
|
176
|
+
throw new import__.ParaRestValidationError("transaction.type must be 0 or 2");
|
|
177
|
+
}
|
|
178
|
+
return numericType;
|
|
179
|
+
}
|
|
180
|
+
function stripEip712Domain(types) {
|
|
181
|
+
const restTypes = {};
|
|
182
|
+
for (const [typeName, fields] of Object.entries(types)) {
|
|
183
|
+
if (typeName === "EIP712Domain") continue;
|
|
184
|
+
restTypes[typeName] = fields.map((field) => ({ name: field.name, type: field.type }));
|
|
185
|
+
}
|
|
186
|
+
return restTypes;
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
ParaRestEthersSigner,
|
|
191
|
+
createParaRestEthersSigner,
|
|
192
|
+
normalizeEvmSignature
|
|
193
|
+
});
|