Skip to content

Commit d0716c3

Browse files
committed
docs: Update certificate reference with runtime SDK examples
Expand the runtime certificate section with examples for the gl-sdk (Python, Kotlin, Swift, JavaScript) using the new DeveloperCert type and Scheduler builder, plus gl-client direct usage examples.
1 parent ec158c1 commit d0716c3

1 file changed

Lines changed: 82 additions & 13 deletions

File tree

docs/src/reference/certs.md

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,101 @@ warning: Set "GL_CUSTOM_NOBODY_KEY" and "GL_CUSTOM_NOBODY_CERT" to use a custom
5353

5454
In case you do not want to provide the certificate at compile-time,
5555
e.g., because you are using pre-compiled language bindings, you can
56-
also provide the certificates at runtime. The following code snippets show how to construct a `Signer` and a `Scheduler` instance with the certificates:
56+
also provide the certificates at runtime.
57+
58+
### Using the SDK (recommended)
59+
60+
The SDK (`gl-sdk`) provides a `DeveloperCert` type and a builder
61+
method on the `Scheduler`. Create a `DeveloperCert` from the PEM
62+
bytes of the certificate and key, then pass it to the scheduler using
63+
`with_developer_cert()`:
64+
65+
=== "Python"
66+
```python
67+
import glsdk
68+
69+
# Load cert and key bytes (e.g., from files or secure storage)
70+
cert = open("client.crt", "rb").read()
71+
key = open("client-key.pem", "rb").read()
72+
73+
dev_cert = glsdk.DeveloperCert(cert, key)
74+
scheduler = glsdk.Scheduler(glsdk.Network.BITCOIN).with_developer_cert(dev_cert)
75+
creds = scheduler.register(signer, code=None)
76+
```
77+
78+
=== "Kotlin"
79+
```kotlin
80+
val cert = File("client.crt").readBytes()
81+
val key = File("client-key.pem").readBytes()
82+
83+
val devCert = DeveloperCert(cert, key)
84+
val scheduler = Scheduler(Network.BITCOIN).withDeveloperCert(devCert)
85+
val creds = scheduler.register(signer, null)
86+
```
87+
88+
=== "Swift"
89+
```swift
90+
let cert = try Data(contentsOf: URL(fileURLWithPath: "client.crt"))
91+
let key = try Data(contentsOf: URL(fileURLWithPath: "client-key.pem"))
92+
93+
let devCert = DeveloperCert(cert: cert, key: key)
94+
let scheduler = Scheduler(network: .bitcoin).withDeveloperCert(cert: devCert)
95+
let creds = try scheduler.register(signer: signer, code: nil)
96+
```
97+
98+
=== "JavaScript"
99+
```javascript
100+
const { DeveloperCert, Scheduler } = require('gl-sdk');
101+
102+
const cert = fs.readFileSync('client.crt');
103+
const key = fs.readFileSync('client-key.pem');
104+
105+
const devCert = new DeveloperCert(cert, key);
106+
const scheduler = new Scheduler('bitcoin').withDeveloperCert(devCert);
107+
const creds = await scheduler.register(signer);
108+
```
109+
110+
If you are using an invite code instead of a developer certificate,
111+
simply omit the `with_developer_cert()` call:
112+
113+
```python
114+
scheduler = glsdk.Scheduler(glsdk.Network.BITCOIN)
115+
creds = scheduler.register(signer, code="your-invite-code")
116+
```
117+
118+
### Using gl-client directly
119+
120+
For the lower-level `gl-client` library, you can construct a
121+
`Nobody` credential with custom certificate bytes:
57122

58123
=== "Rust"
59124
```rust
60-
use gl_client::tls::{Signer, Scheduler, TlsConfig};
61-
let tls = TlsConfig::new()?.identity(certificate, key);
125+
use gl_client::credentials::Nobody;
126+
use gl_client::scheduler::Scheduler;
127+
use gl_client::signer::Signer;
62128

63-
let signer = Signer(seed, Network::Bitcoin, tls);
129+
let cert = std::fs::read("client.crt")?;
130+
let key = std::fs::read("client-key.pem")?;
131+
let developer_creds = Nobody::with(cert, key);
64132

65-
let scheduler = Scheduler::with(signer.node_id(), Network::Bitcoin, "uri", &tls).await?;
133+
let signer = Signer::new(seed, Network::Bitcoin, developer_creds.clone())?;
134+
let scheduler = Scheduler::new(Network::Bitcoin, developer_creds).await?;
135+
let res = scheduler.register(&signer, None).await?;
66136
```
67137

68138
=== "Python"
69139
```python
70-
from glclient import TlsConfig, Signer, Scheduler
71-
tls = TlsConfig().identity(res.device_cert, res.device_key)
140+
from glclient import Credentials, Signer, Scheduler
72141

73-
signer = Signer(seed, network="bitcoin", tls=tls)
142+
cert = open("client.crt", "rb").read()
143+
key = open("client-key.pem", "rb").read()
144+
creds = Credentials.nobody_with(cert, key)
74145

75-
node = Scheduler(node_id=signer.node_id(), network="bitcoin", tls=tls).node()
146+
signer = Signer(seed, network="bitcoin", creds=creds)
147+
scheduler = Scheduler(network="bitcoin", creds=creds)
148+
res = scheduler.register(signer)
76149
```
77150

78-
Notice that this is the same way that the `TlsConfig` is configured
79-
with the user credentials provided from the `register()` and
80-
`recover()` results.
81-
82151
!!! important
83152
Certificates are credentials authenticating you as the
84153
developer of the Application, just like API keys. Do not publish

0 commit comments

Comments
 (0)