Skip to content

Commit d01cfff

Browse files
authored
Merge pull request #46 from polybase/eng-331-api-ref-examples-doesnt-work-for-list
Add clarification to auth header and body args
2 parents e14b84e + a7bd3e4 commit d01cfff

File tree

5 files changed

+89
-8
lines changed

5 files changed

+89
-8
lines changed

api-reference/call-function.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Call a function"
3-
api: "POST https://testnet.polybase.xyz/v0/collections/<collection_path>/records/<record_id>/call/<function_name>"
3+
api: "POST https://testnet.polybase.xyz/v0/collections/{collection_path}/records/{record_id}/call/{function_name}"
44
---
55

66
<RequestExample>
@@ -9,6 +9,9 @@ api: "POST https://testnet.polybase.xyz/v0/collections/<collection_path>/records
99
curl --request POST \
1010
--url https://testnet.polybase.xyz/v0/collections/polybase%2Fcore%2Fusers/records/id123/call/functionName\
1111
--header 'Accept: application/json'
12+
-d '{ "args": ["Polybase"] }'
13+
# optional (if supplied ctx.publicKey will be populated)
14+
--header 'X-Polybase-Signature: v=0,t=1671884992,h=eth-personal-sign,sig=0x288db6271d92253ae19983a8e5110f1bc1bef1911210127ccbf657d85428ba9917aa9457f0f8e7f300a36b106525d3a3471e63ae265af4898742040a377e1da11c'
1215
```
1316

1417
</RequestExample>
@@ -32,4 +35,32 @@ curl --request POST \
3235

3336
<ParamField body="args" type="array" required>
3437
An array of arguments that should be passed to the the function being called on the collection, as defined in the collection schema.
38+
39+
For example, if the collection schema is as follows:
40+
41+
```js
42+
collection Users {
43+
id: string;
44+
name: string;
45+
46+
constructor (name: string) {
47+
this.id = PublicKey;
48+
this.name = name;
49+
}
50+
51+
setName(name: string) {
52+
this.name = name;
53+
}
54+
}
55+
```
56+
57+
The args would be:
58+
```json
59+
{
60+
args: [
61+
// This is the 1st parameter name: string
62+
"Polybase"
63+
]
64+
}
65+
```
3566
</ParamField>

api-reference/create-record.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Create a record"
3-
api: "POST https://testnet.polybase.xyz/v0/collections/<collection_path>/records"
3+
api: "POST https://testnet.polybase.xyz/v0/collections/{collection_path}/records"
44
---
55

66
<RequestExample>
@@ -9,6 +9,9 @@ api: "POST https://testnet.polybase.xyz/v0/collections/<collection_path>/records
99
curl --request POST \
1010
--url https://testnet.polybase.xyz/v0/collections/polybase%2Fcore%2Fusers/records\
1111
--header 'Accept: application/json'
12+
-d '{ "args": ["Polybase"] }'
13+
# optional (if supplied ctx.publicKey will be populated)
14+
--header 'X-Polybase-Signature: v=0,t=1671884992,h=eth-personal-sign,sig=0x288db6271d92253ae19983a8e5110f1bc1bef1911210127ccbf657d85428ba9917aa9457f0f8e7f300a36b106525d3a3471e63ae265af4898742040a377e1da11c'
1215
```
1316

1417
</RequestExample>
@@ -22,5 +25,31 @@ curl --request POST \
2225
## Body Params
2326

2427
<ParamField body="args" type="array" required>
25-
An array of arguments that should be passed to the the constructor of the collection, as defined in the collection schema.
28+
An array of arguments that should be passed to the the `constructor` of the collection, as defined in the collection schema. For example, if the collection schema is as follows:
29+
30+
```js
31+
collection Users {
32+
id: string;
33+
name: string;
34+
age: number;
35+
36+
constructor (name: string, age: number) {
37+
this.id = PublicKey;
38+
this.name = name;
39+
this.age = age;
40+
}
41+
}
42+
```
43+
44+
The args would be:
45+
```json
46+
{
47+
args: [
48+
// This is the 1st parameter name: string
49+
"Polybase",
50+
// This is the 2nd parameter age: number
51+
1
52+
]
53+
}
54+
```
2655
</ParamField>

api-reference/get-record.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Get record"
3-
api: "GET https://testnet.polybase.xyz/v0/collections/<collection_path>/records/<record_id>"
3+
api: "GET https://testnet.polybase.xyz/v0/collections/{collection_path}/records/<record_id>"
44
---
55

66
<RequestExample>

api-reference/list-records.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "List records"
3-
api: "GET https://testnet.polybase.xyz/v0/collections/<collection_path>/records"
3+
api: "GET https://testnet.polybase.xyz/v0/collections/{collection_path}/records"
44
---
55

66
<RequestExample>

api-reference/overview.mdx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ The Polybase Gatweay API uses public/private key pair for authentication. That m
1515
Authentication is composed of:
1616

1717
- `v` the version being used, should be `v=0`
18-
- `t` current unix timestamp in seconds
18+
- `t` current unix timestamp in milliseconds
1919
- `h` type of hash signing being used `eth-personal-sign` is currently the only allowed option
20-
- `sig` the signature of the data
20+
- `sig` the signature of the data (see below)
21+
- `pk` **optional** 65 byte public key (secp256k1 algorithm)
2122

2223

2324
An example of a valid authroization:
@@ -26,4 +27,24 @@ An example of a valid authroization:
2627
v=0,t=1671884992,h=eth-personal-sign,sig=0x288db6271d92253ae19983a8e5110f1bc1bef1911210127ccbf657d85428ba9917aa9457f0f8e7f300a36b106525d3a3471e63ae265af4898742040a377e1da11c
2728
```
2829

29-
The token is passed in the `X-Polybase-Signature` header of the request.
30+
The token is passed in the `X-Polybase-Signature` header of the request.
31+
32+
33+
### Signature (`sig`)
34+
35+
To generate `sig` you must sign a string in the format `<timestamp>.<body_json>`. Where `timestamp` is the `t` you provided above, and `body_json` is the body of the request (as a JSON string).
36+
37+
You can use the [@polybase/util](https://www.npmjs.com/package/@polybase/util) package to generate the signature from any 32 bytes private key, and the sign function to create the signature.
38+
39+
```typescript
40+
import { secp256k1 } from '@polybase/util'
41+
42+
// You can use any 32 byte private key from any library,
43+
// here is an example from @polybase/util
44+
let private_key = secp256k1.generatePrivateKey();
45+
46+
function createSig (timestamp, body) {
47+
const str_to_sign = `${timestamp}.${JSON.stringify(body)}`;
48+
return secp256k1.sign(privateKey, str_to_sign);
49+
}
50+
```

0 commit comments

Comments
 (0)