@smartledger/bsv 3.4.3 ā 3.4.4
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/CHANGELOG.md +321 -0
- package/README.md +72 -72
- package/SECURITY.md +88 -0
- package/bin/cli.js +13 -8
- package/bsv-covenant.min.js +4 -4
- package/bsv-gdaf.min.js +5 -5
- package/bsv-ltp.min.js +7 -7
- package/bsv-smartcontract.min.js +5 -5
- package/bsv.bundle.js +5 -5
- package/bsv.d.ts +486 -9
- package/bsv.min.js +5 -5
- package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
- package/docs/MODULE_REFERENCE_COMPLETE.md +60 -57
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +30 -30
- package/docs/getting-started/QUICK_START.md +14 -14
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/gdaf-entry.js +1 -2
- package/index.js +20 -7
- package/lib/smart_contract/covenant.js +10 -1
- package/lib/smartutxo.js +20 -12
- package/lib/transaction/transaction.js +7 -0
- package/ltp-entry.js +1 -2
- package/package.json +3 -3
- package/utilities/blockchain-state.js +32 -23
- package/demos/README.md +0 -188
- package/demos/architecture_demo.js +0 -247
- package/demos/browser-test.html +0 -1208
- package/demos/bsv_wallet_demo.js +0 -242
- package/demos/complete_ltp_demo.js +0 -511
- package/demos/debug_tools_demo.js +0 -87
- package/demos/demo_features.js +0 -123
- package/demos/easy_interface_demo.js +0 -109
- package/demos/ecies_demo.js +0 -182
- package/demos/gdaf_demo.js +0 -237
- package/demos/ltp_demo.js +0 -361
- package/demos/ltp_primitives_demo.js +0 -403
- package/demos/message_demo.js +0 -209
- package/demos/preimage_separation_demo.js +0 -383
- package/demos/script_helper_demo.js +0 -289
- package/demos/security_demo.js +0 -287
- package/demos/shamir_demo.js +0 -121
- package/demos/simple_demo.js +0 -204
- package/demos/simple_p2pkh_demo.js +0 -169
- package/demos/simple_utxo_preimage_demo.js +0 -196
- package/demos/smart_contract_demo.html +0 -1347
- package/demos/smart_contract_demo.js +0 -910
- package/demos/utxo_generator_demo.js +0 -244
- package/demos/validation_pipeline_demo.js +0 -155
- package/demos/web3keys.html +0 -740
- package/examples/README.md +0 -200
- package/examples/basic/transaction-creation.js +0 -534
- package/examples/basic/transaction_signature_api_gap.js +0 -178
- package/examples/complete_workflow_demo.js +0 -783
- package/examples/covenants/advanced_covenant_demo.js +0 -219
- package/examples/covenants/covenant_interface_demo.js +0 -270
- package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
- package/examples/covenants/covenant_signature_template.js +0 -117
- package/examples/covenants2/covenant_bidirectional_example.js +0 -262
- package/examples/covenants2/covenant_utils_demo.js +0 -120
- package/examples/covenants2/preimage_covenant_utils.js +0 -287
- package/examples/covenants2/production_integration.js +0 -256
- package/examples/data/covenant_utxos.json +0 -28
- package/examples/data/utxos.json +0 -26
- package/examples/definitive_working_demo.js +0 -261
- package/examples/final_working_contracts.js +0 -338
- package/examples/legacy/README.md +0 -11
- package/examples/legacy/smart_contract_test_integration.js +0 -269
- package/examples/legacy/test_builtin_verify.js +0 -117
- package/examples/legacy/test_debug_integration.js +0 -71
- package/examples/legacy/test_ecdsa_little.js +0 -70
- package/examples/legacy/test_shamir.js +0 -221
- package/examples/legacy/test_smartverify_der.js +0 -110
- package/examples/preimage/README.md +0 -178
- package/examples/preimage/extract_preimage_bidirectional.js +0 -421
- package/examples/preimage/generate_sample_preimage.js +0 -208
- package/examples/preimage/generate_sighash_examples.js +0 -152
- package/examples/preimage/parse_preimage.js +0 -117
- package/examples/preimage/test_preimage_extractor.js +0 -53
- package/examples/preimage/test_varint_extraction.js +0 -95
- package/examples/scripts/custom_script_helper_example.js +0 -273
- package/examples/scripts/script_interpreter.js +0 -193
- package/examples/smart_contract/complete_workflow_demo.js +0 -343
- package/examples/smart_contract/covenant_builder_demo.js +0 -176
- package/examples/smart_contract/script_testing_integration.js +0 -198
- package/examples/smart_contract_templates.js +0 -718
- package/examples/working_smart_contracts.js +0 -348
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SmartLedger-BSV LTP: Complete Working Example with Keys, UTXOs & Covenants
|
|
3
|
-
*
|
|
4
|
-
* This demonstrates the Legal Token Protocol primitives using:
|
|
5
|
-
* - Real BSV private keys and addresses
|
|
6
|
-
* - Mock UTXO generation for testing
|
|
7
|
-
* - Smart contract covenants for advanced functionality
|
|
8
|
-
* - Complete end-to-end LTP workflow
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const bsv = require('../index.js')
|
|
12
|
-
const crypto = require('crypto')
|
|
13
|
-
|
|
14
|
-
console.log('š SmartLedger-BSV LTP: Complete Working Example')
|
|
15
|
-
console.log('================================================\n')
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* UTILITY FUNCTIONS
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// Mock UTXO creator (from utilities)
|
|
22
|
-
function createMockUTXO(privateKey, satoshis = 100000) {
|
|
23
|
-
const address = privateKey.toAddress().toString()
|
|
24
|
-
const txid = crypto.randomBytes(32).toString('hex')
|
|
25
|
-
const vout = 0
|
|
26
|
-
const scriptHex = bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
txId: txid,
|
|
30
|
-
txid: txid,
|
|
31
|
-
vout: vout,
|
|
32
|
-
outputIndex: vout,
|
|
33
|
-
satoshis: satoshis,
|
|
34
|
-
value: satoshis,
|
|
35
|
-
script: scriptHex,
|
|
36
|
-
scriptPubKey: scriptHex,
|
|
37
|
-
address: address
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Create covenant script for legal token enforcement
|
|
42
|
-
function createLegalTokenCovenant(tokenData, publicKey) {
|
|
43
|
-
// Create a simple P2PKH script with token data embedded
|
|
44
|
-
const tokenHash = bsv.crypto.Hash.sha256(Buffer.from(JSON.stringify(tokenData)))
|
|
45
|
-
|
|
46
|
-
// Use standard P2PKH script
|
|
47
|
-
const script = bsv.Script.buildPublicKeyHashOut(publicKey.toAddress())
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
script: script,
|
|
51
|
-
tokenHash: tokenHash,
|
|
52
|
-
enforcement: 'P2PKH with embedded token validation'
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log('š STEP 1: Generate Keys and Identities')
|
|
57
|
-
console.log('=======================================')
|
|
58
|
-
|
|
59
|
-
// Generate real BSV keys for all participants
|
|
60
|
-
const issuerPrivateKey = new bsv.PrivateKey()
|
|
61
|
-
const ownerPrivateKey = new bsv.PrivateKey()
|
|
62
|
-
const obligorPrivateKey = new bsv.PrivateKey()
|
|
63
|
-
const registrarPrivateKey = new bsv.PrivateKey()
|
|
64
|
-
|
|
65
|
-
// Create DIDs from public keys
|
|
66
|
-
const issuerDID = `did:bsv:${issuerPrivateKey.publicKey.toString()}`
|
|
67
|
-
const ownerDID = `did:bsv:${ownerPrivateKey.publicKey.toString()}`
|
|
68
|
-
const obligorDID = `did:bsv:${obligorPrivateKey.publicKey.toString()}`
|
|
69
|
-
const registrarDID = `did:bsv:${registrarPrivateKey.publicKey.toString()}`
|
|
70
|
-
|
|
71
|
-
console.log('š„ Participants created:')
|
|
72
|
-
console.log(` šļø Issuer: ${issuerPrivateKey.toAddress()}`)
|
|
73
|
-
console.log(` DID: ${issuerDID}`)
|
|
74
|
-
console.log(` WIF: ${issuerPrivateKey.toWIF()}`)
|
|
75
|
-
console.log('')
|
|
76
|
-
console.log(` š Owner: ${ownerPrivateKey.toAddress()}`)
|
|
77
|
-
console.log(` DID: ${ownerDID}`)
|
|
78
|
-
console.log(` WIF: ${ownerPrivateKey.toWIF()}`)
|
|
79
|
-
console.log('')
|
|
80
|
-
console.log(` š° Obligor: ${obligorPrivateKey.toAddress()}`)
|
|
81
|
-
console.log(` DID: ${obligorDID}`)
|
|
82
|
-
console.log(` WIF: ${obligorPrivateKey.toWIF()}`)
|
|
83
|
-
console.log('')
|
|
84
|
-
|
|
85
|
-
console.log('š° STEP 2: Create Mock UTXOs for Funding')
|
|
86
|
-
console.log('========================================')
|
|
87
|
-
|
|
88
|
-
// Create UTXOs for each participant
|
|
89
|
-
const issuerUTXO = createMockUTXO(issuerPrivateKey, 1000000) // 0.01 BSV
|
|
90
|
-
const ownerUTXO = createMockUTXO(ownerPrivateKey, 500000) // 0.005 BSV
|
|
91
|
-
const obligorUTXO = createMockUTXO(obligorPrivateKey, 750000) // 0.0075 BSV
|
|
92
|
-
|
|
93
|
-
console.log('š³ Mock UTXOs created:')
|
|
94
|
-
console.log(` šļø Issuer UTXO: ${issuerUTXO.satoshis} sats (${issuerUTXO.txid.substring(0, 16)}...)`)
|
|
95
|
-
console.log(` š Owner UTXO: ${ownerUTXO.satoshis} sats (${ownerUTXO.txid.substring(0, 16)}...)`)
|
|
96
|
-
console.log(` š° Obligor UTXO: ${obligorUTXO.satoshis} sats (${obligorUTXO.txid.substring(0, 16)}...)`)
|
|
97
|
-
console.log('')
|
|
98
|
-
|
|
99
|
-
console.log('š STEP 3: Prepare Legal Claim')
|
|
100
|
-
console.log('==============================')
|
|
101
|
-
|
|
102
|
-
// Create a property title claim using available schema
|
|
103
|
-
const propertyClaimData = {
|
|
104
|
-
type: 'PropertyTitle',
|
|
105
|
-
property: {
|
|
106
|
-
address: '123 Bitcoin Boulevard, Satoshi City, BSV 12345',
|
|
107
|
-
parcel_id: 'BSV-2024-DEMO-001',
|
|
108
|
-
property_type: 'residential',
|
|
109
|
-
square_footage: 2500,
|
|
110
|
-
lot_size: 7500,
|
|
111
|
-
year_built: 2020
|
|
112
|
-
},
|
|
113
|
-
owner: ownerDID,
|
|
114
|
-
title_number: 'TIT-2024-BSV-001',
|
|
115
|
-
deed_reference: 'DEED-BSV-2024-DEMO',
|
|
116
|
-
acquisition_date: '2024-01-15',
|
|
117
|
-
market_value: 850000,
|
|
118
|
-
liens: [],
|
|
119
|
-
restrictions: ['HOA Covenant', 'Environmental Protection Zone']
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Use LTP primitives to validate and prepare claim
|
|
123
|
-
console.log('š Property claim data prepared:')
|
|
124
|
-
console.log(` š Property: ${propertyClaimData.property.address}`)
|
|
125
|
-
console.log(` š Value: $${propertyClaimData.market_value.toLocaleString()}`)
|
|
126
|
-
console.log(` š Title #: ${propertyClaimData.title_number}`)
|
|
127
|
-
|
|
128
|
-
// Generate claim hash using LTP utility
|
|
129
|
-
const claimHash = bsv.hashClaim(propertyClaimData)
|
|
130
|
-
const canonicalClaim = bsv.canonicalizeClaim(propertyClaimData)
|
|
131
|
-
|
|
132
|
-
console.log(` š Claim Hash: ${claimHash}`)
|
|
133
|
-
console.log(` š Canonical Size: ${canonicalClaim.length} bytes`)
|
|
134
|
-
console.log('')
|
|
135
|
-
|
|
136
|
-
console.log('šļø STEP 4: Prepare Right Token using LTP Primitives')
|
|
137
|
-
console.log('==================================================')
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
// Use new primitives-only approach
|
|
141
|
-
const rightTokenPrep = bsv.prepareRightToken(
|
|
142
|
-
'PROPERTY_OWNERSHIP',
|
|
143
|
-
issuerDID,
|
|
144
|
-
ownerDID,
|
|
145
|
-
propertyClaimData,
|
|
146
|
-
issuerPrivateKey,
|
|
147
|
-
{
|
|
148
|
-
jurisdiction: 'satoshi_city_bsv',
|
|
149
|
-
validUntil: '2034-01-15',
|
|
150
|
-
transferable: true,
|
|
151
|
-
divisible: false,
|
|
152
|
-
covenant_enforcement: true,
|
|
153
|
-
market_value: propertyClaimData.market_value
|
|
154
|
-
}
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
console.log('š Property ownership right token prepared:')
|
|
158
|
-
console.log(` š Token ID: ${rightTokenPrep.tokenId}`)
|
|
159
|
-
console.log(` āļø Right Type: ${rightTokenPrep.rightType}`)
|
|
160
|
-
console.log(` š¤ Subject: ${rightTokenPrep.subjectDID}`)
|
|
161
|
-
console.log(` šļø Valid Until: ${rightTokenPrep.validUntil}`)
|
|
162
|
-
console.log(` š± Transferable: ${rightTokenPrep.transferable ? 'YES' : 'NO'}`)
|
|
163
|
-
console.log(` āļø Covenant Enforcement: ${rightTokenPrep.covenantEnforcement ? 'ENABLED' : 'DISABLED'}`)
|
|
164
|
-
|
|
165
|
-
// Prepare verification
|
|
166
|
-
const rightVerification = bsv.prepareRightTokenVerification(rightTokenPrep.token)
|
|
167
|
-
console.log(` ā
Verification Status: ${rightVerification.isValid ? 'VALID' : 'INVALID'}`)
|
|
168
|
-
|
|
169
|
-
if (rightVerification.isValid) {
|
|
170
|
-
console.log(` š Signature Valid: YES`)
|
|
171
|
-
console.log(` š Structure Valid: YES`)
|
|
172
|
-
console.log(` ā° Time Valid: YES`)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.log('ā ļø Right token preparation using mock structure (module integration pending)')
|
|
177
|
-
|
|
178
|
-
// Mock the token structure for demonstration
|
|
179
|
-
var rightTokenPrep = {
|
|
180
|
-
tokenId: `RT-${crypto.randomBytes(16).toString('hex')}`,
|
|
181
|
-
rightType: 'PROPERTY_OWNERSHIP',
|
|
182
|
-
subjectDID: ownerDID,
|
|
183
|
-
issuerDID: issuerDID,
|
|
184
|
-
validUntil: '2034-01-15',
|
|
185
|
-
transferable: true,
|
|
186
|
-
covenantEnforcement: true,
|
|
187
|
-
token: {
|
|
188
|
-
id: `RT-${crypto.randomBytes(16).toString('hex')}`,
|
|
189
|
-
type: 'PROPERTY_OWNERSHIP',
|
|
190
|
-
claim: propertyClaimData,
|
|
191
|
-
signature: crypto.randomBytes(64).toString('hex')
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
console.log(` š Token ID: ${rightTokenPrep.tokenId}`)
|
|
196
|
-
console.log(` āļø Right Type: ${rightTokenPrep.rightType}`)
|
|
197
|
-
console.log(` š¤ Subject: ${rightTokenPrep.subjectDID}`)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
console.log('')
|
|
201
|
-
|
|
202
|
-
console.log('š° STEP 5: Create Smart Contract Covenant for Token')
|
|
203
|
-
console.log('=================================================')
|
|
204
|
-
|
|
205
|
-
// Create covenant script that enforces legal token rules
|
|
206
|
-
const covenantInfo = createLegalTokenCovenant(rightTokenPrep.token, issuerPrivateKey.publicKey)
|
|
207
|
-
const covenantAddress = issuerPrivateKey.toAddress()
|
|
208
|
-
|
|
209
|
-
console.log('āļø Smart contract covenant created:')
|
|
210
|
-
console.log(` š Covenant Address: ${covenantAddress.toString()}`)
|
|
211
|
-
console.log(` š Enforces: ${covenantInfo.enforcement}`)
|
|
212
|
-
console.log(` šÆ Purpose: Ensures token integrity during transfers`)
|
|
213
|
-
console.log(` ļæ½ Token Hash: ${covenantInfo.tokenHash.toString('hex').substring(0, 32)}...`)
|
|
214
|
-
|
|
215
|
-
// Create covenant transaction using mock UTXO
|
|
216
|
-
const covenantTx = new bsv.Transaction()
|
|
217
|
-
.from(issuerUTXO)
|
|
218
|
-
.to(covenantAddress, 10000) // Lock 10k sats in covenant
|
|
219
|
-
.addData(Buffer.from(JSON.stringify({
|
|
220
|
-
type: 'LEGAL_TOKEN_COVENANT',
|
|
221
|
-
tokenId: rightTokenPrep.tokenId,
|
|
222
|
-
tokenHash: covenantInfo.tokenHash.toString('hex'),
|
|
223
|
-
enforcement: 'active'
|
|
224
|
-
})))
|
|
225
|
-
.change(issuerPrivateKey.toAddress())
|
|
226
|
-
.sign(issuerPrivateKey)
|
|
227
|
-
|
|
228
|
-
console.log(` š³ Covenant TX: ${covenantTx.id}`)
|
|
229
|
-
console.log(` š° Locked Amount: 10,000 sats`)
|
|
230
|
-
console.log('')
|
|
231
|
-
|
|
232
|
-
console.log('āļø STEP 6: Prepare Obligation Token')
|
|
233
|
-
console.log('==================================')
|
|
234
|
-
|
|
235
|
-
// Create mortgage obligation tied to property
|
|
236
|
-
const mortgageObligationData = {
|
|
237
|
-
type: 'mortgage_payment',
|
|
238
|
-
collateral_token_id: rightTokenPrep.tokenId,
|
|
239
|
-
principal_amount: 680000, // 80% LTV
|
|
240
|
-
interest_rate: 0.0675,
|
|
241
|
-
term_months: 360,
|
|
242
|
-
payment_amount: 4417.05,
|
|
243
|
-
payment_schedule: 'monthly',
|
|
244
|
-
next_payment_date: '2024-11-15',
|
|
245
|
-
payments_remaining: 359,
|
|
246
|
-
lender: issuerDID,
|
|
247
|
-
borrower: obligorDID
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
const obligationTokenPrep = bsv.prepareObligationToken(
|
|
252
|
-
'FINANCIAL_OBLIGATION',
|
|
253
|
-
issuerDID,
|
|
254
|
-
obligorDID,
|
|
255
|
-
mortgageObligationData,
|
|
256
|
-
issuerPrivateKey,
|
|
257
|
-
{
|
|
258
|
-
priority: 'HIGH',
|
|
259
|
-
jurisdiction: 'satoshi_city_bsv',
|
|
260
|
-
enforcement_mechanism: 'collateral_seizure',
|
|
261
|
-
grace_period_days: 30,
|
|
262
|
-
covenant_address: covenantAddress.toString()
|
|
263
|
-
}
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
console.log('š³ Mortgage obligation token prepared:')
|
|
267
|
-
console.log(` š Obligation ID: ${obligationTokenPrep.tokenId}`)
|
|
268
|
-
console.log(` š° Principal: $${mortgageObligationData.principal_amount.toLocaleString()}`)
|
|
269
|
-
console.log(` š Interest Rate: ${(mortgageObligationData.interest_rate * 100).toFixed(2)}%`)
|
|
270
|
-
console.log(` šµ Monthly Payment: $${mortgageObligationData.payment_amount.toLocaleString()}`)
|
|
271
|
-
console.log(` š Collateral: ${rightTokenPrep.tokenId}`)
|
|
272
|
-
console.log(` āļø Covenant Enforcement: ${covenantAddress.toString().substring(0, 20)}...`)
|
|
273
|
-
|
|
274
|
-
} catch (error) {
|
|
275
|
-
console.log('ā ļø Obligation token preparation using mock structure')
|
|
276
|
-
|
|
277
|
-
var obligationTokenPrep = {
|
|
278
|
-
tokenId: `OB-${crypto.randomBytes(16).toString('hex')}`,
|
|
279
|
-
obligationType: 'FINANCIAL_OBLIGATION',
|
|
280
|
-
obligorDID: obligorDID,
|
|
281
|
-
priority: 'HIGH'
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
console.log(` š Obligation ID: ${obligationTokenPrep.tokenId}`)
|
|
285
|
-
console.log(` š° Principal: $${mortgageObligationData.principal_amount.toLocaleString()}`)
|
|
286
|
-
console.log(` š Interest Rate: ${(mortgageObligationData.interest_rate * 100).toFixed(2)}%`)
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
console.log('')
|
|
290
|
-
|
|
291
|
-
console.log('š STEP 7: Generate Cryptographic Proofs')
|
|
292
|
-
console.log('========================================')
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
// Prepare selective disclosure proof (hide financial details)
|
|
296
|
-
const disclosureFields = ['type', 'payment_schedule', 'next_payment_date', 'lender']
|
|
297
|
-
const selectiveDisclosure = bsv.prepareSelectiveDisclosure(
|
|
298
|
-
obligationTokenPrep.token || { data: mortgageObligationData },
|
|
299
|
-
disclosureFields,
|
|
300
|
-
'proof_nonce_2024_demo'
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
console.log('š Selective disclosure proof prepared:')
|
|
304
|
-
console.log(` šļø Revealed Fields: ${disclosureFields.join(', ')}`)
|
|
305
|
-
console.log(` š Hidden Fields: principal_amount, interest_rate, payment_amount`)
|
|
306
|
-
console.log(` š Proof Hash: ${selectiveDisclosure.proofHash || 'demo_hash'}`)
|
|
307
|
-
|
|
308
|
-
} catch (error) {
|
|
309
|
-
console.log('š Selective disclosure proof (mock):')
|
|
310
|
-
console.log(` šļø Revealed: type, payment_schedule, next_payment_date, lender`)
|
|
311
|
-
console.log(` š Hidden: principal_amount, interest_rate, payment_amount`)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Create zero-knowledge proof for property value verification
|
|
315
|
-
try {
|
|
316
|
-
const zkProof = bsv.prepareZeroKnowledgeProof(
|
|
317
|
-
rightTokenPrep.token,
|
|
318
|
-
{
|
|
319
|
-
statement: 'property_value_above_threshold',
|
|
320
|
-
threshold: 500000,
|
|
321
|
-
actual_value: propertyClaimData.market_value
|
|
322
|
-
},
|
|
323
|
-
'zk_nonce_2024_demo'
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
console.log('š§® Zero-knowledge proof prepared:')
|
|
327
|
-
console.log(` š Statement: Property value > $500,000`)
|
|
328
|
-
console.log(` ā
Result: TRUE (without revealing actual value)`)
|
|
329
|
-
console.log(` š ZK Proof: ${zkProof.proofHash || 'zk_demo_hash'}`)
|
|
330
|
-
|
|
331
|
-
} catch (error) {
|
|
332
|
-
console.log('š§® Zero-knowledge proof (mock):')
|
|
333
|
-
console.log(` š Statement: Property value > $500,000`)
|
|
334
|
-
console.log(` ā
Result: TRUE (without revealing $850,000)`)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
console.log('')
|
|
338
|
-
|
|
339
|
-
console.log('š STEP 8: Prepare Registry and Blockchain Anchoring')
|
|
340
|
-
console.log('===================================================')
|
|
341
|
-
|
|
342
|
-
try {
|
|
343
|
-
// Prepare registry for token storage
|
|
344
|
-
const registryConfig = bsv.prepareRegistry({
|
|
345
|
-
name: 'Satoshi City Property Registry',
|
|
346
|
-
jurisdiction: 'satoshi_city_bsv',
|
|
347
|
-
authority: registrarDID,
|
|
348
|
-
compliance_framework: 'GDAF_W3C_LTP',
|
|
349
|
-
storage_type: 'distributed_bsv_ledger'
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
console.log('šļø Registry configuration prepared:')
|
|
353
|
-
console.log(` š Name: ${registryConfig.name}`)
|
|
354
|
-
console.log(` āļø Authority: ${registrarDID.substring(0, 30)}...`)
|
|
355
|
-
console.log(` š Compliance: ${registryConfig.compliance_framework}`)
|
|
356
|
-
|
|
357
|
-
// Prepare token registration
|
|
358
|
-
const tokenRegistration = bsv.prepareTokenRegistration(
|
|
359
|
-
rightTokenPrep.token,
|
|
360
|
-
registryConfig,
|
|
361
|
-
{
|
|
362
|
-
category: 'property_rights',
|
|
363
|
-
public_visibility: false,
|
|
364
|
-
audit_level: 'full',
|
|
365
|
-
covenant_address: covenantAddress.toString()
|
|
366
|
-
}
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
console.log(` š Registration ID: ${tokenRegistration.registrationId || 'REG-DEMO-001'}`)
|
|
370
|
-
console.log(` š·ļø Category: ${tokenRegistration.category || 'property_rights'}`)
|
|
371
|
-
|
|
372
|
-
} catch (error) {
|
|
373
|
-
console.log('šļø Registry preparation (mock):')
|
|
374
|
-
console.log(` š Name: Satoshi City Property Registry`)
|
|
375
|
-
console.log(` āļø Authority: ${registrarDID.substring(0, 30)}...`)
|
|
376
|
-
console.log(` š Registration ID: REG-DEMO-001`)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Prepare blockchain anchoring
|
|
380
|
-
try {
|
|
381
|
-
const tokenCommitment = bsv.prepareTokenCommitment(rightTokenPrep.token, {
|
|
382
|
-
include_metadata: true,
|
|
383
|
-
merkle_proof: true,
|
|
384
|
-
commitment_type: 'sha256'
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
console.log('āļø Blockchain commitment prepared:')
|
|
388
|
-
console.log(` š Commitment Hash: ${tokenCommitment.commitmentHash || crypto.randomBytes(32).toString('hex')}`)
|
|
389
|
-
console.log(` š³ Merkle Root: ${tokenCommitment.merkleRoot || crypto.randomBytes(32).toString('hex')}`)
|
|
390
|
-
|
|
391
|
-
// Prepare batch with both tokens
|
|
392
|
-
const batchCommitment = bsv.prepareBatchCommitment(
|
|
393
|
-
[rightTokenPrep.token, { id: obligationTokenPrep.tokenId }],
|
|
394
|
-
{
|
|
395
|
-
batch_size: 2,
|
|
396
|
-
include_individual_proofs: true,
|
|
397
|
-
optimization: 'bsv_efficient'
|
|
398
|
-
}
|
|
399
|
-
)
|
|
400
|
-
|
|
401
|
-
console.log(` š¦ Batch Root: ${batchCommitment.batchRoot || crypto.randomBytes(32).toString('hex')}`)
|
|
402
|
-
console.log(` š Batch Size: 2 tokens (right + obligation)`)
|
|
403
|
-
|
|
404
|
-
} catch (error) {
|
|
405
|
-
console.log('āļø Blockchain commitment (mock):')
|
|
406
|
-
const mockCommitment = crypto.randomBytes(32).toString('hex')
|
|
407
|
-
const mockBatch = crypto.randomBytes(32).toString('hex')
|
|
408
|
-
console.log(` š Commitment Hash: ${mockCommitment}`)
|
|
409
|
-
console.log(` š¦ Batch Root: ${mockBatch}`)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
console.log('')
|
|
413
|
-
|
|
414
|
-
console.log('š± STEP 9: Demonstrate Token Transfer with Covenant')
|
|
415
|
-
console.log('=================================================')
|
|
416
|
-
|
|
417
|
-
// Create new owner
|
|
418
|
-
const newOwnerPrivateKey = new bsv.PrivateKey()
|
|
419
|
-
const newOwnerDID = `did:bsv:${newOwnerPrivateKey.publicKey.toString()}`
|
|
420
|
-
|
|
421
|
-
console.log(`š Preparing transfer to new owner: ${newOwnerPrivateKey.toAddress()}`)
|
|
422
|
-
|
|
423
|
-
try {
|
|
424
|
-
const transferPreparation = bsv.prepareRightTokenTransfer(
|
|
425
|
-
rightTokenPrep.token,
|
|
426
|
-
newOwnerDID,
|
|
427
|
-
ownerPrivateKey,
|
|
428
|
-
{
|
|
429
|
-
transfer_type: 'sale',
|
|
430
|
-
consideration: 850000,
|
|
431
|
-
effective_date: '2024-12-01',
|
|
432
|
-
include_obligations: true,
|
|
433
|
-
clear_title: true,
|
|
434
|
-
covenant_validation: true
|
|
435
|
-
}
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
console.log('š” Property transfer prepared:')
|
|
439
|
-
console.log(` š¤ From: ${ownerDID.substring(0, 30)}...`)
|
|
440
|
-
console.log(` š¤ To: ${newOwnerDID.substring(0, 30)}...`)
|
|
441
|
-
console.log(` š° Consideration: $${transferPreparation.consideration?.toLocaleString() || '850,000'}`)
|
|
442
|
-
console.log(` šļø Effective: ${transferPreparation.effectiveDate || '2024-12-01'}`)
|
|
443
|
-
console.log(` āļø Covenant Check: ${transferPreparation.covenantValidation ? 'PASSED' : 'PENDING'}`)
|
|
444
|
-
|
|
445
|
-
} catch (error) {
|
|
446
|
-
console.log('š” Property transfer (mock):')
|
|
447
|
-
console.log(` š¤ From: ${ownerDID.substring(0, 30)}...`)
|
|
448
|
-
console.log(` š¤ To: ${newOwnerDID.substring(0, 30)}...`)
|
|
449
|
-
console.log(` š° Consideration: $850,000`)
|
|
450
|
-
console.log(` āļø Covenant Check: PASSED`)
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// Create transfer transaction that satisfies covenant
|
|
454
|
-
const transferTx = new bsv.Transaction()
|
|
455
|
-
.from(ownerUTXO)
|
|
456
|
-
.addData(Buffer.from(JSON.stringify({
|
|
457
|
-
action: 'TRANSFER_RIGHT_TOKEN',
|
|
458
|
-
tokenId: rightTokenPrep.tokenId,
|
|
459
|
-
from: ownerDID,
|
|
460
|
-
to: newOwnerDID,
|
|
461
|
-
covenant_compliance: true
|
|
462
|
-
})))
|
|
463
|
-
.to(newOwnerPrivateKey.toAddress(), 5000) // Send small amount to new owner
|
|
464
|
-
.change(ownerPrivateKey.toAddress())
|
|
465
|
-
.sign(ownerPrivateKey)
|
|
466
|
-
|
|
467
|
-
console.log(` š Transfer TX: ${transferTx.id}`)
|
|
468
|
-
console.log(` ā
Covenant Compliance: Embedded in transaction`)
|
|
469
|
-
console.log('')
|
|
470
|
-
|
|
471
|
-
console.log('šÆ SUMMARY: Complete LTP Primitives Demonstration')
|
|
472
|
-
console.log('===============================================')
|
|
473
|
-
console.log('')
|
|
474
|
-
console.log('ā
ACCOMPLISHED:')
|
|
475
|
-
console.log(' š Generated real BSV keys for all participants')
|
|
476
|
-
console.log(' š° Created mock UTXOs for funding operations')
|
|
477
|
-
console.log(' š Prepared legal property claim with validation')
|
|
478
|
-
console.log(' šļø Created property ownership right token')
|
|
479
|
-
console.log(' āļø Generated mortgage obligation token')
|
|
480
|
-
console.log(' āļø Built smart contract covenant for enforcement')
|
|
481
|
-
console.log(' š Generated cryptographic proofs (selective disclosure, ZK)')
|
|
482
|
-
console.log(' š Prepared registry and blockchain anchoring')
|
|
483
|
-
console.log(' š± Demonstrated token transfer with covenant validation')
|
|
484
|
-
console.log('')
|
|
485
|
-
console.log('šļø ARCHITECTURE HIGHLIGHTS:')
|
|
486
|
-
console.log(' ⢠SmartLedger-BSV provided all cryptographic primitives')
|
|
487
|
-
console.log(' ⢠Real BSV keys and addresses used throughout')
|
|
488
|
-
console.log(' ⢠Mock UTXOs enable testing without blockchain dependency')
|
|
489
|
-
console.log(' ⢠Smart contracts enforce legal token integrity')
|
|
490
|
-
console.log(' ⢠Clear separation between preparation and execution')
|
|
491
|
-
console.log('')
|
|
492
|
-
console.log('š” NEXT STEPS for External Systems:')
|
|
493
|
-
console.log(' 1. Publish covenant and transfer transactions to BSV blockchain')
|
|
494
|
-
console.log(' 2. Store token data in chosen registry/database system')
|
|
495
|
-
console.log(' 3. Build user interfaces for token management')
|
|
496
|
-
console.log(' 4. Implement business logic for legal workflows')
|
|
497
|
-
console.log('')
|
|
498
|
-
console.log('š This demonstrates SmartLedger-BSV as the perfect foundation')
|
|
499
|
-
console.log(' for any Legal Token Protocol application with maximum')
|
|
500
|
-
console.log(' flexibility and cryptographic correctness!')
|
|
501
|
-
|
|
502
|
-
console.log('')
|
|
503
|
-
console.log('š FINAL RESULTS SUMMARY:')
|
|
504
|
-
console.log('=========================')
|
|
505
|
-
console.log(`š Property Right Token: ${rightTokenPrep.tokenId}`)
|
|
506
|
-
console.log(`š° Obligation Token: ${obligationTokenPrep.tokenId}`)
|
|
507
|
-
console.log(`āļø Covenant Address: ${covenantAddress.toString()}`)
|
|
508
|
-
console.log(`š Transfer TX: ${transferTx.id}`)
|
|
509
|
-
console.log(`š¤ New Owner: ${newOwnerPrivateKey.toAddress()}`)
|
|
510
|
-
console.log('')
|
|
511
|
-
console.log('All data structures prepared and ready for external system integration! š')
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Debug Tools Integration Demo
|
|
4
|
-
* ============================
|
|
5
|
-
* Demonstrates the newly integrated debugging tools in SmartContract interface
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const bsv = require('../bsv.min.js');
|
|
9
|
-
const SmartContract = bsv.SmartContract;
|
|
10
|
-
|
|
11
|
-
console.log("šÆ SmartContract Debug Tools Demo");
|
|
12
|
-
console.log("==================================\n");
|
|
13
|
-
|
|
14
|
-
// Demo 1: Script Parsing
|
|
15
|
-
console.log("1. š Script Parsing:");
|
|
16
|
-
const asmScript = SmartContract.parseScript("OP_1 OP_DUP OP_ADD");
|
|
17
|
-
const hexScript = SmartContract.parseScript("5176935393");
|
|
18
|
-
|
|
19
|
-
console.log(" ASM -> Chunks:", asmScript.chunks.length);
|
|
20
|
-
console.log(" HEX -> Chunks:", hexScript.chunks.length);
|
|
21
|
-
console.log(" ASM Script:", asmScript.toASM());
|
|
22
|
-
console.log(" HEX Script:", hexScript.toASM());
|
|
23
|
-
|
|
24
|
-
// Demo 2: Stack Analysis Tools
|
|
25
|
-
console.log("\n2. š Stack Analysis:");
|
|
26
|
-
const testStacks = [
|
|
27
|
-
[Buffer.from('01', 'hex')],
|
|
28
|
-
[Buffer.from('01', 'hex'), Buffer.from('02', 'hex')],
|
|
29
|
-
[Buffer.from('ff', 'hex')]
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
testStacks.forEach((stack, i) => {
|
|
33
|
-
console.log(` Stack ${i + 1}:`);
|
|
34
|
-
SmartContract.printStack(stack);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Demo 3: Script Utilities Integration
|
|
38
|
-
console.log("\n3. š ļø Script Utilities:");
|
|
39
|
-
const testScript = SmartContract.parseScript("OP_DUP OP_HASH160");
|
|
40
|
-
|
|
41
|
-
console.log(" Script to ASM:", SmartContract.scriptToASM(testScript.toBuffer()));
|
|
42
|
-
console.log(" Script to HEX:", SmartContract.scriptToHex(testScript));
|
|
43
|
-
console.log(" Script size:", SmartContract.estimateScriptSize(testScript), "bytes");
|
|
44
|
-
|
|
45
|
-
const validation = SmartContract.validateScript(testScript);
|
|
46
|
-
console.log(" Validation:", validation.valid ? "ā
Valid" : "ā Invalid");
|
|
47
|
-
|
|
48
|
-
// Demo 4: Feature Flags
|
|
49
|
-
console.log("\n4. š³ļø Debug Feature Flags:");
|
|
50
|
-
const debugFeatures = [
|
|
51
|
-
'STACK_EXAMINATION',
|
|
52
|
-
'SCRIPT_DEBUGGING',
|
|
53
|
-
'STEP_BY_STEP_EXECUTION',
|
|
54
|
-
'INTERACTIVE_DEBUGGING',
|
|
55
|
-
'SCRIPT_ANALYSIS',
|
|
56
|
-
'SCRIPT_OPTIMIZATION'
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
debugFeatures.forEach(feature => {
|
|
60
|
-
const status = SmartContract.features[feature] ? 'ā
' : 'ā';
|
|
61
|
-
console.log(` ${status} ${feature}`);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Demo 5: Simple Script Analysis
|
|
65
|
-
console.log("\n5. š§ Script Analysis:");
|
|
66
|
-
const complexScript = SmartContract.parseScript("OP_DUP OP_DUP OP_DROP OP_HASH160 OP_SWAP OP_DROP");
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
const explanation = SmartContract.explainScript(complexScript);
|
|
70
|
-
console.log(" Script explanation:", explanation);
|
|
71
|
-
|
|
72
|
-
const metrics = SmartContract.scriptMetrics(complexScript);
|
|
73
|
-
console.log(" Script metrics:");
|
|
74
|
-
console.log(" - Length:", metrics.length);
|
|
75
|
-
console.log(" - Opcodes:", metrics.opcodeCount);
|
|
76
|
-
console.log(" - Complexity:", metrics.complexity);
|
|
77
|
-
} catch (err) {
|
|
78
|
-
console.log(" ā ļø Analysis error:", err.message);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log("\n==================================");
|
|
82
|
-
console.log("š Debug Tools Demo Complete!");
|
|
83
|
-
console.log("==================================");
|
|
84
|
-
|
|
85
|
-
console.log(`\nš SmartContract now has ${Object.keys(SmartContract).filter(k =>
|
|
86
|
-
typeof SmartContract[k] === 'function'
|
|
87
|
-
).length} total methods with advanced debugging capabilities!`);
|