@0to1pay/server-sdk 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +28 -2
- package/dist/contracts/openapi.yaml +3862 -0
- package/dist/packages/domain/contract.d.ts +27 -0
- package/dist/packages/domain/contract.js +19 -0
- package/dist/packages/server-sdk/index.d.ts +184 -0
- package/dist/packages/server-sdk/index.js +160 -0
- package/dist/packages/server-sdk/recipient-proof.d.ts +10 -0
- package/dist/packages/server-sdk/recipient-proof.js +24 -0
- package/dist/packages/server-sdk/schema.d.ts +2712 -0
- package/dist/packages/server-sdk/schema.js +5 -0
- package/dist/packages/server-sdk/solana-recipient-proof.d.ts +3 -0
- package/dist/packages/server-sdk/solana-recipient-proof.js +28 -0
- package/dist/packages/server-sdk/tron-recipient-proof.d.ts +3 -0
- package/dist/packages/server-sdk/tron-recipient-proof.js +24 -0
- package/package.json +32 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RecipientProof } from './recipient-proof.js';
|
|
2
|
+
/** Return the exact UTF-8 message a recipient's Solana wallet signs via signMessage. */
|
|
3
|
+
export declare function solanaRecipientProofMessage(input: RecipientProof, denomination?: 'stable:USDC' | 'stable:USDT'): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const publicKey = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
2
|
+
const identifier = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
/** Return the exact UTF-8 message a recipient's Solana wallet signs via signMessage. */
|
|
4
|
+
export function solanaRecipientProofMessage(input, denomination = 'stable:USDC') {
|
|
5
|
+
const origin = new URL(input.origin);
|
|
6
|
+
const network = input.chain_id === 900001 ? 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
|
|
7
|
+
: input.chain_id === 900002 ? 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1' : undefined;
|
|
8
|
+
if (!network || !['https:', 'http:'].includes(origin.protocol) || origin.origin !== input.origin ||
|
|
9
|
+
![input.merchant_id, input.project_id, input.connection_id].every(value => identifier.test(value)) ||
|
|
10
|
+
!['test', 'live'].includes(input.environment) || !publicKey.test(input.address) ||
|
|
11
|
+
input.address === '11111111111111111111111111111111') {
|
|
12
|
+
throw new Error('INVALID_SOLANA_RECIPIENT_PROOF_SCOPE');
|
|
13
|
+
}
|
|
14
|
+
if (denomination !== 'stable:USDC' && denomination !== 'stable:USDT')
|
|
15
|
+
throw new Error('INVALID_SOLANA_RECIPIENT_PROOF_ASSET');
|
|
16
|
+
return [
|
|
17
|
+
denomination === 'stable:USDC' ? 'StablePay Solana recipient registration v1' : 'StablePay Solana recipient registration v2',
|
|
18
|
+
`I authorize the use of my native ${denomination.slice('stable:'.length)} associated token account for one order on this StablePay connection.`,
|
|
19
|
+
'',
|
|
20
|
+
'Origin: ' + origin.origin,
|
|
21
|
+
'Merchant: ' + input.merchant_id.toLowerCase(),
|
|
22
|
+
'Project: ' + input.project_id.toLowerCase(),
|
|
23
|
+
'Environment: ' + input.environment,
|
|
24
|
+
'Connection: ' + input.connection_id.toLowerCase(),
|
|
25
|
+
'Network: ' + network,
|
|
26
|
+
'Wallet: ' + input.address,
|
|
27
|
+
].join('\n');
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const address = /^T[1-9A-HJ-NP-Za-km-z]{33}$/;
|
|
2
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
/** Return the UTF-8 message a TRON wallet signs with signMessageV2. */
|
|
4
|
+
export function tronRecipientProofMessage(input) {
|
|
5
|
+
const origin = new URL(input.origin);
|
|
6
|
+
const validChain = input.environment === 'live' ? input.chain_id === 728126428 :
|
|
7
|
+
input.environment === 'test' && input.chain_id === 900003;
|
|
8
|
+
if (!validChain || !['https:', 'http:'].includes(origin.protocol) || origin.origin !== input.origin ||
|
|
9
|
+
![input.merchant_id, input.project_id, input.connection_id].every(value => uuid.test(value)) || !address.test(input.address)) {
|
|
10
|
+
throw new Error('INVALID_TRON_RECIPIENT_PROOF_SCOPE');
|
|
11
|
+
}
|
|
12
|
+
return [
|
|
13
|
+
'StablePay TRON recipient registration v1',
|
|
14
|
+
'I authorize the use of this address for one USDT order on this StablePay connection.',
|
|
15
|
+
'',
|
|
16
|
+
'Origin: ' + origin.origin,
|
|
17
|
+
'Merchant: ' + input.merchant_id.toLowerCase(),
|
|
18
|
+
'Project: ' + input.project_id.toLowerCase(),
|
|
19
|
+
'Environment: ' + input.environment,
|
|
20
|
+
'Connection: ' + input.connection_id.toLowerCase(),
|
|
21
|
+
'Network: tron:' + input.chain_id,
|
|
22
|
+
'Address: ' + input.address,
|
|
23
|
+
].join('\n');
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0to1pay/server-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Server-only 0to1Pay API client with OpenAPI request and response validation",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/apfl99/0to1pay-sdk.git",
|
|
10
|
+
"directory": "packages/server-sdk"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"registry": "https://registry.npmjs.org/"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.20.0"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"types": "./dist/packages/server-sdk/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/packages/server-sdk/index.d.ts",
|
|
26
|
+
"import": "./dist/packages/server-sdk/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"ajv": "8.20.0",
|
|
31
|
+
"ajv-formats": "3.0.1",
|
|
32
|
+
"yaml": "2.9.1"
|
|
33
|
+
}
|
|
34
|
+
}
|