Skip to content

Commit e156c18

Browse files
thephezclaude
authored andcommitted
fix(sdk): fix generate docs (#2730)
Co-authored-by: Claude <[email protected]>
1 parent be2325f commit e156c18

File tree

6 files changed

+186
-50
lines changed

6 files changed

+186
-50
lines changed

packages/wasm-sdk/AI_REFERENCE.md

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -757,29 +757,61 @@ const result = await sdk.{transition_name}(identityHex, ...params, privateKeyHex
757757
**Identity Create** - `identityCreate`
758758
*Create a new identity with initial credits*
759759

760-
Parameters (in addition to identity/key):
761-
- `seedPhrase` (textarea, required) - Seed Phrase
762-
- Example: `Enter seed phrase (12-24 words) or click Generate`
763-
- `generateSeedButton` (button, optional) - Generate New Seed
764-
- `identityIndex` (number, required) - Identity Index
765-
- `keySelectionMode` (select, required) - Key Selection Mode
766-
- `keyPreview` (keyPreview, optional) - Keys to be added
760+
Parameters:
761+
- `assetLockProof` (string, required) - Asset Lock Proof
762+
- Hex-encoded JSON asset lock proof
763+
- `assetLockProofPrivateKey` (string, required) - Asset Lock Proof Private Key
764+
- WIF format private key
765+
- `publicKeys` (string, required) - Public Keys
766+
- JSON array of public keys
767+
768+
Example:
769+
```javascript
770+
// Asset lock proof is a hex-encoded JSON object
771+
const assetLockProof = "a9147d3b... (hex-encoded)";
772+
const assetLockProofPrivateKey = "XFfpaSbZq52HPy3WWwe1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1"; // WIF format
773+
774+
// Public keys array with proper key types
775+
const publicKeys = JSON.stringify([
776+
{
777+
id: 0,
778+
type: 0, // ECDSA_SECP256K1 = 0, BLS12_381 = 1, ECDSA_HASH160 = 2
779+
purpose: 0, // AUTHENTICATION = 0, ENCRYPTION = 1, DECRYPTION = 2, TRANSFER = 3, etc.
780+
securityLevel: 0, // MASTER = 0, CRITICAL = 1, HIGH = 2, MEDIUM = 3
781+
data: "A5GzYHPIolbHkFrp5l+s9IvF2lWMuuuSu3oWZB8vWHNJ", // Base64-encoded public key
782+
readOnly: false
783+
},
784+
{
785+
id: 1,
786+
type: 0,
787+
purpose: 0,
788+
securityLevel: 2,
789+
data: "AnotherBase64EncodedPublicKeyHere", // Base64-encoded public key
790+
readOnly: false
791+
}
792+
]);
767793

768-
Example:
769-
```javascript
770-
const result = await sdk.identityCreate(identityHex, /* params */, privateKeyHex);
794+
const result = await sdk.identityCreate(assetLockProof, assetLockProofPrivateKey, publicKeys);
771795
```
772796

773797
**Identity Top Up** - `identityTopUp`
774798
*Add credits to an existing identity*
775799

776-
Parameters (in addition to identity/key):
777-
- `identityId` (text, required) - Identity ID
778-
- Example: `Enter the identity ID to top up (base58)`
800+
Parameters:
801+
- `identityId` (string, required) - Identity ID
802+
- Base58 format identity ID
803+
- `assetLockProof` (string, required) - Asset Lock Proof
804+
- Hex-encoded JSON asset lock proof
805+
- `assetLockProofPrivateKey` (string, required) - Asset Lock Proof Private Key
806+
- WIF format private key
779807

780808
Example:
781809
```javascript
782-
const result = await sdk.identityTopUp(identityHex, /* params */, privateKeyHex);
810+
const identityId = "5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk"; // base58
811+
const assetLockProof = "a9147d3b... (hex-encoded)";
812+
const assetLockProofPrivateKey = "XFfpaSbZq52HPy3WWve1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1"; // WIF format
813+
814+
const result = await sdk.identityTopUp(identityId, assetLockProof, assetLockProofPrivateKey);
783815
```
784816

785817
**Identity Update** - `identityUpdate`

packages/wasm-sdk/api-definitions.json

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,31 @@
12351235
"label": "Keys to be added",
12361236
"help": "These keys will be added to your new identity"
12371237
}
1238-
]
1238+
],
1239+
"sdk_params": [
1240+
{
1241+
"name": "assetLockProof",
1242+
"type": "string",
1243+
"label": "Asset Lock Proof",
1244+
"required": true,
1245+
"description": "Hex-encoded JSON asset lock proof"
1246+
},
1247+
{
1248+
"name": "assetLockProofPrivateKey",
1249+
"type": "string",
1250+
"label": "Asset Lock Proof Private Key",
1251+
"required": true,
1252+
"description": "WIF format private key"
1253+
},
1254+
{
1255+
"name": "publicKeys",
1256+
"type": "string",
1257+
"label": "Public Keys",
1258+
"required": true,
1259+
"description": "JSON array of public keys"
1260+
}
1261+
],
1262+
"sdk_example": "// Asset lock proof is a hex-encoded JSON object\nconst assetLockProof = \"a9147d3b... (hex-encoded)\";\nconst assetLockProofPrivateKey = \"XFfpaSbZq52HPy3WWwe1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1\"; // WIF format\n\n// Public keys array with proper key types\nconst publicKeys = JSON.stringify([\n {\n id: 0,\n type: 0, // ECDSA_SECP256K1 = 0, BLS12_381 = 1, ECDSA_HASH160 = 2\n purpose: 0, // AUTHENTICATION = 0, ENCRYPTION = 1, DECRYPTION = 2, TRANSFER = 3, etc.\n securityLevel: 0, // MASTER = 0, CRITICAL = 1, HIGH = 2, MEDIUM = 3\n data: \"A5GzYHPIolbHkFrp5l+s9IvF2lWMuuuSu3oWZB8vWHNJ\", // Base64-encoded public key\n readOnly: false\n },\n {\n id: 1,\n type: 0,\n purpose: 0,\n securityLevel: 2,\n data: \"AnotherBase64EncodedPublicKeyHere\", // Base64-encoded public key\n readOnly: false\n }\n]);\n\nconst result = await sdk.identityCreate(assetLockProof, assetLockProofPrivateKey, publicKeys);"
12391263
},
12401264
"identityTopUp": {
12411265
"label": "Identity Top Up",
@@ -1249,7 +1273,31 @@
12491273
"placeholder": "Enter the identity ID to top up (base58)",
12501274
"help": "The identity ID that will receive the credits from the asset lock proof"
12511275
}
1252-
]
1276+
],
1277+
"sdk_params": [
1278+
{
1279+
"name": "identityId",
1280+
"type": "string",
1281+
"label": "Identity ID",
1282+
"required": true,
1283+
"description": "Base58 format identity ID"
1284+
},
1285+
{
1286+
"name": "assetLockProof",
1287+
"type": "string",
1288+
"label": "Asset Lock Proof",
1289+
"required": true,
1290+
"description": "Hex-encoded JSON asset lock proof"
1291+
},
1292+
{
1293+
"name": "assetLockProofPrivateKey",
1294+
"type": "string",
1295+
"label": "Asset Lock Proof Private Key",
1296+
"required": true,
1297+
"description": "WIF format private key"
1298+
}
1299+
],
1300+
"sdk_example": "const identityId = \"5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk\"; // base58\nconst assetLockProof = \"a9147d3b... (hex-encoded)\";\nconst assetLockProofPrivateKey = \"XFfpaSbZq52HPy3WWve1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1\"; // WIF format\n\nconst result = await sdk.identityTopUp(identityId, assetLockProof, assetLockProofPrivateKey);"
12531301
},
12541302
"identityUpdate": {
12551303
"label": "Identity Update",

packages/wasm-sdk/docs.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ h3 {
270270
font-size: 0.9em;
271271
margin-bottom: 10px;
272272
position: relative;
273+
white-space: pre-wrap;
274+
overflow-x: auto;
273275
}
274276

275277
.run-button {

packages/wasm-sdk/docs.html

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,37 +1952,52 @@ <h4 id="transition-identityCreate">Identity Create</h4>
19521952
<div class="parameters">
19531953
<h5>Parameters:</h5>
19541954
<div class="parameter">
1955-
<span class="param-name">Seed Phrase</span>
1956-
<span class="param-type">textarea</span>
1955+
<span class="param-name">Asset Lock Proof</span>
1956+
<span class="param-type">string</span>
19571957
<span class="param-required">(required)</span>
1958-
<br><small>Example: Enter seed phrase (12-24 words) or click Generate</small>
1959-
</div>
1960-
<div class="parameter">
1961-
<span class="param-name">Generate New Seed</span>
1962-
<span class="param-type">button</span>
1963-
<span class="param-optional">(optional)</span>
1958+
<br><small>Hex-encoded JSON asset lock proof</small>
19641959
</div>
19651960
<div class="parameter">
1966-
<span class="param-name">Identity Index</span>
1967-
<span class="param-type">number</span>
1961+
<span class="param-name">Asset Lock Proof Private Key</span>
1962+
<span class="param-type">string</span>
19681963
<span class="param-required">(required)</span>
1964+
<br><small>WIF format private key</small>
19691965
</div>
19701966
<div class="parameter">
1971-
<span class="param-name">Key Selection Mode</span>
1972-
<span class="param-type">select</span>
1967+
<span class="param-name">Public Keys</span>
1968+
<span class="param-type">string</span>
19731969
<span class="param-required">(required)</span>
1974-
<br><small>Options: Default (Recommended), Advanced</small>
1975-
</div>
1976-
<div class="parameter">
1977-
<span class="param-name">Keys to be added</span>
1978-
<span class="param-type">keyPreview</span>
1979-
<span class="param-optional">(optional)</span>
1970+
<br><small>JSON array of public keys</small>
19801971
</div>
19811972
</div>
19821973

19831974
<div class="example-container">
19841975
<h5>Example</h5>
1985-
<div class="example-code">const result = await sdk.identityCreate(identityHex, /* params */, privateKeyHex);</div> </div>
1976+
<div class="example-code">// Asset lock proof is a hex-encoded JSON object
1977+
const assetLockProof = "a9147d3b... (hex-encoded)";
1978+
const assetLockProofPrivateKey = "XFfpaSbZq52HPy3WWwe1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1"; // WIF format
1979+
1980+
// Public keys array with proper key types
1981+
const publicKeys = JSON.stringify([
1982+
{
1983+
id: 0,
1984+
type: 0, // ECDSA_SECP256K1 = 0, BLS12_381 = 1, ECDSA_HASH160 = 2
1985+
purpose: 0, // AUTHENTICATION = 0, ENCRYPTION = 1, DECRYPTION = 2, TRANSFER = 3, etc.
1986+
securityLevel: 0, // MASTER = 0, CRITICAL = 1, HIGH = 2, MEDIUM = 3
1987+
data: "A5GzYHPIolbHkFrp5l+s9IvF2lWMuuuSu3oWZB8vWHNJ", // Base64-encoded public key
1988+
readOnly: false
1989+
},
1990+
{
1991+
id: 1,
1992+
type: 0,
1993+
purpose: 0,
1994+
securityLevel: 2,
1995+
data: "AnotherBase64EncodedPublicKeyHere", // Base64-encoded public key
1996+
readOnly: false
1997+
}
1998+
]);
1999+
2000+
const result = await sdk.identityCreate(assetLockProof, assetLockProofPrivateKey, publicKeys);</div> </div>
19862001
</div>
19872002
<div class="operation">
19882003
<h4 id="transition-identityTopUp">Identity Top Up</h4>
@@ -1992,15 +2007,31 @@ <h4 id="transition-identityTopUp">Identity Top Up</h4>
19922007
<h5>Parameters:</h5>
19932008
<div class="parameter">
19942009
<span class="param-name">Identity ID</span>
1995-
<span class="param-type">text</span>
2010+
<span class="param-type">string</span>
2011+
<span class="param-required">(required)</span>
2012+
<br><small>Base58 format identity ID</small>
2013+
</div>
2014+
<div class="parameter">
2015+
<span class="param-name">Asset Lock Proof</span>
2016+
<span class="param-type">string</span>
19962017
<span class="param-required">(required)</span>
1997-
<br><small>Example: Enter the identity ID to top up (base58)</small>
2018+
<br><small>Hex-encoded JSON asset lock proof</small>
2019+
</div>
2020+
<div class="parameter">
2021+
<span class="param-name">Asset Lock Proof Private Key</span>
2022+
<span class="param-type">string</span>
2023+
<span class="param-required">(required)</span>
2024+
<br><small>WIF format private key</small>
19982025
</div>
19992026
</div>
20002027

20012028
<div class="example-container">
20022029
<h5>Example</h5>
2003-
<div class="example-code">const result = await sdk.identityTopUp(identityHex, /* params */, privateKeyHex);</div> </div>
2030+
<div class="example-code">const identityId = "5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk"; // base58
2031+
const assetLockProof = "a9147d3b... (hex-encoded)";
2032+
const assetLockProofPrivateKey = "XFfpaSbZq52HPy3WWve1dXsZMiU1bQn8vQd34HNXkSZThevBWRn1"; // WIF format
2033+
2034+
const result = await sdk.identityTopUp(identityId, assetLockProof, assetLockProofPrivateKey);</div> </div>
20042035
</div>
20052036
<div class="operation">
20062037
<h4 id="transition-identityUpdate">Identity Update</h4>

packages/wasm-sdk/docs_manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"generated_at": "2025-08-18T16:09:12.996174+00:00",
2+
"generated_at": "2025-08-18T19:21:21.062910+00:00",
33
"queries": {
44
"getIdentity": {
55
"category": "identity",

packages/wasm-sdk/generate_docs.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,15 @@ def generate_operation_entry(operation_key, operation, type_prefix):
245245
<h5>Parameters:</h5>
246246
'''
247247

248+
# Use sdk_params if available (for state transitions), otherwise use inputs
249+
sdk_params = operation.get('sdk_params', [])
248250
inputs = operation.get('inputs', [])
249-
if not inputs:
251+
params_to_use = sdk_params if sdk_params else inputs
252+
253+
if not params_to_use:
250254
html_content += ' <p class="param-optional">No parameters required</p>'
251255
else:
252-
for param in inputs:
256+
for param in params_to_use:
253257
html_content += generate_parameter_entry(param)
254258

255259
html_content += ''' </div>
@@ -297,7 +301,7 @@ def generate_operation_entry(operation_key, operation, type_prefix):
297301
html_content += f'\n <div class="example-result" id="result-{operation_key}"></div>'
298302
else:
299303
# State transitions don't have run buttons
300-
html_content += f' <div class="example-code">{generate_transition_example(operation_key)}</div>'
304+
html_content += f' <div class="example-code">{generate_transition_example(operation_key, operation)}</div>'
301305

302306
html_content += ''' </div>
303307
</div>
@@ -312,7 +316,9 @@ def generate_parameter_entry(param):
312316
<span class="param-type">{param.get('type', 'text')}</span>
313317
{required_text}
314318
'''
315-
if param.get('placeholder'):
319+
if param.get('description'):
320+
html_content += f' <br><small>{html_lib.escape(param.get("description"))}</small>\n'
321+
elif param.get('placeholder'):
316322
html_content += f' <br><small>Example: {html_lib.escape(param.get("placeholder"))}</small>\n'
317323
elif param.get('name') == 'limit' and not param.get('required', False):
318324
html_content += ' <br><small>Default: 100 (maximum items returned if not specified)</small>\n'
@@ -324,8 +330,12 @@ def generate_parameter_entry(param):
324330
html_content += ' </div>\n'
325331
return html_content
326332

327-
def generate_transition_example(trans_key):
333+
def generate_transition_example(trans_key, transition=None):
328334
"""Generate example code for state transitions"""
335+
# Check if there's a custom sdk_example
336+
if transition and transition.get('sdk_example'):
337+
return transition.get('sdk_example')
338+
329339
if trans_key == 'documentCreate':
330340
return '''const result = await sdk.document_create(
331341
identityHex,
@@ -1670,27 +1680,40 @@ def generate_ai_reference_md(query_defs, transition_defs):
16701680
md_content += f"\n**{transition.get('label', trans_key)}** - `{trans_key}`\n"
16711681
md_content += f"*{transition.get('description', 'No description')}*\n\n"
16721682

1673-
# Parameters
1683+
# Parameters - use sdk_params if available, otherwise fall back to inputs
1684+
sdk_params = transition.get('sdk_params', [])
16741685
inputs = transition.get('inputs', [])
1675-
if inputs:
1686+
params_to_use = sdk_params if sdk_params else inputs
1687+
1688+
# Adjust parameter section header based on whether we're using SDK params
1689+
if sdk_params:
1690+
md_content += "Parameters:\n"
1691+
elif inputs:
16761692
md_content += "Parameters (in addition to identity/key):\n"
1677-
for param in inputs:
1693+
1694+
if params_to_use:
1695+
for param in params_to_use:
16781696
req = "required" if param.get('required', False) else "optional"
16791697
md_content += f"- `{param.get('name', 'unknown')}` ({param.get('type', 'text')}, {req})"
16801698

16811699
if param.get('label') and param.get('label') != param.get('name'):
16821700
md_content += f" - {param.get('label')}"
16831701

1684-
if param.get('placeholder'):
1702+
if param.get('description'):
1703+
md_content += f"\n - {param.get('description')}"
1704+
elif param.get('placeholder'):
16851705
md_content += f"\n - Example: `{param.get('placeholder')}`"
16861706

16871707
md_content += "\n"
16881708

16891709
# Example
16901710
md_content += f"\nExample:\n```javascript\n"
16911711

1692-
# Generate specific examples
1693-
if trans_key == 'documentCreate':
1712+
# Check if there's a custom sdk_example
1713+
sdk_example = transition.get('sdk_example')
1714+
if sdk_example:
1715+
md_content += sdk_example
1716+
elif trans_key == 'documentCreate':
16941717
md_content += '''const result = await sdk.document_create(
16951718
identityHex,
16961719
contractId,

0 commit comments

Comments
 (0)