Skip to content

Commit

Permalink
Merge pull request #191 from keyko-io/fix-encoding-dc-removal-proposal
Browse files Browse the repository at this point in the history
remove datacap proposal -- fix encoding the proposal parameters
  • Loading branch information
jbesraa authored Jun 30, 2023
2 parents b7f2334 + 8bca11f commit a619440
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keyko-io/filecoin-verifier-tools",
"version": "2.2.2",
"version": "2.2.3",
"description": "Javascript implementation of a HAMT using ipld",
"main": "lib/index.js",
"repository": {
Expand Down
22 changes: 17 additions & 5 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { decode } from 'cbor'

const cacheAddress = {}
const cacheKey = {}
const SignatureDomainSeparation_RemoveDataCap = "fil_removedatacap:"

export class VerifyAPI {
constructor(lotusClient, walletContext, testnet = true) {
Expand Down Expand Up @@ -67,17 +68,28 @@ export class VerifyAPI {
return res['/']
}

encodeRemoveDataCapParameters(message: [address: string, datacap: string, id: number[]]) {
return this.methods.encode(this.methods.RemoveDataCapProposal,message)
// encodeRemoveDataCapParameters_old(message: [address: string, datacap: string, id: number[]]) {
// return this.methods.encode(
// this.methods.RemoveDataCapProposal, message
// )
// }

encodeRemoveDataCapParameters(message: {verifiedClient: string, dataCapAmount: string, removalProposalID: number[]}) {
const orderedProposalParams = [SignatureDomainSeparation_RemoveDataCap, message.verifiedClient, message.dataCapAmount, message.removalProposalID]
return this.methods.encode(this.methods.RemoveDataCapProposal, orderedProposalParams)
}

async proposeRemoveDataCap(clientToRemoveDcFrom, datacap, verifier1, signature1, verifier2, signature2, indexAccount, wallet, { gas } = { gas: 0 }) {
const removeDatacapProposal = this.methods.verifreg.removeVerifiedClientDataCap(
async proposeRemoveDataCap(
clientToRemoveDcFrom, datacap,
verifier1, signature1, verifier2, signature2,
indexAccount, wallet, { gas } = { gas: 0 }) {

const removeDatacapRequest = this.methods.verifreg.removeVerifiedClientDataCap(
clientToRemoveDcFrom, datacap,
{ verifier: verifier1, signature: signature1 },
{ verifier: verifier2, signature: signature2 },
)
const tx = this.methods.rootkey.propose(removeDatacapProposal)
const tx = this.methods.rootkey.propose(removeDatacapRequest)
const res = await this.methods.sendTx(this.client, indexAccount, this.checkWallet(wallet), { ...tx, gas })
return res['/']
}
Expand Down
19 changes: 12 additions & 7 deletions src/filecoin/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import cbor from "cbor";
import * as hamt from "../hamt/hamt-2";
import blake from "blakejs";
import * as address from "@glif/filecoin-address";
// const { CID } = require("multiformats/cid");
import { CID } from "multiformats/cid";
import multihashes from "multihashes";
import { identity } from "multiformats/hashes/identity";
import * as rawFormat from "multiformats/codecs/raw";

Expand Down Expand Up @@ -731,11 +729,18 @@ function make(testnet) {

const REMOVE_DATACAP_PROPOSAL = [
"cbor",
{
verifiedClient: 'address',
datacapAmount: 'bigint',
removalProposalID: ["list", "int"]
},
[
'string', // sigDomainSeparationString
'address', // verifiedClient
'bigint', // dataCapAmount
["list", "int"] // removalProposalID
]
// {
// sigDomainSeparationString: 'string',
// verifiedClient: 'address',
// dataCapAmount: 'bigint',
// removalProposalID: ["list", "int"]
// }
];

const reg = {
Expand Down
10 changes: 4 additions & 6 deletions src/samples/api/encodeRemoveParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ const api = new VerifyAPI.VerifyAPI(VerifyAPI.VerifyAPI.standAloneProvider(endpo

async function removeDatacap() {
try {

const encoded = api.encodeRemoveDataCapParameters(["t01004",158856254,[1256]])
const encoded = api.encodeRemoveDataCapParameters(['t01004', 158856254, [1256]])
console.log(encoded)
console.log(encoded.toString('hex'))
// console.log('encoded:', encoded[0].toString('hex'), encoded[1].toString('hex'), encoded[2].toString('hex'))
//datacap 000977f43e ok!!!
//address 00ec07
//id 0004e8

// datacap 000977f43e ok!!!
// address 00ec07
// id 0004e8

console.log('834300ec0745000977f43e811904e8')
console.log(encoded.toString('hex') === '834300ec0745000977f43e811904e8')
Expand Down

0 comments on commit a619440

Please sign in to comment.