gitmark 0.0.63 → 0.0.66
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/bin/git-mark-list +30 -13
- package/package.json +1 -1
package/bin/git-mark-list
CHANGED
|
@@ -21,6 +21,13 @@ globalThis.data = {
|
|
|
21
21
|
// console.log('data', data)
|
|
22
22
|
|
|
23
23
|
// FUNCTIONS
|
|
24
|
+
function buf2hex(buffer) {
|
|
25
|
+
// buffer is an ArrayBuffer
|
|
26
|
+
return [...new Uint8Array(buffer)]
|
|
27
|
+
.map(x => x.toString(16).padStart(2, '0'))
|
|
28
|
+
.join('')
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
const BITMARK = {
|
|
25
32
|
messagePrefix: '\x19BITMARK Signed Message:\n',
|
|
26
33
|
bech32: 'btm',
|
|
@@ -56,12 +63,6 @@ function addCryptoToCommit(commit) {
|
|
|
56
63
|
)
|
|
57
64
|
commit.wifkey = keyPair1.toWIF()
|
|
58
65
|
|
|
59
|
-
function buf2hex(buffer) {
|
|
60
|
-
// buffer is an ArrayBuffer
|
|
61
|
-
return [...new Uint8Array(buffer)]
|
|
62
|
-
.map(x => x.toString(16).padStart(2, '0'))
|
|
63
|
-
.join('')
|
|
64
|
-
}
|
|
65
66
|
|
|
66
67
|
commit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
|
|
67
68
|
// console.log('private key WIF:', keyPair1.toWIF())
|
|
@@ -82,10 +83,12 @@ function addCryptoToCommit(commit) {
|
|
|
82
83
|
|
|
83
84
|
function renderCommit(commit, type) {
|
|
84
85
|
if (!commit) return
|
|
86
|
+
commit.tags = commit.tags || []
|
|
87
|
+
if (commit.c) commit.tags.push(["c", commit.c])
|
|
85
88
|
if (type === 'nostr') {
|
|
86
|
-
var canon = [0, commit.pubkey, commit.authorDate, 17,
|
|
89
|
+
var canon = [0, commit.pubkey, commit.authorDate, 17, commit.tags, commit.hash]
|
|
87
90
|
|
|
88
|
-
canon = JSON.stringify(canon)
|
|
91
|
+
canon = JSON.stringify(canon).replace(/\\"/g, '"')
|
|
89
92
|
var id = sha256(canon)
|
|
90
93
|
|
|
91
94
|
// console.log(canon)
|
|
@@ -101,7 +104,7 @@ function renderCommit(commit, type) {
|
|
|
101
104
|
// console.log(sig)
|
|
102
105
|
// var sig = 1
|
|
103
106
|
|
|
104
|
-
var event = `["EVENT",{"id":"${id}","pubkey":"${commit.pubkey}","created_at":${commit.authorDate},"kind":${KIND_CODE},"tags"
|
|
107
|
+
var event = `["EVENT",{"id":"${id}","pubkey":"${commit.pubkey}","created_at":${commit.authorDate},"kind":${KIND_CODE},"tags":${JSON.stringify(commit.tags)},"content":"${commit.hash}","sig":"${sig}"}]`
|
|
105
108
|
|
|
106
109
|
console.log(event)
|
|
107
110
|
} else {
|
|
@@ -135,7 +138,10 @@ function getPrivKey() {
|
|
|
135
138
|
|
|
136
139
|
// INIT
|
|
137
140
|
data.privkey = argv._[0] || getPrivKey() || data.privkey
|
|
141
|
+
data.g = argv.g
|
|
138
142
|
data.count = argv.count
|
|
143
|
+
data.genesis = argv.genesis
|
|
144
|
+
data.created_at = argv.created
|
|
139
145
|
|
|
140
146
|
var POINT = Buffer.from(data.privkey, 'hex')
|
|
141
147
|
|
|
@@ -153,11 +159,21 @@ var b3
|
|
|
153
159
|
// genesis
|
|
154
160
|
var genesis = require('../gitmark.json')
|
|
155
161
|
var genesisCommit = {
|
|
156
|
-
"pubkey": genesis.pubkey,
|
|
157
162
|
"hash": "genesis",
|
|
158
|
-
"authorDate":
|
|
159
|
-
"privkey": b1.toString(16)
|
|
163
|
+
"authorDate": data.created_at,
|
|
164
|
+
"privkey": b1.toString(16),
|
|
165
|
+
"c": data.genesis,
|
|
160
166
|
}
|
|
167
|
+
var keyPair1 = bitcoin.ECPair.fromPrivateKey(
|
|
168
|
+
Buffer.from(b1.toString(16), 'hex'),
|
|
169
|
+
{ network: BITMARK }
|
|
170
|
+
)
|
|
171
|
+
genesisCommit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
|
|
172
|
+
if (data.g) {
|
|
173
|
+
genesisCommit.tags = [["g", data.g]]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
161
177
|
// console.log('genesis', genesis)
|
|
162
178
|
// console.log('genesisCommit', genesisCommit)
|
|
163
179
|
if (!data.count) {
|
|
@@ -185,7 +201,8 @@ for (var i = commits.length - 1; i >= 0; i--) {
|
|
|
185
201
|
hash: commits[i + 1]?.hash,
|
|
186
202
|
subject: commits[i].subject,
|
|
187
203
|
authorDate: Math.floor(new Date(commits[i].authorDate).getTime() / 1000),
|
|
188
|
-
privkey: b1.toString(16)
|
|
204
|
+
privkey: b1.toString(16),
|
|
205
|
+
c: commits[i].subject
|
|
189
206
|
}
|
|
190
207
|
commit = addCryptoToCommit(commit)
|
|
191
208
|
// console.log(commit)
|