gitmark 0.0.53 → 0.0.57

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 CHANGED
@@ -102,6 +102,11 @@ const commits = gitlog(options)
102
102
  var head = commits[0].hash
103
103
  console.log('current head', head)
104
104
 
105
+ if (argv._[0] === 'init') {
106
+ console.log($('./bin/git-mark-init').toString())
107
+ process.exit(0)
108
+ }
109
+
105
110
  data.privkey = argv._[0] || secret || getPrivKey() || data.privkey
106
111
  data.hash = argv._[1] || head || data.hash
107
112
  data.genesis = argv.genesis || data.genesis
package/bin/git-mark-init CHANGED
@@ -12,6 +12,7 @@ const homedir = require('os').homedir()
12
12
  const exec = require('child_process').exec
13
13
  const $ = require('child_process').execSync
14
14
  const execSync = require('child_process').execSync
15
+ const package = require('../package.json')
15
16
 
16
17
  // MODEL
17
18
  // default privkey = brain for urn:json:bitmark
@@ -140,8 +141,8 @@ console.log('tx', tx)
140
141
  // create gitmark.json
141
142
  console.log('create gitmark.json and check in files')
142
143
  console.log(`{
143
- "@id": "gitmark:${tx}:1",
144
- "genesis": "gitmark:${tx}:1",
144
+ "@id": "gitmark:${tx}:0",
145
+ "genesis": "gitmark:${tx}:0",
145
146
  "nick": "gitmark",
146
147
  "package": "./package.json",
147
148
  "repository": "./"
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+
3
+ // USAGE: git-mark-list
4
+
5
+ // IMPORTS
6
+ const gitlog = require('gitlog').default
7
+ var bitcoin = require('bitcoinjs-lib')
8
+ var argv = require('minimist')(process.argv.slice(2))
9
+ const fs = require('fs')
10
+ const homedir = require('os').homedir()
11
+ const sha256 = require('sha256')
12
+ // const Buffer = require('safe-buffer').Buffer;
13
+ const schnorr = require('bip-schnorr')
14
+
15
+ // MODEL
16
+ // default privkey = brain for urn:json:bitmark
17
+ globalThis.data = {
18
+ privkey: '132e7465a63e30a74c5b0deae3573033319e9de18a84878613eaa21878b2b56b'
19
+ }
20
+
21
+ // console.log('data', data)
22
+
23
+ // FUNCTIONS
24
+ const BITMARK = {
25
+ messagePrefix: '\x19BITMARK Signed Message:\n',
26
+ bech32: 'btm',
27
+ bip32: {
28
+ public: 0x019da462,
29
+ private: 0x019d9cfe
30
+ },
31
+ pubKeyHash: 85,
32
+ wif: 213,
33
+ scriptHash: 0x32
34
+ }
35
+
36
+ const options = {
37
+ repo: './',
38
+ fields: ['subject', 'authorName', 'authorDate'],
39
+ execOptions: { maxBuffer: 1000 * 1024 },
40
+ number: 1000,
41
+ fields: ['hash', 'subject', 'authorDate']
42
+ }
43
+
44
+ function renderCommit(commit, type) {
45
+ if (type === 'nostr') {
46
+ var canon = [0, commit.pubkey, commit.authorDate, 1, [], commit.hash]
47
+
48
+ canon = JSON.stringify(canon)
49
+ var id = sha256(canon)
50
+
51
+ // console.log(canon)
52
+
53
+ // sign
54
+
55
+
56
+ const privateKeyHex = commit.privkey
57
+ const message = Buffer.from(id, 'hex')
58
+
59
+ const sig = schnorr.sign(privateKeyHex, message).toString('hex')
60
+
61
+ // console.log(sig)
62
+ // var sig = 1
63
+
64
+ var event = `["EVENT",{"id":"${id}","pubkey":"${commit.pubkey}","created_at":${commit.authorDate},"kind":1,"tags":[],"content":"${commit.hash}","sig":"${sig}"}]`
65
+
66
+ console.log(event)
67
+ } else {
68
+ console.log(commit)
69
+ }
70
+ }
71
+
72
+
73
+ function getPrivKey() {
74
+ try {
75
+ const fetchHeadDir = './.git/'
76
+ var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
77
+
78
+ var fetchHead = fs.readFileSync(fetchHeadFile).toString()
79
+
80
+ var repo = fetchHead
81
+ .split(' ')
82
+ .pop()
83
+ .replace(':', '/')
84
+ .replace('\n', '')
85
+
86
+ const gitmarkRepoBase = homedir + '/.gitmark/repo'
87
+
88
+ const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
89
+
90
+ return require(gitmarkFile).privkey
91
+ } catch {
92
+ return undefined
93
+ }
94
+ }
95
+
96
+ // INIT
97
+ data.privkey = argv._[0] || getPrivKey() || data.privkey
98
+ data.count = argv.count
99
+
100
+ var POINT = Buffer.from(data.privkey, 'hex')
101
+
102
+ var OFFSET = Buffer.from('000000000000000000000000' + data.hash, 'hex')
103
+
104
+ // MAIN
105
+ // priv keys
106
+ var b1 = BigInt('0x' + data.privkey)
107
+ var b2
108
+ var b3
109
+ // var keyPair1 = bitcoin.ECPair.fromPrivateKey(POINT)
110
+ // var pubkey = keypair.publicKey
111
+
112
+
113
+ // genesis
114
+ var genesis = require('../gitmark.json')
115
+ var genesisCommit = {
116
+ "pubkey": genesis.pubkey,
117
+ "hash": "genesis",
118
+ "authorDate": genesis.created_at,
119
+ "privkey": b1.toString(16)
120
+ }
121
+ // console.log('genesis', genesis)
122
+ // console.log('genesisCommit', genesisCommit)
123
+ if (!data.count) {
124
+ renderCommit(genesisCommit, 'nostr')
125
+ }
126
+
127
+ // get commits
128
+ const commits = gitlog(options)
129
+ if (commits.length === 1) {
130
+ console.log('Set up new repository with a gitmark')
131
+ process.exit()
132
+ }
133
+
134
+ // traverse backwards
135
+ // console.log('Genesis tx need not be verified\n')
136
+ var done = 0
137
+ 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
+
166
+ commit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
167
+ // console.log('private key WIF:', keyPair1.toWIF())
168
+
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++
180
+ // console.log(commit)
181
+ if (data.count && done >= data.count) break
182
+ }
183
+ }
184
+
185
+
package/gitmark.json CHANGED
@@ -3,5 +3,7 @@
3
3
  "genesis": "gitmark:59ff24db0321cb6b32a404815345b00ae68ca8b81150fbea6464ee10557e0fae:1",
4
4
  "nick": "gitmark",
5
5
  "package": "./package.json",
6
+ "created_at": 1618076262,
7
+ "pubkey": "7574866ae7653e084c3c8e9e6359660e2c728d249fefb0f984bd32393f2ac67f",
6
8
  "repository": "./"
7
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitmark",
3
- "version": "0.0.53",
3
+ "version": "0.0.57",
4
4
  "description": "gitmark",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,9 @@
15
15
  ],
16
16
  "bin": {
17
17
  "git-mark": "bin/git-mark",
18
- "git-mark-init": "bin/git-mark-init"
18
+ "git-mark-init": "bin/git-mark-init",
19
+ "git-mark-list": "bin/git-mark-list",
20
+ "git-mark-verify": "bin/git-mark-verify"
19
21
  },
20
22
  "author": "Melvin Carvalho",
21
23
  "license": "MIT",
@@ -24,11 +26,14 @@
24
26
  },
25
27
  "homepage": "https://github.com/solidpayorg/gitmark#readme",
26
28
  "dependencies": {
29
+ "bip-schnorr": "^0.6.4",
27
30
  "bitcoinjs-lib": "^5.2.0",
28
31
  "child_process": "^1.0.2",
29
32
  "fs": "^0.0.1-security",
30
33
  "gitlog": "^4.0.4",
34
+ "gitmark": "^0.0.56",
31
35
  "minimist": "^1.2.5",
36
+ "sha256": "^0.2.0",
32
37
  "tiny-secp256k1": "^1.1.6",
33
38
  "ws": "^8.2.3"
34
39
  }