@1shotapi/client-sdk 1.0.0 → 1.0.1
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 +93 -99
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @1shotapi/client-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client SDK for the [1Shot API](https://1shotapi.com). It provides a strongly typed REST client and a utility for verifying webhook signatures.
|
|
4
|
+
|
|
5
|
+
**API reference:** The M2M Gateway API is described in the [OpenAPI specification (m2mGatewaySpec.yaml)](https://github.com/1Shot-API/1Shot-API-SDK/blob/main/m2mGatewaySpec.yaml).
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
npm install @
|
|
10
|
+
npm install @1shotapi/client-sdk
|
|
9
11
|
```
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
@@ -13,150 +15,142 @@ npm install @uxly/1shot-client
|
|
|
13
15
|
### REST Client
|
|
14
16
|
|
|
15
17
|
```typescript
|
|
16
|
-
import { OneShotClient } from
|
|
18
|
+
import { OneShotClient } from "@1shotapi/client-sdk";
|
|
17
19
|
|
|
18
20
|
// Initialize the client
|
|
19
21
|
const client = new OneShotClient({
|
|
20
|
-
apiKey:
|
|
21
|
-
apiSecret:
|
|
22
|
-
baseUrl: 'https://api.1shotapi.com/v1' // Optional, defaults to this URL
|
|
22
|
+
apiKey: "your_api_key",
|
|
23
|
+
apiSecret: "your_api_secret",
|
|
23
24
|
});
|
|
25
|
+
```
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
const contractMethods = await client.contractMethods.list({
|
|
27
|
-
businessId: 'your_business_id',
|
|
28
|
-
params: { page: 1, pageSize: 10 }
|
|
29
|
-
});
|
|
27
|
+
### Contract Methods
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
// List contract methods for a business (businessId first, optional filters second)
|
|
31
|
+
const listResult = await client.contractMethods.list("your_business_id", {
|
|
32
|
+
page: 1,
|
|
33
|
+
pageSize: 10,
|
|
34
|
+
chainId: 1,
|
|
35
|
+
status: "live",
|
|
38
36
|
});
|
|
39
37
|
|
|
40
|
-
// Get
|
|
41
|
-
const contractMethod = await client.contractMethods.get(
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
name: 'recipient',
|
|
56
|
-
type: 'address'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'amount',
|
|
60
|
-
type: 'uint256'
|
|
61
|
-
}
|
|
62
|
-
]
|
|
38
|
+
// Get a single contract method by ID
|
|
39
|
+
const contractMethod = await client.contractMethods.get("your_contract_method_id");
|
|
40
|
+
|
|
41
|
+
// Execute a contract method (contractMethodId, params, optional options)
|
|
42
|
+
const transaction = await client.contractMethods.execute(
|
|
43
|
+
"your_contract_method_id",
|
|
44
|
+
{
|
|
45
|
+
amount: "1000000000000000000",
|
|
46
|
+
recipient: "0x1234567890123456789012345678901234567890",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
walletId: "optional_wallet_id",
|
|
50
|
+
memo: "Optional note for this execution",
|
|
51
|
+
value: "0", // For payable methods
|
|
63
52
|
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// Read the result of a view or pure function (no transaction, no gas)
|
|
56
|
+
const result = await client.contractMethods.read("your_contract_method_id", {
|
|
57
|
+
owner: "0x1234567890123456789012345678901234567890",
|
|
58
|
+
});
|
|
59
|
+
// result is the decoded return value (e.g. balance, token URI)
|
|
60
|
+
|
|
61
|
+
// Test a contract method without executing (simulation)
|
|
62
|
+
const testResult = await client.contractMethods.test(
|
|
63
|
+
"your_contract_method_id",
|
|
64
|
+
{ amount: "1000000", recipient: "0x..." },
|
|
65
|
+
{ value: "0" }
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Estimate gas for an execution
|
|
69
|
+
const estimate = await client.contractMethods.estimate(
|
|
70
|
+
"your_contract_method_id",
|
|
71
|
+
{ amount: "1000000", recipient: "0x..." }
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Create a new contract method
|
|
75
|
+
const newMethod = await client.contractMethods.create("your_business_id", {
|
|
76
|
+
chainId: 1,
|
|
77
|
+
contractAddress: "0x...",
|
|
78
|
+
walletId: "your_wallet_id",
|
|
79
|
+
name: "Transfer Tokens",
|
|
80
|
+
description: "Transfers ERC20 tokens to a recipient",
|
|
81
|
+
functionName: "transfer",
|
|
82
|
+
stateMutability: "nonpayable",
|
|
83
|
+
inputs: [
|
|
84
|
+
{ name: "recipient", type: "address", index: 0 },
|
|
85
|
+
{ name: "amount", type: "uint256", index: 1 },
|
|
86
|
+
],
|
|
87
|
+
outputs: [],
|
|
64
88
|
});
|
|
65
89
|
```
|
|
66
90
|
|
|
67
91
|
### Webhook Verification
|
|
68
92
|
|
|
69
|
-
#### Using the
|
|
93
|
+
#### Using the standalone function
|
|
70
94
|
|
|
71
95
|
```typescript
|
|
72
|
-
import { verifyWebhook } from
|
|
73
|
-
import express from
|
|
96
|
+
import { verifyWebhook } from "@1shotapi/client-sdk";
|
|
97
|
+
import express from "express";
|
|
74
98
|
|
|
75
99
|
const app = express();
|
|
76
100
|
app.use(express.json());
|
|
77
101
|
|
|
78
|
-
app.post(
|
|
79
|
-
// Get the webhook body and signature
|
|
102
|
+
app.post("/webhook", async (req, res) => {
|
|
80
103
|
const body = req.body;
|
|
81
104
|
const signature = body.signature;
|
|
82
105
|
delete body.signature;
|
|
83
|
-
|
|
106
|
+
|
|
84
107
|
if (!signature) {
|
|
85
|
-
return res.status(400).json({ error:
|
|
108
|
+
return res.status(400).json({ error: "Signature missing" });
|
|
86
109
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
110
|
+
|
|
111
|
+
const publicKey = "your_webhook_public_key";
|
|
112
|
+
|
|
91
113
|
try {
|
|
92
|
-
// Verify the webhook signature
|
|
93
114
|
const isValid = verifyWebhook({
|
|
94
115
|
body,
|
|
95
116
|
signature,
|
|
96
|
-
publicKey
|
|
117
|
+
publicKey,
|
|
97
118
|
});
|
|
98
|
-
|
|
119
|
+
|
|
99
120
|
if (!isValid) {
|
|
100
|
-
return res.status(403).json({ error:
|
|
121
|
+
return res.status(403).json({ error: "Invalid signature" });
|
|
101
122
|
}
|
|
102
|
-
|
|
103
|
-
return res.json({ message:
|
|
104
|
-
|
|
123
|
+
|
|
124
|
+
return res.json({ message: "Webhook verified successfully" });
|
|
105
125
|
} catch (error) {
|
|
106
126
|
return res.status(403).json({ error: error.message });
|
|
107
127
|
}
|
|
108
128
|
});
|
|
109
129
|
```
|
|
110
130
|
|
|
131
|
+
## Error handling
|
|
111
132
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
The client throws errors for various conditions:
|
|
133
|
+
The client can throw:
|
|
115
134
|
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
135
|
+
- **RequestError** – HTTP request failures
|
|
136
|
+
- **ZodError** – Invalid parameters (from schema validation)
|
|
137
|
+
- **InvalidSignatureError** – Invalid webhook signatures (from `verifyWebhook`)
|
|
119
138
|
|
|
120
|
-
## Type
|
|
139
|
+
## Type safety
|
|
121
140
|
|
|
122
|
-
|
|
141
|
+
All API methods and responses are typed. Models and options align with the [M2M Gateway API spec](https://github.com/1Shot-API/1Shot-API-SDK/blob/main/m2mGatewaySpec.yaml).
|
|
123
142
|
|
|
124
143
|
## Publishing
|
|
125
144
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
"version": "0.1.0" // Update this to your new version
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
2. Build the package:
|
|
136
|
-
```bash
|
|
137
|
-
npm run build
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
3. Test the build:
|
|
141
|
-
```bash
|
|
142
|
-
npm pack
|
|
143
|
-
npm install ./uxly-1shot-client-0.1.0.tgz
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
4. Publish to npm:
|
|
147
|
-
```bash
|
|
148
|
-
npm publish
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
Note: You'll need to have an npm account and be logged in. You can log in using:
|
|
152
|
-
```bash
|
|
153
|
-
npm login
|
|
154
|
-
```
|
|
145
|
+
1. Bump the version in `package.json`.
|
|
146
|
+
2. Build: `npm run build`
|
|
147
|
+
3. Test the tarball: `npm pack` then install the generated `.tgz`.
|
|
148
|
+
4. Publish: `npm publish` (after `npm login` if needed).
|
|
155
149
|
|
|
156
150
|
## Contributing
|
|
157
151
|
|
|
158
|
-
Contributions are welcome
|
|
152
|
+
Contributions are welcome. Please open a Pull Request.
|
|
159
153
|
|
|
160
154
|
## License
|
|
161
155
|
|
|
162
|
-
This project is licensed under the MIT License
|
|
156
|
+
This project is licensed under the MIT License – see the LICENSE file for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1shotapi/client-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "TypeScript client SDK for 1Shot API. Provides a strongly typed REST client and utility methods for verifying webhook signatures.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -63,9 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@noble/ed25519": "^2.2.0",
|
|
66
|
-
"@noble/hashes": "^1.3.3"
|
|
66
|
+
"@noble/hashes": "^1.3.3",
|
|
67
|
+
"zod": "^3.24.3"
|
|
67
68
|
},
|
|
68
|
-
"
|
|
69
|
-
"zod": "^3.0.0"
|
|
70
|
-
}
|
|
69
|
+
"packageManager": "yarn@4.1.1+sha512.ec40d0639bb307441b945d9467139cbb88d14394baac760b52eca038b330d16542d66fef61574271534ace5a200518dabf3b53a85f1f9e4bfa37141b538a9590"
|
|
71
70
|
}
|