gitmark 0.0.57 → 0.0.60

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.
Files changed (2) hide show
  1. package/bin/git-mark-list +62 -44
  2. package/package.json +1 -1
package/bin/git-mark-list CHANGED
@@ -37,11 +37,51 @@ const options = {
37
37
  repo: './',
38
38
  fields: ['subject', 'authorName', 'authorDate'],
39
39
  execOptions: { maxBuffer: 1000 * 1024 },
40
- number: 1000,
40
+ number: 1000000,
41
41
  fields: ['hash', 'subject', 'authorDate']
42
42
  }
43
43
 
44
+ function addCryptoToCommit(commit) {
45
+ // console.log('commit', commit)
46
+ if (!commit.hash) return
47
+ b2 = BigInt('0x' + commit.hash)
48
+ b3 = BigInt.asUintN(256, b1 + b2)
49
+ commit.privkey = b1.toString(16)
50
+ commit.tweakedkey = b3.toString(16)
51
+ // console.log('original private key', b3.toString(16))
52
+ // console.log('tweaked private key', b3.toString(16))
53
+ var keyPair1 = bitcoin.ECPair.fromPrivateKey(
54
+ Buffer.from(b1.toString(16), 'hex'),
55
+ { network: BITMARK }
56
+ )
57
+ commit.wifkey = keyPair1.toWIF()
58
+
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
+ commit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
67
+ // console.log('private key WIF:', keyPair1.toWIF())
68
+
69
+ var { address } = bitcoin.payments.p2pkh({
70
+ pubkey: keyPair1.publicKey,
71
+ network: BITMARK
72
+ })
73
+ commit.address = address
74
+ // console.log('verify address computed from private key:', address)
75
+
76
+ commit.verify = `https://gitmark.info/${commit.subject.split(/[: ]/)[1]}`
77
+
78
+ return commit
79
+
80
+ }
81
+
82
+
44
83
  function renderCommit(commit, type) {
84
+ if (!commit) return
45
85
  if (type === 'nostr') {
46
86
  var canon = [0, commit.pubkey, commit.authorDate, 1, [], commit.hash]
47
87
 
@@ -51,7 +91,7 @@ function renderCommit(commit, type) {
51
91
  // console.log(canon)
52
92
 
53
93
  // sign
54
-
94
+ const KIND_CODE = 17
55
95
 
56
96
  const privateKeyHex = commit.privkey
57
97
  const message = Buffer.from(id, 'hex')
@@ -61,7 +101,7 @@ function renderCommit(commit, type) {
61
101
  // console.log(sig)
62
102
  // var sig = 1
63
103
 
64
- var event = `["EVENT",{"id":"${id}","pubkey":"${commit.pubkey}","created_at":${commit.authorDate},"kind":1,"tags":[],"content":"${commit.hash}","sig":"${sig}"}]`
104
+ var event = `["EVENT",{"id":"${id}","pubkey":"${commit.pubkey}","created_at":${commit.authorDate},"kind":${KIND_CODE},"tags":[],"content":"${commit.hash}","sig":"${sig}"}]`
65
105
 
66
106
  console.log(event)
67
107
  } else {
@@ -131,55 +171,33 @@ if (commits.length === 1) {
131
171
  process.exit()
132
172
  }
133
173
 
174
+
175
+
134
176
  // traverse backwards
135
177
  // console.log('Genesis tx need not be verified\n')
136
178
  var done = 0
179
+ var gitmarks = []
137
180
  for (var i = commits.length - 1; i >= 0; i--) {
138
- var commit = {}
139
- commit.subject = commits[i].subject
140
-
141
- if (commit.subject.match(/^gitmark[: ][A-Fa-f0-9]/)) {
142
- commit.hash = commits[i + 1].hash
143
- commit.authorDate = Math.floor(
144
- new Date(commits[i].authorDate).getTime() / 1000
145
- )
146
- // console.log()
147
- b2 = BigInt('0x' + commit.hash)
148
- b3 = BigInt.asUintN(256, b1 + b2)
149
- commit.privkey = b1.toString(16)
150
- commit.tweakedkey = b3.toString(16)
151
- // console.log('original private key', b3.toString(16))
152
- // console.log('tweaked private key', b3.toString(16))
153
- var keyPair1 = bitcoin.ECPair.fromPrivateKey(
154
- Buffer.from(b1.toString(16), 'hex'),
155
- { network: BITMARK }
156
- )
157
- commit.wifkey = keyPair1.toWIF()
158
-
159
- function buf2hex(buffer) {
160
- // buffer is an ArrayBuffer
161
- return [...new Uint8Array(buffer)]
162
- .map(x => x.toString(16).padStart(2, '0'))
163
- .join('')
164
- }
165
181
 
166
- commit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
167
- // console.log('private key WIF:', keyPair1.toWIF())
182
+ if (commits[i].subject.match(/^gitmark[: ][A-Fa-f0-9]/)) {
168
183
 
169
- var { address } = bitcoin.payments.p2pkh({
170
- pubkey: keyPair1.publicKey,
171
- network: BITMARK
172
- })
173
- commit.address = address
174
- // console.log('verify address computed from private key:', address)
175
-
176
- commit.verify = `https://gitmark.info/${commit.subject.split(/[: ]/)[1]}`
177
-
178
- renderCommit(commit, 'nostr')
179
- done++
184
+ var commit = {
185
+ hash: commits[i + 1]?.hash,
186
+ subject: commits[i].subject,
187
+ authorDate: Math.floor(new Date(commits[i].authorDate).getTime() / 1000),
188
+ privkey: b1.toString(16)
189
+ }
190
+ commit = addCryptoToCommit(commit)
180
191
  // console.log(commit)
181
- if (data.count && done >= data.count) break
192
+ gitmarks.push(commit)
193
+
182
194
  }
183
195
  }
184
196
 
185
197
 
198
+ gitmarks = gitmarks.reverse()
199
+ var len = data.count || gitmarks.length
200
+ for (var i = 0; i < len; i++) {
201
+ // console.log(gitmarks[i])
202
+ renderCommit(gitmarks[i], 'nostr')
203
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitmark",
3
- "version": "0.0.57",
3
+ "version": "0.0.60",
4
4
  "description": "gitmark",
5
5
  "main": "index.js",
6
6
  "scripts": {