gitmark 0.0.24 → 0.0.28

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/GENESIS.md ADDED
@@ -0,0 +1,49 @@
1
+ ## Genesis
2
+
3
+ The genesis transaction output starts the chain of marks in git mark
4
+
5
+ In order to start marking you will need a genesis transaction output
6
+
7
+ This will also have a public address and a private key (secret exponent)
8
+
9
+ You will need the transaction id and the secret exponent to start git marking
10
+
11
+ One way to save the secret exponent is in git
12
+
13
+ ```
14
+ git config gitmark.secret <secretexponent>
15
+ ```
16
+
17
+ This is not terribly secure, but for small projects to get started it is convenient
18
+
19
+ A useful way to generate an address and secret exponent would be:
20
+
21
+ https://project-bitmark.github.io/brain/
22
+
23
+ Use a very secure password for anything more than testing
24
+
25
+ Once you have an address, send some coins there from a faucet, a friend, or by being marked
26
+
27
+ The genesis id also doubles as the @id for a gitmark project
28
+
29
+ Optionally it can be added a file, `gitmark.json` in the root directory of your repo
30
+
31
+ It may look like this:
32
+
33
+ ```JSON
34
+ {
35
+ "@id": "gitmark:b1fb9acb83f85887760b2e1a71e1df370976b1596be101bb0dbe8fd1c80f91cd:0",
36
+ "genesis": "gitmark:b1fb9acb83f85887760b2e1a71e1df370976b1596be101bb0dbe8fd1c80f91cd:0",
37
+ "nick": "myrepo",
38
+ "package": "./package.json",
39
+ "repository": "./"
40
+ }
41
+ ```
42
+
43
+ Once you have your genesis tx, you can make your first git mark by running, for example:
44
+
45
+ ```
46
+ git mark --genesis b1fb9acb83f85887760b2e1a71e1df370976b1596be101bb0dbe8fd1c80f91cd:0
47
+ ```
48
+
49
+ Do this after you have commited your first files, and as recommended a gitmark.json file too
package/README.md CHANGED
@@ -93,6 +93,8 @@ After running this script, an empty commit message is generated which you can ch
93
93
 
94
94
  Congratulations! You have now marked your first git repo!
95
95
 
96
+ See also: [Example Workflow](./WORKFLOW.md)
97
+
96
98
  ## How it works
97
99
 
98
100
  Gitmark simply uses [single use seals](https://petertodd.org/2017/scalable-single-use-seal-asset-transfer) to tweak the initial public key address of the genesis transaction by the commit hash of the git tree. The current git hash is added to the original, genesis, public key in the output transaction, creating a chain of commits in the block chain
package/WORKFLOW.md ADDED
@@ -0,0 +1,44 @@
1
+ ## Example workflow
2
+
3
+ 1. Generate a [genesis](./GENESIS.md) address
4
+
5
+ 2. For example from here: https://project-bitmark.github.io/brain/
6
+
7
+ 3. Add funds to that address, from a faucet, from your coins, or by being marked
8
+
9
+ 4. Grab the transaction id of your new funds, that's the genesis of the mark chain, and also id of the git mark repo
10
+
11
+ 5. Commit your git tree
12
+
13
+ 6. [Optionally] add a gitmark.json e.g.
14
+
15
+ ```JSON
16
+ {
17
+ "@id": "gitmark:b1fb9acb83f85887760b2e1a71e1df370976b1596be101bb0dbe8fd1c80f91cd:0",
18
+ "genesis": "gitmark:b1fb9acb83f85887760b2e1a71e1df370976b1596be101bb0dbe8fd1c80f91cd:0",
19
+ "nick": "myrepo",
20
+ "package": "./package.json",
21
+ "repository": "./"
22
+ }
23
+ ```
24
+
25
+ 7. Commit gitmark.json
26
+
27
+ 8. Run:
28
+ ```
29
+ git mark --genesis <txid:output>
30
+ ```
31
+
32
+ 9. Run the produced command to create a new tx
33
+
34
+ 10. If successful you will get a tx output which can be used in a tag or in a new commit message:
35
+
36
+ ```
37
+ git commit --allow-empty "<txid:output>
38
+ ```
39
+
40
+ You are done!
41
+
42
+ You can now continue git marking as your project grows, and also push to whatever remotes that you have
43
+
44
+ Full workflow is here for illustration. Some or all of these steps can be automated, to make it a one click process
package/bin/git-mark CHANGED
@@ -10,6 +10,7 @@ const gitlog = require('gitlog').default
10
10
  const fs = require('fs')
11
11
  const homedir = require('os').homedir()
12
12
  const exec = require('child_process').exec
13
+ const $ = require('child_process').execSync
13
14
  const execSync = require('child_process').execSync
14
15
 
15
16
  // MODEL
@@ -176,7 +177,6 @@ var { address } = bitcoin.payments.p2pkh({
176
177
  })
177
178
  console.log('address computed from public', address)
178
179
 
179
- var fee = 1000
180
180
  var tx
181
181
  const gitmarkTxBase = homedir + '/.gitmark/tx'
182
182
 
@@ -185,6 +185,7 @@ try {
185
185
  tx = { total_output: '1', fees: '0.00001' }
186
186
  } else {
187
187
  tx = require(gitmarkTxBase + '/' + lastCommit[0] + '.json')
188
+ if (!tx.total_output) tx.total_output = tx.vout[0].value
188
189
  }
189
190
  } catch (e) {
190
191
  console.error(e)
@@ -198,14 +199,21 @@ try {
198
199
  '.json'
199
200
  )
200
201
  console.log('trying:')
201
- var command = `curl "https://chainz.cryptoid.info/marks/api.dws?q=txinfo&t=${lastCommit[0]}" > ${gitmarkTxBase}/${lastCommit[0]}.json`
202
+ var explorerURI = $('git config gitmark.explorer || true').toString()?.replace('\n', '') || 'https://chainz.cryptoid.info/marks/api.dws?q=txinfo&t='
203
+
204
+ explorerURI = 'http://gitmark.me/'
205
+ var command = `curl "${explorerURI}${lastCommit[0]}.json" > ${gitmarkTxBase}/${lastCommit[0]}.json`
202
206
  console.log(command)
203
- exec(command, console.log)
204
- console.log('do not run more than once per 10s')
205
- process.exit(-1)
207
+ $(command)
208
+ tx = JSON.parse(fs.readFileSync(gitmarkTxBase + '/' + lastCommit[0] + '.json').toString())
209
+ if (!tx.total_output) tx.total_output = tx.vout[0].value
210
+ // console.log('tx', tx)
211
+ // console.log('do not run more than once per 10s')
212
+ // process.exit(-1)
206
213
  }
207
214
 
208
- var nextfee = tx.total_output - tx.fees
215
+ var fee = tx?.fees || 0.00001
216
+ var nextfee = tx.total_output - fee
209
217
  nextfee = Math.round((nextfee + Number.EPSILON) * 100000000) / 100000000
210
218
 
211
219
  var priv = data.genesis ? b1 : b5
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ // USAGE: git-mark [privkeyhex] [$(git rev-parse HEAD)]
4
+
5
+ // IMPORTS
6
+ const bitcoin = require('bitcoinjs-lib')
7
+ const tiny = require('tiny-secp256k1')
8
+ const argv = require('minimist')(process.argv.slice(2))
9
+ const gitlog = require('gitlog').default
10
+ const fs = require('fs')
11
+ const homedir = require('os').homedir()
12
+ const exec = require('child_process').exec
13
+ const $ = require('child_process').execSync
14
+ const execSync = require('child_process').execSync
15
+
16
+ // MODEL
17
+ // default privkey = brain for urn:json:bitmark
18
+ globalThis.data = {
19
+ address: null,
20
+ sshkey: '$HOME/.ssh/id_rsa',
21
+ salt: null,
22
+ secret: null,
23
+ genesistxo: null,
24
+ faucet: 'http://faucet.gitmark.me/'
25
+ }
26
+
27
+ // FUNCTIONS
28
+ function getConfig(key) {
29
+ try {
30
+ var cmd = `git config ${key}`
31
+ var secret = execSync(cmd)?.toString()?.replace('\n', '')
32
+ return secret
33
+ } catch (e) {
34
+ }
35
+ }
36
+
37
+ function init(str) {
38
+ return argv[str] || getConfig('gitmark.' + str) || data[str]
39
+ }
40
+
41
+ // INIT
42
+ let NETWORK = require('../lib/networks.js').BITMARK
43
+ if (process.env.NETWORK) {
44
+ NETWORK = require('../lib/networks.js')[process.env.NETWORK] || NETWORK
45
+ }
46
+ console.log('NETWORK', NETWORK)
47
+
48
+ data.address = init('address')
49
+ data.sshkey = init('sshkey')
50
+ data.salt = init('salt')
51
+ data.secret = init('secret')
52
+ data.genesistxo = init('genesistxo')
53
+ data.faucet = init('faucet')
54
+
55
+
56
+ console.log('data', data)
57
+
58
+ // MAIN
59
+ // check if already init
60
+ console.log('checking if init already')
61
+ // how
62
+ // config
63
+ // gitmark.json
64
+ // commits
65
+
66
+ function getNewSecret() {
67
+ try {
68
+ var sshkey = `$HOME/.ssh/id_rsa`
69
+ var cmd = `pwd | ssh-keygen -Y sign -f ${sshkey} -n gitmark - | sha256sum | head -c 64`
70
+ var newSecret = $(cmd).toString()
71
+ return newSecret
72
+ } catch {
73
+
74
+ }
75
+ }
76
+
77
+ // get secret
78
+ // generate secret if none
79
+ if (data.secret) {
80
+ console.log('no secret found')
81
+ var newsecret = getNewSecret()
82
+ console.log('newsecret', newsecret)
83
+ data.secret = newsecret
84
+
85
+
86
+ // var gen = $(`git config gitmark.secret $(git config--get remote.origin.url | ssh - keygen - Y sign - f ~/.ssh/id_rsa - n gitmark - | sha256sum | head - c 40)`)
87
+ // console.log(gen)
88
+
89
+ }
90
+
91
+ console.log('using secret', data.secret)
92
+
93
+ // generate address from secret
94
+ const POINT = Buffer.from(data.secret, 'hex')
95
+ var keyPair1 = bitcoin.ECPair.fromPrivateKey(POINT)
96
+ console.log('public keys hex buffer')
97
+ console.log(keyPair1.publicKey)
98
+ console.log('private keys hex')
99
+ var { address } = bitcoin.payments.p2pkh({
100
+ pubkey: keyPair1.publicKey,
101
+ network: NETWORK
102
+ })
103
+ console.log('pubkey address computed from private', address)
104
+
105
+ // todo: put all in config, if not there
106
+
107
+
108
+ // get faucet
109
+ console.log('faucet', data.faucet)
110
+
111
+ // add to faucet
112
+ console.log('type', address, 'into', data.faucet, 'and wait for tx to get in a block')
113
+
114
+ // todo get tx value
115
+
116
+ // todo print to screen
117
+
118
+ // create gitmark.json
119
+ console.log('create gitmark.json and check in files')
120
+
121
+ // git mark genesis
122
+ console.log('run git mark --genesis tx')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitmark",
3
- "version": "0.0.24",
3
+ "version": "0.0.28",
4
4
  "description": "gitmark",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,7 +14,8 @@
14
14
  "gitmark"
15
15
  ],
16
16
  "bin": {
17
- "git-mark": "bin/git-mark"
17
+ "git-mark": "bin/git-mark",
18
+ "git-mark-init": "bin/git-mark-init"
18
19
  },
19
20
  "author": "Melvin Carvalho",
20
21
  "license": "MIT",