fix account sign method
This commit is contained in:
parent
5667643068
commit
ced31593b3
|
@ -1,6 +1,10 @@
|
||||||
import { keccak256 } from 'ethereum-cryptography/keccak'
|
import { keccak256 } from 'ethereum-cryptography/keccak'
|
||||||
import { getPublicKey, sign, utils } from 'ethereum-cryptography/secp256k1'
|
import { getPublicKey, sign } from 'ethereum-cryptography/secp256k1'
|
||||||
import { bytesToHex } from 'ethereum-cryptography/utils'
|
import {
|
||||||
|
bytesToHex,
|
||||||
|
concatBytes,
|
||||||
|
hexToBytes,
|
||||||
|
} from 'ethereum-cryptography/utils'
|
||||||
|
|
||||||
export class Account {
|
export class Account {
|
||||||
public privateKey: string
|
public privateKey: string
|
||||||
|
@ -21,8 +25,15 @@ export class Account {
|
||||||
this.chatKey = bytesToHex(chatKey)
|
this.chatKey = bytesToHex(chatKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
signMessage = (payload: Uint8Array) => {
|
// sig must be a 65-byte compact ECDSA signature containing the recovery id as the last element.
|
||||||
|
sign = async (payload: Uint8Array) => {
|
||||||
const hash = keccak256(payload)
|
const hash = keccak256(payload)
|
||||||
return sign(hash, this.privateKey)
|
const [signature, recoverId] = await sign(hash, this.privateKey, {
|
||||||
|
recovered: true,
|
||||||
|
der: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
return concatBytes(signature, new Uint8Array([recoverId]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
|
// todo: replies
|
||||||
|
// todo: identities/members?
|
||||||
// todo: validate sig
|
// todo: validate sig
|
||||||
// todo: observer contact updates
|
// todo: observer contact updates
|
||||||
// todo: replies
|
// todo: observer channels
|
||||||
// todo: subsribe to newly added channel
|
|
||||||
// todo: identities/members?
|
// denormalized
|
||||||
// todo: getmesages
|
// before calling callback; response to message id
|
||||||
|
// proactively change
|
||||||
import { bytesToHex } from 'ethereum-cryptography/utils'
|
import { bytesToHex } from 'ethereum-cryptography/utils'
|
||||||
import { Waku, waku_message } from 'js-waku'
|
import { Waku, waku_message } from 'js-waku'
|
||||||
|
import chunk from 'lodash/chunk'
|
||||||
import difference from 'lodash/difference'
|
import difference from 'lodash/difference'
|
||||||
import sortBy from 'lodash/sortBy'
|
import sortBy from 'lodash/sortBy'
|
||||||
import uniqBy from 'lodash/uniqBy'
|
import uniqBy from 'lodash/uniqBy'
|
||||||
import chunk from 'lodash/chunk'
|
|
||||||
|
|
||||||
import { ApplicationMetadataMessage } from '../protos/application-metadata-message'
|
import { ApplicationMetadataMessage } from '../protos/application-metadata-message'
|
||||||
// import { ChatIdentity } from '../protos/chat-identity'
|
// import { ChatIdentity } from '../protos/chat-identity'
|
||||||
|
@ -144,7 +147,6 @@ class Community {
|
||||||
console.log('COMMUNITY:', this)
|
console.log('COMMUNITY:', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo? and channels
|
|
||||||
private async observeCommunity() {
|
private async observeCommunity() {
|
||||||
// console.log('here')
|
// console.log('here')
|
||||||
this.waku.relay.addDecryptionKey(this.communityDecryptionKey)
|
this.waku.relay.addDecryptionKey(this.communityDecryptionKey)
|
||||||
|
@ -530,27 +532,11 @@ class Community {
|
||||||
callback: (messages: MessageType[], isDone: boolean) => boolean,
|
callback: (messages: MessageType[], isDone: boolean) => boolean,
|
||||||
options: { start: Date; end: Date; chunk: number /*total: number*/ }
|
options: { start: Date; end: Date; chunk: number /*total: number*/ }
|
||||||
) {
|
) {
|
||||||
// const id = `${this.communityPublicKey}${channelId}`
|
|
||||||
// const channelContentTopic = await idToContentTopic(channelId)
|
|
||||||
// const symKey = await createSymKeyFromPassword(id)
|
|
||||||
|
|
||||||
// this.waku.store.addDecryptionKey(symKey, {
|
|
||||||
// method: waku_message.DecryptionMethod.Symmetric,
|
|
||||||
// contentTopics: [channelContentTopic],
|
|
||||||
// })
|
|
||||||
|
|
||||||
const id = `${this.communityPublicKey}${channelId}`
|
const id = `${this.communityPublicKey}${channelId}`
|
||||||
const channelContentTopic = await idToContentTopic(id)
|
const channelContentTopic = await idToContentTopic(id)
|
||||||
const symKey = await createSymKeyFromPassword(id)
|
const symKey = await createSymKeyFromPassword(id)
|
||||||
|
|
||||||
// todo: request waku feature to be passed as param
|
|
||||||
// this.waku.store.addDecryptionKey(symKey, {
|
|
||||||
// method: waku_message.DecryptionMethod.Symmetric,
|
|
||||||
// contentTopics: [channelContentTopic],
|
|
||||||
// })
|
|
||||||
|
|
||||||
const messages: MessageType[] = []
|
const messages: MessageType[] = []
|
||||||
let count = 0
|
|
||||||
let shouldStop = false
|
let shouldStop = false
|
||||||
|
|
||||||
await this.waku.store.queryHistory([channelContentTopic], {
|
await this.waku.store.queryHistory([channelContentTopic], {
|
||||||
|
@ -559,7 +545,7 @@ class Community {
|
||||||
// endTime: options.end,
|
// endTime: options.end,
|
||||||
// },
|
// },
|
||||||
// todo!: increase after testing
|
// todo!: increase after testing
|
||||||
// pageSize: 5,
|
pageSize: 100,
|
||||||
decryptionKeys: [symKey],
|
decryptionKeys: [symKey],
|
||||||
callback: wakuMessages => {
|
callback: wakuMessages => {
|
||||||
for (const wakuMessage of wakuMessages.reverse()) {
|
for (const wakuMessage of wakuMessages.reverse()) {
|
||||||
|
@ -621,8 +607,6 @@ class Community {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const _chunk of chunk(messages, options.chunk)) {
|
for (const _chunk of chunk(messages, options.chunk)) {
|
||||||
|
|
Loading…
Reference in New Issue