I was in trouble to sign an image.
[AVLE] Image Upload - Signing Image not working
Through arduous efforts, I managed to sign an image!
There was no way to pass a data of dart to the Buffer data of javascipt.
So, I changed the dsteem source code to accept Uint8List of Dart which is the Buffer!
This is the modified sign function of dsteem's crypto.ts file.
// crypto.ts of dsteem
public sign(message: any): Signature {
// for avle, need to pass Uint8List
const msgBuf = Buffer.from(message);
let rv: { signature: Buffer; recovery: number };
let attempts = 0;
do {
const options = {
data: sha256(Buffer.concat([msgBuf, Buffer.alloc(1, ++attempts)])),
};
rv = secp256k1.sign(msgBuf, this.key, options);
} while (!isCanonicalSignature(rv.signature));
return new Signature(rv.signature, rv.recovery);
}
And the following is the signMessage function in Dart side:
String? signMessage({required Uint8List data, required String wifKey}) {
try {
// create a private key instance
final privateKey = PrivateKey.fromString(wifKey);
// create a buffer
final dataBuffer = BytesBuilder();
// prefix string to sign
final prefix = 'ImageSigningChallenge';
// write the prefix data in the buffer
dataBuffer.add(utf8.encode(prefix) as Uint8List);
// add data in the buffer
dataBuffer.add(data);
// hash the buffer data
final hash = sha256.convert(dataBuffer.toBytes()).bytes as Uint8List;
print('hash: $hash');
final signature = privateKey.sign(hash);
} catch (error) {
print('failed to sign message');
}
}
Now the signing and uploading an image are smooth!
After signing the image, then we can get the url of the image!
Resteem / Vote / Comment / Follow / Support
This project will Make STEEM Great Again! I, the developer of PLAY STEEM mobile app, am doing my best to bring people to the STEEM ecosystem.
cc.
@steemcurator01
응원합니다. ^^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
잘 해결되어서 다행입니다!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit