@azure-rest/confidential-ledger 1.1.2-alpha.20250122.1 → 1.1.2-alpha.20250124.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 +135 -66
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -46,44 +46,51 @@ Creating the client also requires your Confidential Ledger's URL and id, which y
|
|
|
46
46
|
|
|
47
47
|
Because Confidential Ledgers use self-signed certificates securely generated and stored in an enclave, the signing certificate for each Confidential Ledger must first be retrieved from the Confidential Ledger Identity Service.
|
|
48
48
|
|
|
49
|
-
```
|
|
50
|
-
import ConfidentialLedger, { getLedgerIdentity } from "
|
|
49
|
+
```ts snippet:ReadmeSampleCreateClient_Node
|
|
50
|
+
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
51
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
51
52
|
|
|
52
53
|
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// for example, https://identity.confidential-ledger.core.azure.com
|
|
56
|
-
IDENTITY_SERVICE_URL,
|
|
54
|
+
"test-ledger-name",
|
|
55
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
57
56
|
);
|
|
58
57
|
const credential = new DefaultAzureCredential();
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const client = ConfidentialLedger(
|
|
60
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
61
|
+
ledgerIdentityCertificate,
|
|
62
|
+
credential,
|
|
63
|
+
);
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
#### Using a client certificate
|
|
65
67
|
|
|
66
68
|
As an alternative to Azure Active Directory, clients may choose to authenticate with a client certificate in mutual TLS instead of via an Azure Active Directory token. For this kind of authentication, the client needs to be passed a `CertificateCredential` which is composed of a certificate and private key, both in PEM format.
|
|
67
69
|
|
|
68
|
-
```
|
|
70
|
+
```ts snippet:ReadmeSampleCreateClient_Certificate
|
|
69
71
|
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
70
72
|
|
|
71
73
|
// Get the signing certificate from the Confidential Ledger Identity Service
|
|
72
74
|
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
"test-ledger-name",
|
|
76
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
75
77
|
);
|
|
78
|
+
|
|
76
79
|
// both cert (certificate key) and key (private key) are in PEM format
|
|
77
|
-
const cert =
|
|
78
|
-
const key = PRIVATE_KEY;
|
|
80
|
+
const cert = "<PUBLIC_CERTIFICATE>";
|
|
81
|
+
const key = "<PRIVATE_KEY>";
|
|
82
|
+
|
|
79
83
|
// Create the Confidential Ledger Client
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
const client = ConfidentialLedger(
|
|
85
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
86
|
+
ledgerIdentityCertificate,
|
|
87
|
+
{
|
|
88
|
+
tlsOptions: {
|
|
89
|
+
cert,
|
|
90
|
+
key,
|
|
91
|
+
},
|
|
85
92
|
},
|
|
86
|
-
|
|
93
|
+
);
|
|
87
94
|
```
|
|
88
95
|
|
|
89
96
|
## Key concepts
|
|
@@ -127,9 +134,28 @@ This section contains code snippets for the following samples:
|
|
|
127
134
|
|
|
128
135
|
### Post Ledger Entry
|
|
129
136
|
|
|
130
|
-
```
|
|
137
|
+
```ts snippet:ReadmeSamplePostLedgerEntry
|
|
138
|
+
import ConfidentialLedger, {
|
|
139
|
+
getLedgerIdentity,
|
|
140
|
+
LedgerEntry,
|
|
141
|
+
CreateLedgerEntryParameters,
|
|
142
|
+
} from "@azure-rest/confidential-ledger";
|
|
143
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
144
|
+
|
|
145
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
146
|
+
"test-ledger-name",
|
|
147
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
148
|
+
);
|
|
149
|
+
const credential = new DefaultAzureCredential();
|
|
150
|
+
|
|
151
|
+
const client = ConfidentialLedger(
|
|
152
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
153
|
+
ledgerIdentityCertificate,
|
|
154
|
+
credential,
|
|
155
|
+
);
|
|
156
|
+
|
|
131
157
|
const entry: LedgerEntry = {
|
|
132
|
-
contents:
|
|
158
|
+
contents: "<content>",
|
|
133
159
|
};
|
|
134
160
|
const ledgerEntry: CreateLedgerEntryParameters = {
|
|
135
161
|
contentType: "application/json",
|
|
@@ -140,38 +166,117 @@ const result = await client.path("/app/transactions").post(ledgerEntry);
|
|
|
140
166
|
|
|
141
167
|
### Get a Ledger Entry By Transaction Id
|
|
142
168
|
|
|
143
|
-
```
|
|
169
|
+
```ts snippet:ReadmeSampleGetLedgerEntry
|
|
170
|
+
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
171
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
172
|
+
|
|
173
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
174
|
+
"test-ledger-name",
|
|
175
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
176
|
+
);
|
|
177
|
+
const credential = new DefaultAzureCredential();
|
|
178
|
+
|
|
179
|
+
const client = ConfidentialLedger(
|
|
180
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
181
|
+
ledgerIdentityCertificate,
|
|
182
|
+
credential,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const transactionId = "<TRANSACTION_ID>";
|
|
144
186
|
const status = await client.path("/app/transactions/{transactionId}/status", transactionId).get();
|
|
145
187
|
```
|
|
146
188
|
|
|
147
189
|
### Get All Ledger Entries
|
|
148
190
|
|
|
149
|
-
```
|
|
191
|
+
```ts snippet:ReadmeSampleGetAllLedgerEntries
|
|
192
|
+
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
193
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
194
|
+
|
|
195
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
196
|
+
"test-ledger-name",
|
|
197
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
198
|
+
);
|
|
199
|
+
const credential = new DefaultAzureCredential();
|
|
200
|
+
|
|
201
|
+
const client = ConfidentialLedger(
|
|
202
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
203
|
+
ledgerIdentityCertificate,
|
|
204
|
+
credential,
|
|
205
|
+
);
|
|
206
|
+
|
|
150
207
|
const ledgerEntries = await client.path("/app/transactions");
|
|
151
208
|
```
|
|
152
209
|
|
|
153
210
|
### Get All Collections
|
|
154
211
|
|
|
155
|
-
```
|
|
212
|
+
```ts snippet:ReadmeSampleGetAllCollections
|
|
213
|
+
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
214
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
215
|
+
|
|
216
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
217
|
+
"test-ledger-name",
|
|
218
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
219
|
+
);
|
|
220
|
+
const credential = new DefaultAzureCredential();
|
|
221
|
+
|
|
222
|
+
const client = ConfidentialLedger(
|
|
223
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
224
|
+
ledgerIdentityCertificate,
|
|
225
|
+
credential,
|
|
226
|
+
);
|
|
227
|
+
|
|
156
228
|
const result = await client.path("/app/collections").get();
|
|
157
229
|
```
|
|
158
230
|
|
|
159
231
|
### Get Transactions for a Collection
|
|
160
232
|
|
|
161
|
-
```
|
|
233
|
+
```ts snippet:ReadmeSampleGetTransactionsForCollection
|
|
234
|
+
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
235
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
236
|
+
|
|
237
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
238
|
+
"test-ledger-name",
|
|
239
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
240
|
+
);
|
|
241
|
+
const credential = new DefaultAzureCredential();
|
|
242
|
+
|
|
243
|
+
const client = ConfidentialLedger(
|
|
244
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
245
|
+
ledgerIdentityCertificate,
|
|
246
|
+
credential,
|
|
247
|
+
);
|
|
248
|
+
|
|
162
249
|
const getLedgerEntriesParams = { queryParameters: { collectionId: "my collection" } };
|
|
163
250
|
const ledgerEntries = await client.path("/app/transactions").get(getLedgerEntriesParams);
|
|
164
251
|
```
|
|
165
252
|
|
|
166
253
|
### List Enclave Quotes
|
|
167
254
|
|
|
168
|
-
```
|
|
255
|
+
```ts snippet:ReadmeSampleListEnclaveQuotes
|
|
256
|
+
import ConfidentialLedger, {
|
|
257
|
+
getLedgerIdentity,
|
|
258
|
+
isUnexpected,
|
|
259
|
+
} from "@azure-rest/confidential-ledger";
|
|
260
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
261
|
+
|
|
262
|
+
const { ledgerIdentityCertificate } = await getLedgerIdentity(
|
|
263
|
+
"test-ledger-name",
|
|
264
|
+
"https://identity.confidential-ledger.core.azure.com",
|
|
265
|
+
);
|
|
266
|
+
const credential = new DefaultAzureCredential();
|
|
267
|
+
|
|
268
|
+
const client = ConfidentialLedger(
|
|
269
|
+
"https://test-ledger-name.confidential-ledger.azure.com",
|
|
270
|
+
ledgerIdentityCertificate,
|
|
271
|
+
credential,
|
|
272
|
+
);
|
|
273
|
+
|
|
169
274
|
// Get enclave quotes
|
|
170
|
-
const enclaveQuotes = await
|
|
275
|
+
const enclaveQuotes = await client.path("/app/enclaveQuotes").get();
|
|
171
276
|
|
|
172
277
|
// Check for non-success response
|
|
173
|
-
if (enclaveQuotes
|
|
174
|
-
throw enclaveQuotes
|
|
278
|
+
if (isUnexpected(enclaveQuotes)) {
|
|
279
|
+
throw enclaveQuotes;
|
|
175
280
|
}
|
|
176
281
|
|
|
177
282
|
// Log all the enclave quotes' nodeId
|
|
@@ -180,49 +285,13 @@ Object.keys(enclaveQuotes.body.enclaveQuotes).forEach((key) => {
|
|
|
180
285
|
});
|
|
181
286
|
```
|
|
182
287
|
|
|
183
|
-
### Full Example
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
import ConfidentialLedger, { getLedgerIdentity } from "@azure-rest/confidential-ledger";
|
|
187
|
-
import { DefaultAzureCredential } from "@azure/identity";
|
|
188
|
-
|
|
189
|
-
export async function main() {
|
|
190
|
-
// Get the signing certificate from the Confidential Ledger Identity Service
|
|
191
|
-
const ledgerIdentity = await getLedgerIdentity("<my-ledger-id>");
|
|
192
|
-
|
|
193
|
-
// Create the Confidential Ledger Client
|
|
194
|
-
const confidentialLedger = ConfidentialLedger(
|
|
195
|
-
"https://<ledger-name>.eastus.cloudapp.azure.com",
|
|
196
|
-
ledgerIdentity.ledgerIdentityCertificate,
|
|
197
|
-
new DefaultAzureCredential(),
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
// Get enclave quotes
|
|
201
|
-
const enclaveQuotes = await confidentialLedger.path("/app/enclaveQuotes").get();
|
|
202
|
-
|
|
203
|
-
// Check for non-success response
|
|
204
|
-
if (enclaveQuotes.status !== "200") {
|
|
205
|
-
throw enclaveQuotes.body.error;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Log all the enclave quotes' nodeId
|
|
209
|
-
Object.keys(enclaveQuotes.body.enclaveQuotes).forEach((key) => {
|
|
210
|
-
console.log(enclaveQuotes.body.enclaveQuotes[key].nodeId);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
main().catch((err) => {
|
|
215
|
-
console.error(err);
|
|
216
|
-
});
|
|
217
|
-
```
|
|
218
|
-
|
|
219
288
|
## Troubleshooting
|
|
220
289
|
|
|
221
290
|
### Logging
|
|
222
291
|
|
|
223
292
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
224
293
|
|
|
225
|
-
```
|
|
294
|
+
```ts snippet:SetLogLevel
|
|
226
295
|
import { setLogLevel } from "@azure/logger";
|
|
227
296
|
|
|
228
297
|
setLogLevel("info");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"sdk-type": "client",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "An isomorphic rest level client library for the Azure Confidential Ledger service.",
|
|
6
|
-
"version": "1.1.2-alpha.
|
|
6
|
+
"version": "1.1.2-alpha.20250124.1",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"node",
|
|
9
9
|
"azure",
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
"unit-test": "npm run unit-test:node",
|
|
74
74
|
"unit-test:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
75
75
|
"unit-test:node": "dev-tool run test:vitest",
|
|
76
|
-
"update-snippets": "
|
|
76
|
+
"update-snippets": "dev-tool run update-snippets"
|
|
77
77
|
},
|
|
78
78
|
"sideEffects": false,
|
|
79
79
|
"autoPublish": false,
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@azure-rest/core-client": "^2.3.1",
|
|
82
82
|
"@azure/core-auth": "^1.9.0",
|
|
83
|
-
"@azure/core-rest-pipeline": "^1.18.
|
|
83
|
+
"@azure/core-rest-pipeline": "^1.18.2",
|
|
84
84
|
"@azure/logger": "^1.1.4",
|
|
85
85
|
"tslib": "^2.8.1"
|
|
86
86
|
},
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
|
|
93
93
|
"@azure/identity": "^4.5.0",
|
|
94
94
|
"@types/node": "^18.0.0",
|
|
95
|
-
"@vitest/coverage-istanbul": "^
|
|
95
|
+
"@vitest/coverage-istanbul": "^3.0.3",
|
|
96
96
|
"dotenv": "^16.0.0",
|
|
97
97
|
"eslint": "^9.9.0",
|
|
98
98
|
"typescript": "~5.7.2",
|
|
99
|
-
"vitest": "^
|
|
99
|
+
"vitest": "^3.0.3"
|
|
100
100
|
},
|
|
101
101
|
"type": "module",
|
|
102
102
|
"tshy": {
|