gitmark 0.0.55 → 0.0.56

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.
@@ -0,0 +1,179 @@
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
+
99
+ var POINT = Buffer.from(data.privkey, 'hex')
100
+
101
+ var OFFSET = Buffer.from('000000000000000000000000' + data.hash, 'hex')
102
+
103
+ // MAIN
104
+ // priv keys
105
+ var b1 = BigInt('0x' + data.privkey)
106
+ var b2
107
+ var b3
108
+ // var keyPair1 = bitcoin.ECPair.fromPrivateKey(POINT)
109
+ // var pubkey = keypair.publicKey
110
+
111
+
112
+ // genesis
113
+ var genesis = require('../gitmark.json')
114
+ var genesisCommit = {
115
+ "pubkey": genesis.pubkey,
116
+ "hash": "genesis",
117
+ "authorDate": genesis.created_at,
118
+ "privkey": b1.toString(16)
119
+ }
120
+ // console.log('genesis', genesis)
121
+ // console.log('genesisCommit', genesisCommit)
122
+ renderCommit(genesisCommit, 'nostr')
123
+
124
+ // get commits
125
+ const commits = gitlog(options)
126
+ if (commits.length === 1) {
127
+ console.log('Set up new repository with a gitmark')
128
+ process.exit()
129
+ }
130
+
131
+ // traverse backwards
132
+ // console.log('Genesis tx need not be verified\n')
133
+ for (var i = commits.length - 1; i >= 0; i--) {
134
+ var commit = {}
135
+ commit.subject = commits[i].subject
136
+
137
+ if (commit.subject.match(/^gitmark[: ][A-Fa-f0-9]/)) {
138
+ commit.hash = commits[i + 1].hash
139
+ commit.authorDate = Math.floor(
140
+ new Date(commits[i].authorDate).getTime() / 1000
141
+ )
142
+ // console.log()
143
+ b2 = BigInt('0x' + commit.hash)
144
+ b3 = BigInt.asUintN(256, b1 + b2)
145
+ commit.privkey = b1.toString(16)
146
+ commit.tweakedkey = b3.toString(16)
147
+ // console.log('original private key', b3.toString(16))
148
+ // console.log('tweaked private key', b3.toString(16))
149
+ var keyPair1 = bitcoin.ECPair.fromPrivateKey(
150
+ Buffer.from(b1.toString(16), 'hex'),
151
+ { network: BITMARK }
152
+ )
153
+ commit.wifkey = keyPair1.toWIF()
154
+
155
+ function buf2hex(buffer) {
156
+ // buffer is an ArrayBuffer
157
+ return [...new Uint8Array(buffer)]
158
+ .map(x => x.toString(16).padStart(2, '0'))
159
+ .join('')
160
+ }
161
+
162
+ commit.pubkey = buf2hex(keyPair1.publicKey).substring(2)
163
+ // console.log('private key WIF:', keyPair1.toWIF())
164
+
165
+ var { address } = bitcoin.payments.p2pkh({
166
+ pubkey: keyPair1.publicKey,
167
+ network: BITMARK
168
+ })
169
+ commit.address = address
170
+ // console.log('verify address computed from private key:', address)
171
+
172
+ commit.verify = `https://gitmark.info/${commit.subject.split(/[: ]/)[1]}`
173
+
174
+ renderCommit(commit, 'nostr')
175
+ // console.log(commit)
176
+ }
177
+ }
178
+
179
+
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.55",
3
+ "version": "0.0.56",
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,12 +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",
31
34
  "minimist": "^1.2.5",
35
+ "sha256": "^0.2.0",
32
36
  "tiny-secp256k1": "^1.1.6",
33
37
  "ws": "^8.2.3"
34
38
  }
35
- }
39
+ }