Skip to content

Commit ca0899c

Browse files
committed
cert revocation with logs
1 parent 6b7006e commit ca0899c

File tree

2 files changed

+92
-72
lines changed

2 files changed

+92
-72
lines changed

src/identity/IdentityClient.ts

Lines changed: 91 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AuthFetch } from '../auth/clients/index.js'
22
import { DEFAULT_IDENTITY_CLIENT_OPTIONS, defaultIdentity, DisplayableIdentity, KNOWN_IDENTITY_TYPES } from './types/index.js'
33
import {
4+
Base64String,
45
CertificateFieldNameUnder50Bytes,
56
DiscoverByAttributesArgs,
67
DiscoverByIdentityKeyArgs,
@@ -13,9 +14,9 @@ import {
1314
} from '../wallet/index.js'
1415
import { BroadcastFailure, BroadcastResponse, Transaction } from '../transaction/index.js'
1516
import Certificate from '../auth/certificates/Certificate.js'
16-
import { PushDrop } from '../script/index.js'
17+
import { LockingScript, PushDrop } from '../script/index.js'
1718
import { PrivateKey, Utils } from '../primitives/index.js'
18-
import { TopicBroadcaster } from '../overlay-tools/index.js'
19+
import { LookupResolver, SHIPBroadcaster, TopicBroadcaster } from '../overlay-tools/index.js'
1920
import { ContactsManager, Contact } from './ContactsManager.js'
2021

2122
/**
@@ -132,6 +133,12 @@ export class IdentityClient {
132133
}
133134

134135
const { certificates } = await this.wallet.discoverByIdentityKey(args, this.originator)
136+
137+
// TODO JACKIE REEEEEEEEEEEEEE
138+
certificates.forEach(cert => {
139+
console.log(cert.serialNumber)
140+
})
141+
135142
return certificates.map(cert => {
136143
return IdentityClient.parseIdentity(cert)
137144
})
@@ -162,86 +169,98 @@ export class IdentityClient {
162169
// Guard if certificates might be absent
163170
const certs = certificatesResult?.certificates ?? []
164171

172+
console.log('reeeeeeeeee', certs)
173+
165174
// Parse certificates and substitute with contacts where available
166175
return certs.map(cert =>
167176
contactByKey.get(cert.subject) ?? IdentityClient.parseIdentity(cert)
168177
)
169178
}
170179

171180
/**
172-
* TODO: Implement once revocation overlay is created
181+
* TODO: Implement once revocation overlay is created JACKIE REEEEEEEE
173182
* Remove public certificate revelation from overlay services by spending the identity token
174183
* @param serialNumber - Unique serial number of the certificate to revoke revelation
175184
*/
176-
// async revokeCertificateRevelation(
177-
// serialNumber: Base64String
178-
// ): Promise<BroadcastResponse | BroadcastFailure> {
179-
// // 1. Find existing UTXO
180-
// const lookupResolver = new LookupResolver()
181-
// const result = await lookupResolver.query({
182-
// service: 'ls_identity',
183-
// query: {
184-
// serialNumber
185-
// }
186-
// })
187-
188-
// let outpoint: string
189-
// let lockingScript: LockingScript | undefined
190-
// if (result.type === 'output-list') {
191-
// const tx = Transaction.fromAtomicBEEF(result.outputs[this.options.outputIndex].beef)
192-
// outpoint = `${tx.id('hex')}.${this.options.outputIndex}` // Consider better way
193-
// lockingScript = tx.outputs[this.options.outputIndex].lockingScript
194-
// }
195-
196-
// if (lockingScript === undefined) {
197-
// throw new Error('Failed to get locking script for revelation output!')
198-
// }
199-
200-
// // 2. Parse results
201-
// const { signableTransaction } = await this.wallet.createAction({
202-
// description: '',
203-
// inputs: [{
204-
// inputDescription: 'Spend certificate revelation token',
205-
// outpoint,
206-
// unlockingScriptLength: 73
207-
// }],
208-
// options: {
209-
// randomizeOutputs: false
210-
// }
211-
// })
212-
213-
// if (signableTransaction === undefined) {
214-
// throw new Error('Failed to create signable transaction')
215-
// }
216-
217-
// const partialTx = Transaction.fromBEEF(signableTransaction.tx)
218-
219-
// const unlocker = new PushDrop(this.wallet).unlock(
220-
// this.options.protocolID,
221-
// this.options.keyID,
222-
// 'self',
223-
// 'all',
224-
// false,
225-
// 1,
226-
// lockingScript
227-
// )
228-
229-
// const unlockingScript = await unlocker.sign(partialTx, this.options.outputIndex)
230-
231-
// const { tx: signedTx } = await this.wallet.signAction({
232-
// reference: signableTransaction.reference,
233-
// spends: {
234-
// [this.options.outputIndex]: {
235-
// unlockingScript: unlockingScript.toHex()
236-
// }
237-
// }
238-
// })
239-
240-
// // 4. Return broadcast status
241-
// // Submit the transaction to an overlay
242-
// const broadcaster = new SHIPBroadcaster(['tm_identity'])
243-
// return await broadcaster.broadcast(Transaction.fromAtomicBEEF(signedTx as number[]))
244-
// }
185+
async revokeCertificateRevelation(
186+
serialNumber: Base64String
187+
): Promise<BroadcastResponse | BroadcastFailure> {
188+
debugger
189+
190+
// 1. Find existing UTXO
191+
const lookupResolver = new LookupResolver({
192+
networkPreset: (await this.wallet.getNetwork({})).network
193+
})
194+
const result = await lookupResolver.query({
195+
service: 'ls_identity',
196+
query: {
197+
serialNumber
198+
}
199+
})
200+
201+
console.log(result)
202+
203+
let outpoint: string
204+
let lockingScript: LockingScript | undefined
205+
if (result.type === 'output-list') {
206+
const tx = Transaction.fromBEEF(result.outputs[0].beef)
207+
outpoint = `${tx.id('hex')}.${this.options.outputIndex}` // Consider better way
208+
lockingScript = tx.outputs[this.options.outputIndex].lockingScript
209+
}
210+
211+
if (lockingScript === undefined) {
212+
throw new Error('Failed to get locking script for revelation output!')
213+
}
214+
215+
// 2. Parse results
216+
const { signableTransaction } = await this.wallet.createAction({
217+
description: 'Spend certificate revelation token',
218+
inputBEEF: result.outputs[0].beef,
219+
inputs: [{
220+
inputDescription: 'Revelation token',
221+
outpoint,
222+
unlockingScriptLength: 74
223+
}],
224+
options: {
225+
randomizeOutputs: false
226+
}
227+
})
228+
229+
if (signableTransaction === undefined) {
230+
throw new Error('Failed to create signable transaction')
231+
}
232+
233+
const partialTx = Transaction.fromBEEF(signableTransaction.tx)
234+
235+
const unlocker = new PushDrop(this.wallet).unlock(
236+
this.options.protocolID,
237+
this.options.keyID,
238+
'anyone'
239+
)
240+
241+
const unlockingScript = await unlocker.sign(partialTx, this.options.outputIndex)
242+
243+
const { tx: signedTx } = await this.wallet.signAction({
244+
reference: signableTransaction.reference,
245+
spends: {
246+
[this.options.outputIndex]: {
247+
unlockingScript: unlockingScript.toHex()
248+
}
249+
}
250+
})
251+
252+
// 4. Return broadcast status
253+
// Submit the transaction to an overlay
254+
255+
console.log("REEEEEEE")
256+
const broadcaster = new SHIPBroadcaster(['tm_identity'])
257+
console.log("REEEEEEE 2")
258+
259+
const broadcastResult = await broadcaster.broadcast(Transaction.fromAtomicBEEF(signedTx as number[]))
260+
console.log(broadcastResult)
261+
262+
return broadcastResult // await broadcaster.broadcast(Transaction.fromAtomicBEEF(signedTx as number[]))
263+
}
245264

246265
/**
247266
* Load all records from the contacts basket

src/wallet/substrates/WalletWireTransceiver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ export default class WalletWireTransceiver implements WalletInterface {
17801780
},
17811781
originator?: OriginatorDomainNameStringUnder250Bytes
17821782
): Promise<{ relinquished: true }> {
1783+
debugger
17831784
const paramWriter = new Utils.Writer()
17841785
const typeAsArray = Utils.toArray(args.type, 'base64')
17851786
paramWriter.write(typeAsArray)

0 commit comments

Comments
 (0)