gitmark 0.0.23
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/CNAME +1 -0
- package/LICENSE +21 -0
- package/README.md +156 -0
- package/bin/addpub.js +134 -0
- package/bin/git-mark +232 -0
- package/bin/git-mark-verify +114 -0
- package/bin/tx.sh +11 -0
- package/lib/networks.js +80 -0
- package/package.json +33 -0
- package/resitry.json +3 -0
package/CNAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
git-mark.com
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 solidpayorg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>gitmark</h1>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
Mark your git commits, to create global consensus, and a definitive project history
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<h4>Getting Started</h4>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[](https://github.com/solidpayorg/git-mark/blob/gh-pages/LICENSE)
|
|
19
|
+

|
|
20
|
+
[](https://npmjs.com/package/gitmark)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Introduction
|
|
24
|
+
|
|
25
|
+
Gitmark extends git to allow commits to be "marked" (using the command `git mark`) by a supporting block chain. This "reinforces" or "finalizes" a given commit, to determine global consensus and a definitive project history
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
sudo npm install -g gitmark
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git mark # marks the current commit
|
|
37
|
+
|
|
38
|
+
git mark [--genesis txoutput] # used for the genesis commit
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Motivation
|
|
42
|
+
|
|
43
|
+
Gitmark, was originally created to facilitate the [marking](https://github.com/project-bitmark/marking/wiki) use case, which aims to allow global, distributed, reputation trees, to be grounded in a block chain
|
|
44
|
+
|
|
45
|
+
What is made possible, is a way to provide consensus on a definitive git branch/chain, in order to ensure that the history has not been tampered with
|
|
46
|
+
|
|
47
|
+
One can reconstruct the current state from the history, and this can also be used to preserve your reputation at any given time, say, if any provider ceases to operate
|
|
48
|
+
|
|
49
|
+
It's also possible to audit and verify the integrity of the git chain, to create a secure, finalized, state machine, with a definitive head, that is globally synced
|
|
50
|
+
|
|
51
|
+
The system can be extended beyond reputation trees, to use any git based store, and anchor it to a secure, verifyable chain of blocks, to determine the definitve history
|
|
52
|
+
|
|
53
|
+
Many thanks go to Peter Todd for his work on [single use seals](https://petertodd.org/2017/scalable-single-use-seal-asset-transfer) and Dr Maxim Orlovsky for his work on [RGB](https://rgb-org.github.io/)
|
|
54
|
+
|
|
55
|
+
_Gitmark is pre-alpha software, it should be considered experimental, and used at your own risk_
|
|
56
|
+
|
|
57
|
+
## Prerequisites
|
|
58
|
+
|
|
59
|
+
Because gitmark was designed to anchor reputation trees, the reputation of the underlying block chain must be unimpared. Gitmark only supports block chains that are provably fair. Bitcoin is regarded as the most secure and fairest of all block chains, and should be used for high value projects where cost is not an issue
|
|
60
|
+
|
|
61
|
+
Gitmark does not support projects that are premines, instamines, ICOs, have developer taxes or provably unfair consensus, such as proof of stake
|
|
62
|
+
|
|
63
|
+
In solving the reputation use case, we aim to innovate in the space, contribute back code, and operate as a testing ground
|
|
64
|
+
|
|
65
|
+
Bearing in mind that this is experimental software, the [bitmark](https://bitmark.rocks/) block chain, is the first chain on which gitmark is tested and implemented. As it inexpensive, easily obitained, and was designed for the grounding of reputation trees (gitmark is a play on the word bitmark). This also provides a testing ground for developers to get started. The Liquid network is also a possible target, and Litecoin appears to be another good possibility, as well as the various testnets
|
|
66
|
+
|
|
67
|
+
The first prerequisite is to obtain an unspent transaction on a supporting block chain. This can be in any coin, but to get started we suggest, getting hold of one Bitmark, which can be obtained inexpensively for example in the [chat room](https://projectbitmark.slack.com/) as it is designed to be spread between helpful actors, to foster innovation
|
|
68
|
+
|
|
69
|
+
## Getting started
|
|
70
|
+
|
|
71
|
+
After you have obtained some block chain currency, send those coins to an address for which you have the keypair. That becomes the genesis unspent transaction
|
|
72
|
+
|
|
73
|
+
Having created a genesis transaction, and recording the key pair safely, you are ready to start marking!
|
|
74
|
+
|
|
75
|
+
Install gitmark globally via npm, the executables will be in the bin directory which can be located with `which git-mark`
|
|
76
|
+
|
|
77
|
+
The genesis transaction provides the first input to the `git mark` command, and the private key (secret exponent in hex) is needed to advance the genesis transaction in line with the current git HEAD
|
|
78
|
+
|
|
79
|
+
## Git mark
|
|
80
|
+
|
|
81
|
+
Simply running `git mark` on a repo will create your first marking
|
|
82
|
+
|
|
83
|
+
You will need a genesis address for the first run of the form `tx:output` and supply that with the argument --genesis [tx]
|
|
84
|
+
|
|
85
|
+
You will also need the private key from that tx, which is an argument to the gitmark script, but can be also saved in a location as directed by the output from the git mark command. The key (ie 64 char hex secret exponent) should be stored in the indicated file with the json key "privkey"
|
|
86
|
+
|
|
87
|
+
_Warning: do not use the default private key, that is set, in the script!_
|
|
88
|
+
|
|
89
|
+
Git mark will generate a new address to send to, a fee, an amount, a spending private key and unspent tx data as inputs to an rpc or a simple script `tx.sh` that lives in the bin directory. Future versions will use a transaction builder to send to a network directly
|
|
90
|
+
|
|
91
|
+
After running this script, an empty commit message is generated which you can check in, and points to the latest new unspent transaction, creating a two way link
|
|
92
|
+
|
|
93
|
+
Congratulations! You have now marked your first git repo!
|
|
94
|
+
|
|
95
|
+
## How it works
|
|
96
|
+
|
|
97
|
+
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
|
|
98
|
+
|
|
99
|
+
In this way the block chain points to git. It then points the next commit back to the block chain tx, creating two way link, and therefore, strong binding, at one particular point in time
|
|
100
|
+
|
|
101
|
+
Similarly the definitive git tree forms a chain of commits that go forward in time, and so do the new transaction on the block chain. Further commits are periodically marked in time proving an auditable trail in both time on-chain of the evolution of the git tree. It also shows the latest confirmed state of a git tree that can be used for trading or in safe or smart contracts
|
|
102
|
+
|
|
103
|
+
The first use case for gitmark is marking of reputation trees, but it can be applied to any git system where the history is important
|
|
104
|
+
|
|
105
|
+
## Recent git marks
|
|
106
|
+
|
|
107
|
+
- [Github](https://github.com/search?o=desc&q=%22gitmark+%22&s=committer-date&type=Commits)
|
|
108
|
+
|
|
109
|
+
## Use Cases
|
|
110
|
+
|
|
111
|
+
- Distributed Reputation Trees
|
|
112
|
+
- Distributed Ledgers
|
|
113
|
+
- Registries
|
|
114
|
+
- Safe or Smart Contracts
|
|
115
|
+
- Asset Issuance
|
|
116
|
+
- Distributed Exchanges
|
|
117
|
+
- Reconstruct histories from Genesis
|
|
118
|
+
- Distributed Global Consensus
|
|
119
|
+
- Domain independent web sites
|
|
120
|
+
- Archiving and Time Travel through History
|
|
121
|
+
- Distributed Identity and PKI
|
|
122
|
+
- Federated Side Chains
|
|
123
|
+
- Auditing Histories
|
|
124
|
+
- Fraud Detection
|
|
125
|
+
- Supply Chains
|
|
126
|
+
|
|
127
|
+
## Related work
|
|
128
|
+
|
|
129
|
+
- [Single Use Seals](https://petertodd.org/2017/scalable-single-use-seal-asset-transfer)
|
|
130
|
+
- [RGB](https://rgb-org.github.io/)
|
|
131
|
+
- [Commerce Block Mainstay](https://www.commerceblock.com/mainstay/) [[White Paper](https://cloudflare-ipfs.com/ipns/ipfs.commerceblock.com/commerceblock-whitepaper-mainstay.pdf)]
|
|
132
|
+
- [BIP 175 - Pay to Contract Protocol](https://github.com/bitcoin/bips/blob/master/bip-0175.mediawiki)
|
|
133
|
+
|
|
134
|
+
## Source code
|
|
135
|
+
|
|
136
|
+
- [Source](https://github.com/solidpayorg/gitmark)
|
|
137
|
+
- [Issue Tracker](https://github.com/solidpayorg/gitmark/issues)
|
|
138
|
+
- [NPM](https://www.npmjs.com/package/gitmark)
|
|
139
|
+
|
|
140
|
+
## Future work
|
|
141
|
+
|
|
142
|
+
- Git marks can be extended to further layers by using git submodules hence creating almost unlimited space
|
|
143
|
+
|
|
144
|
+
- Private git repositories can be supported out of the box, and given that private keys are used in each seal, encrypted backups can be made
|
|
145
|
+
|
|
146
|
+
- The project git tree can be backed up or archived using git clone in multiple locations. It is natural that popular projects are cloned often in any case
|
|
147
|
+
|
|
148
|
+
- Seals can be opened and closed using a federation, in order to try out multiple consensus and vefification methods
|
|
149
|
+
|
|
150
|
+
- More robust verification frameworks can be built using node testing frameworks, and continusous integration, tho currently the distribution contains a git-mark-verify script
|
|
151
|
+
|
|
152
|
+
- Lightweight Autonomous Marking Agents (LAMAs) can be created that listen to communities for marks and just work, without needing a human operator. The service can be deployed on a server or container, and be designed to bring itself up if it goes down in any one location
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
- MIT
|
package/bin/addpub.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// USAGE: git-mark [privkeyhex] [$(git rev-parse HEAD)]
|
|
4
|
+
|
|
5
|
+
// IMPORTS
|
|
6
|
+
var bitcoin = require('bitcoinjs-lib')
|
|
7
|
+
var tiny = require('tiny-secp256k1')
|
|
8
|
+
var 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
|
+
|
|
13
|
+
// MODEL
|
|
14
|
+
// default privkey = brain for urn:json:bitmark
|
|
15
|
+
globalThis.data = {
|
|
16
|
+
privkey: '132e7465a63e30a74c5b0deae3573033319e9de18a84878613eaa21878b2b56b',
|
|
17
|
+
hash: 'b3e8f5735849af7f18a13ead08532043a7f82153',
|
|
18
|
+
genesis: null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// FUNCTIONS
|
|
22
|
+
const BITMARK = {
|
|
23
|
+
messagePrefix: '\x19BITMARK Signed Message:\n',
|
|
24
|
+
bech32: 'btm',
|
|
25
|
+
bip32: {
|
|
26
|
+
public: 0x019da462,
|
|
27
|
+
private: 0x019d9cfe
|
|
28
|
+
},
|
|
29
|
+
pubKeyHash: 85,
|
|
30
|
+
scriptHash: 0x32,
|
|
31
|
+
wif: 213
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const options = {
|
|
35
|
+
repo: './',
|
|
36
|
+
fields: ['subject', 'authorName', 'authorDate'],
|
|
37
|
+
execOptions: { maxBuffer: 1000 * 1024 },
|
|
38
|
+
number: 1000,
|
|
39
|
+
fields: ['hash', 'subject']
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getPrivKey () {
|
|
43
|
+
try {
|
|
44
|
+
const fetchHeadDir = './.git/'
|
|
45
|
+
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
|
|
46
|
+
|
|
47
|
+
var fetchHead = fs.readFileSync(fetchHeadFile).toString()
|
|
48
|
+
|
|
49
|
+
var repo = fetchHead
|
|
50
|
+
.split(' ')
|
|
51
|
+
.pop()
|
|
52
|
+
.replace(':', '/')
|
|
53
|
+
.replace('\n', '')
|
|
54
|
+
|
|
55
|
+
const gitmarkRepoBase = homedir + '/.gitmark/repo'
|
|
56
|
+
|
|
57
|
+
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
|
|
58
|
+
|
|
59
|
+
return require(gitmarkFile).privkey
|
|
60
|
+
} catch (e) {
|
|
61
|
+
const fetchHeadDir = './.git/'
|
|
62
|
+
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
|
|
63
|
+
|
|
64
|
+
var fetchHead = fs.readFileSync(fetchHeadFile).toString()
|
|
65
|
+
|
|
66
|
+
var repo = fetchHead
|
|
67
|
+
.split(' ')
|
|
68
|
+
.pop()
|
|
69
|
+
.replace(':', '/')
|
|
70
|
+
.replace('\n', '')
|
|
71
|
+
|
|
72
|
+
const gitmarkRepoBase = homedir + '/.gitmark/repo'
|
|
73
|
+
|
|
74
|
+
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
|
|
75
|
+
|
|
76
|
+
console.log('no priv key found in', gitmarkFile)
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// INIT
|
|
82
|
+
data.hash = argv._[0] || data.hash
|
|
83
|
+
data.privkey = argv._[1] || getPrivKey() || data.privkey
|
|
84
|
+
|
|
85
|
+
console.log('data', data)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const POINT = Buffer.from(data.privkey.padStart(64, 0), 'hex')
|
|
89
|
+
|
|
90
|
+
const OFFSET = Buffer.from(data.hash.padStart(64, 0), 'hex')
|
|
91
|
+
|
|
92
|
+
// MAIN
|
|
93
|
+
// priv keys
|
|
94
|
+
const b1 = BigInt('0x' + data.privkey)
|
|
95
|
+
const b2 = BigInt('0x' + data.hash)
|
|
96
|
+
const b3 = BigInt.asUintN(256, b1 + b2)
|
|
97
|
+
|
|
98
|
+
// print priv keys
|
|
99
|
+
console.log('private keys hex')
|
|
100
|
+
console.log(b1.toString(16))
|
|
101
|
+
console.log(b2.toString(16))
|
|
102
|
+
console.log(b3.toString(16))
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// pub keys
|
|
106
|
+
var keyPair1 = bitcoin.ECPair.fromPrivateKey(POINT)
|
|
107
|
+
var keyPair2 = bitcoin.ECPair.fromPrivateKey(OFFSET)
|
|
108
|
+
var keyPair3 = bitcoin.ECPair.fromPrivateKey(
|
|
109
|
+
Buffer.from(b3.toString(16).padStart(64, 0), 'hex')
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
// add pub keys together
|
|
113
|
+
const SUM = tiny.pointAdd(keyPair1.publicKey, keyPair2.publicKey)
|
|
114
|
+
|
|
115
|
+
// print pub keys
|
|
116
|
+
console.log('public keys hex buffer')
|
|
117
|
+
console.log(keyPair1.publicKey)
|
|
118
|
+
console.log(keyPair2.publicKey)
|
|
119
|
+
console.log(SUM)
|
|
120
|
+
|
|
121
|
+
// address from priv key addition
|
|
122
|
+
var { address } = bitcoin.payments.p2pkh({
|
|
123
|
+
pubkey: keyPair3.publicKey,
|
|
124
|
+
network: BITMARK
|
|
125
|
+
})
|
|
126
|
+
console.log('address computed from private', address)
|
|
127
|
+
|
|
128
|
+
// address from pub key addition
|
|
129
|
+
var { address } = bitcoin.payments.p2pkh({
|
|
130
|
+
pubkey: SUM,
|
|
131
|
+
network: BITMARK
|
|
132
|
+
})
|
|
133
|
+
console.log('address computed from public', address)
|
|
134
|
+
|
package/bin/git-mark
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
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
|
+
|
|
14
|
+
// MODEL
|
|
15
|
+
// default privkey = brain for urn:json:bitmark
|
|
16
|
+
globalThis.data = {
|
|
17
|
+
privkey: '132e7465a63e30a74c5b0deae3573033319e9de18a84878613eaa21878b2b56b',
|
|
18
|
+
hash: 'b3e8f5735849af7f18a13ead08532043a7f82153',
|
|
19
|
+
genesis: null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// FUNCTIONS
|
|
23
|
+
const options = {
|
|
24
|
+
repo: './',
|
|
25
|
+
fields: ['subject', 'authorName', 'authorDate'],
|
|
26
|
+
execOptions: { maxBuffer: 1000 * 1024 },
|
|
27
|
+
number: 1000,
|
|
28
|
+
fields: ['hash', 'subject']
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getPrivKey() {
|
|
32
|
+
try {
|
|
33
|
+
const fetchHeadDir = './.git/'
|
|
34
|
+
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
|
|
35
|
+
|
|
36
|
+
var fetchHead = fs.readFileSync(fetchHeadFile).toString()
|
|
37
|
+
|
|
38
|
+
var repo = fetchHead
|
|
39
|
+
.split(' ')
|
|
40
|
+
.pop()
|
|
41
|
+
.replace(':', '/')
|
|
42
|
+
.replace('\n', '')
|
|
43
|
+
|
|
44
|
+
const gitmarkRepoBase = homedir + '/.gitmark/repo'
|
|
45
|
+
|
|
46
|
+
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
|
|
47
|
+
|
|
48
|
+
return require(gitmarkFile).privkey
|
|
49
|
+
} catch (e) {
|
|
50
|
+
const fetchHeadDir = './.git/'
|
|
51
|
+
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
|
|
52
|
+
|
|
53
|
+
var fetchHead = fs.readFileSync(fetchHeadFile).toString()
|
|
54
|
+
|
|
55
|
+
var repo = fetchHead
|
|
56
|
+
.split(' ')
|
|
57
|
+
.pop()
|
|
58
|
+
.replace(':', '/')
|
|
59
|
+
.replace('\n', '')
|
|
60
|
+
|
|
61
|
+
const gitmarkRepoBase = homedir + '/.gitmark/repo'
|
|
62
|
+
|
|
63
|
+
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
|
|
64
|
+
|
|
65
|
+
console.log('no priv key found in', gitmarkFile)
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// INIT
|
|
71
|
+
let NETWORK = require('../lib/networks.js').BITMARK
|
|
72
|
+
if (process.env.NETWORK) {
|
|
73
|
+
NETWORK = require('../lib/networks.js')[process.env.NETWORK] || NETWORK
|
|
74
|
+
}
|
|
75
|
+
console.log('NETWORK', NETWORK)
|
|
76
|
+
|
|
77
|
+
const commits = gitlog(options)
|
|
78
|
+
var head = commits[0].hash
|
|
79
|
+
console.log('current head', head)
|
|
80
|
+
|
|
81
|
+
data.privkey = argv._[0] || getPrivKey() || data.privkey
|
|
82
|
+
data.hash = argv._[1] || head || data.hash
|
|
83
|
+
data.genesis = argv.genesis || data.genesis
|
|
84
|
+
|
|
85
|
+
console.log('data', data)
|
|
86
|
+
|
|
87
|
+
var lastCommit = commits.filter(i => {
|
|
88
|
+
return i.subject.match(/^gitmark/)
|
|
89
|
+
})
|
|
90
|
+
if (lastCommit && lastCommit[0] && lastCommit[0].subject) {
|
|
91
|
+
lastCommit = lastCommit[0].subject
|
|
92
|
+
lastCommit = lastCommit.split(' ').pop()
|
|
93
|
+
lastCommit = lastCommit.split(':')
|
|
94
|
+
console.log('lastCommit', lastCommit)
|
|
95
|
+
} else {
|
|
96
|
+
console.log('New repo, set up first gitmark')
|
|
97
|
+
console.log('Add private key')
|
|
98
|
+
console.log('Fund genesis tx with genesis hash')
|
|
99
|
+
console.log('Add --gensis and run')
|
|
100
|
+
lastCommit = data.genesis.split(':')
|
|
101
|
+
console.log('data.genesis', data.genesis)
|
|
102
|
+
if (!data.genesis) {
|
|
103
|
+
process.exit(-1)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const POINT = Buffer.from(data.privkey, 'hex')
|
|
108
|
+
|
|
109
|
+
const OFFSET = Buffer.from('000000000000000000000000' + data.hash, 'hex')
|
|
110
|
+
|
|
111
|
+
// MAIN
|
|
112
|
+
function findLastCommitHash() {
|
|
113
|
+
var i
|
|
114
|
+
for (i = 0; i < commits.length; i++) {
|
|
115
|
+
if (commits[i].subject.match(/^gitmark/)) break
|
|
116
|
+
}
|
|
117
|
+
if (i === commits.length) {
|
|
118
|
+
return head
|
|
119
|
+
} else {
|
|
120
|
+
return commits[i + 1].hash
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
var lastCommitHash = findLastCommitHash()
|
|
124
|
+
console.log('lastCommitHash', lastCommitHash)
|
|
125
|
+
|
|
126
|
+
// priv keys
|
|
127
|
+
const b1 = BigInt('0x' + data.privkey)
|
|
128
|
+
const b2 = BigInt('0x' + data.hash)
|
|
129
|
+
const b3 = BigInt.asUintN(256, b1 + b2)
|
|
130
|
+
const b4 = BigInt('0x' + lastCommitHash)
|
|
131
|
+
const b5 = BigInt.asUintN(256, b1 + b4)
|
|
132
|
+
|
|
133
|
+
// pub keys
|
|
134
|
+
var keyPair1 = bitcoin.ECPair.fromPrivateKey(POINT)
|
|
135
|
+
var keyPair2 = bitcoin.ECPair.fromPrivateKey(OFFSET)
|
|
136
|
+
var keyPair3 = bitcoin.ECPair.fromPrivateKey(
|
|
137
|
+
Buffer.from(b3.toString(16).padStart(64, 0), 'hex')
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
// add pub keys together
|
|
141
|
+
const SUM = tiny.pointAdd(keyPair1.publicKey, keyPair2.publicKey)
|
|
142
|
+
|
|
143
|
+
// print pub keys
|
|
144
|
+
console.log('public keys hex buffer')
|
|
145
|
+
console.log(keyPair1.publicKey)
|
|
146
|
+
console.log(keyPair2.publicKey)
|
|
147
|
+
console.log(SUM)
|
|
148
|
+
|
|
149
|
+
// print priv keys
|
|
150
|
+
console.log('private keys hex')
|
|
151
|
+
console.log(b1.toString(16))
|
|
152
|
+
console.log(b2.toString(16))
|
|
153
|
+
console.log(b3.toString(16))
|
|
154
|
+
console.log(b4.toString(16))
|
|
155
|
+
console.log(b5.toString(16))
|
|
156
|
+
|
|
157
|
+
// address from priv key addition
|
|
158
|
+
var { address } = bitcoin.payments.p2pkh({
|
|
159
|
+
pubkey: keyPair3.publicKey,
|
|
160
|
+
network: NETWORK
|
|
161
|
+
})
|
|
162
|
+
console.log('address computed from private', address)
|
|
163
|
+
|
|
164
|
+
// address from pub key addition
|
|
165
|
+
var { address } = bitcoin.payments.p2pkh({
|
|
166
|
+
pubkey: SUM,
|
|
167
|
+
network: NETWORK
|
|
168
|
+
})
|
|
169
|
+
console.log('address computed from public', address)
|
|
170
|
+
|
|
171
|
+
var fee = 1000
|
|
172
|
+
var tx
|
|
173
|
+
const gitmarkTxBase = homedir + '/.gitmark/tx'
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
if (data.genesis) {
|
|
177
|
+
tx = { total_output: '1', fees: '0.00001' }
|
|
178
|
+
} else {
|
|
179
|
+
tx = require(gitmarkTxBase + '/' + lastCommit[0] + '.json')
|
|
180
|
+
}
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error(e)
|
|
183
|
+
console.error(
|
|
184
|
+
'error: need tx: ' +
|
|
185
|
+
lastCommit[0] +
|
|
186
|
+
'in ' +
|
|
187
|
+
gitmarkTxBase +
|
|
188
|
+
'/' +
|
|
189
|
+
lastCommit[0] +
|
|
190
|
+
'.json'
|
|
191
|
+
)
|
|
192
|
+
console.log('trying:')
|
|
193
|
+
var command = `curl "https://chainz.cryptoid.info/marks/api.dws?q=txinfo&t=${lastCommit[0]}" > ${gitmarkTxBase}/${lastCommit[0]}.json`
|
|
194
|
+
console.log(command)
|
|
195
|
+
exec(command, console.log)
|
|
196
|
+
console.log('do not run more than once per 10s')
|
|
197
|
+
process.exit(-1)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var nextfee = tx.total_output - tx.fees
|
|
201
|
+
nextfee = Math.round((nextfee + Number.EPSILON) * 100000000) / 100000000
|
|
202
|
+
|
|
203
|
+
var priv = data.genesis ? b1 : b5
|
|
204
|
+
var keyPair1 = bitcoin.ECPair.fromPrivateKey(
|
|
205
|
+
Buffer.from(priv.toString(16).padStart(64, 0), 'hex'),
|
|
206
|
+
{ network: NETWORK }
|
|
207
|
+
)
|
|
208
|
+
console.log('private key WIF:', keyPair1.toWIF())
|
|
209
|
+
|
|
210
|
+
console.log('last commit hash', lastCommit.hash)
|
|
211
|
+
|
|
212
|
+
console.log(nextfee)
|
|
213
|
+
console.log('console commands')
|
|
214
|
+
// console.log(
|
|
215
|
+
// 'createrawtransaction',
|
|
216
|
+
// lastCommit[0],
|
|
217
|
+
// lastCommit[1],
|
|
218
|
+
// address,
|
|
219
|
+
// nextfee
|
|
220
|
+
// )
|
|
221
|
+
lastCommit[1] = lastCommit[1] || 0
|
|
222
|
+
console.log(
|
|
223
|
+
`createrawtransaction '[{"txid": "${lastCommit[0]}", "vout": ${lastCommit[1]}}]' '{"${address}": ${nextfee}}'`
|
|
224
|
+
)
|
|
225
|
+
var hex = `1234`
|
|
226
|
+
// console.log('signrawtransaction', keyPair1.toWIF())
|
|
227
|
+
console.log(`signrawtransaction ${hex} null '["${keyPair1.toWIF()}"]'`)
|
|
228
|
+
console.log('sendrawtransaction')
|
|
229
|
+
console.log(
|
|
230
|
+
`bin/tx.sh ${lastCommit[0]} ${lastCommit[1]
|
|
231
|
+
} ${address} ${nextfee} ${keyPair1.toWIF()}`
|
|
232
|
+
)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// USAGE: git-mark-verify
|
|
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
|
+
|
|
12
|
+
// MODEL
|
|
13
|
+
// default privkey = brain for urn:json:bitmark
|
|
14
|
+
globalThis.data = {
|
|
15
|
+
privkey: '132e7465a63e30a74c5b0deae3573033319e9de18a84878613eaa21878b2b56b'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// console.log('data', data)
|
|
19
|
+
|
|
20
|
+
// FUNCTIONS
|
|
21
|
+
const BITMARK = {
|
|
22
|
+
messagePrefix: '\x19BITMARK Signed Message:\n',
|
|
23
|
+
bech32: 'btm',
|
|
24
|
+
bip32: {
|
|
25
|
+
public: 0x019da462,
|
|
26
|
+
private: 0x019d9cfe
|
|
27
|
+
},
|
|
28
|
+
pubKeyHash: 85,
|
|
29
|
+
wif: 213,
|
|
30
|
+
scriptHash: 0x32
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const options = {
|
|
34
|
+
repo: './',
|
|
35
|
+
fields: ['subject', 'authorName', 'authorDate'],
|
|
36
|
+
execOptions: { maxBuffer: 1000 * 1024 },
|
|
37
|
+
number: 1000,
|
|
38
|
+
fields: ['hash', 'subject']
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getPrivKey () {
|
|
42
|
+
try {
|
|
43
|
+
const fetchHeadDir = './.git/'
|
|
44
|
+
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD'
|
|
45
|
+
|
|
46
|
+
var fetchHead = fs.readFileSync(fetchHeadFile).toString()
|
|
47
|
+
|
|
48
|
+
var repo = fetchHead
|
|
49
|
+
.split(' ')
|
|
50
|
+
.pop()
|
|
51
|
+
.replace(':', '/')
|
|
52
|
+
.replace('\n', '')
|
|
53
|
+
|
|
54
|
+
const gitmarkRepoBase = homedir + '/.gitmark/repo'
|
|
55
|
+
|
|
56
|
+
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json'
|
|
57
|
+
|
|
58
|
+
return require(gitmarkFile).privkey
|
|
59
|
+
} catch {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// INIT
|
|
65
|
+
data.privkey = argv._[0] || getPrivKey() || data.privkey
|
|
66
|
+
|
|
67
|
+
var POINT = Buffer.from(data.privkey, 'hex')
|
|
68
|
+
|
|
69
|
+
var OFFSET = Buffer.from('000000000000000000000000' + data.hash, 'hex')
|
|
70
|
+
|
|
71
|
+
// MAIN
|
|
72
|
+
// priv keys
|
|
73
|
+
var b1 = BigInt('0x' + data.privkey)
|
|
74
|
+
var b2
|
|
75
|
+
var b3
|
|
76
|
+
|
|
77
|
+
// commits
|
|
78
|
+
const commits = gitlog(options)
|
|
79
|
+
if (commits.length === 1) {
|
|
80
|
+
console.log('Set up new repository with a gitmark')
|
|
81
|
+
process.exit()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log('Genesis tx need not be verified\n')
|
|
85
|
+
for (var i = commits.length-1; i >= 0; i--) {
|
|
86
|
+
var subject = commits[i].subject
|
|
87
|
+
if (subject.match(/^gitmark/)) {
|
|
88
|
+
var hash = commits[i + 1].hash
|
|
89
|
+
console.log()
|
|
90
|
+
console.log(subject)
|
|
91
|
+
console.log('hash:', hash)
|
|
92
|
+
b2 = BigInt('0x' + hash)
|
|
93
|
+
b3 = BigInt.asUintN(256, b1 + b2)
|
|
94
|
+
console.log(b3.toString(16))
|
|
95
|
+
var keyPair1 = bitcoin.ECPair.fromPrivateKey(
|
|
96
|
+
Buffer.from(b3.toString(16), 'hex'),
|
|
97
|
+
{ network: BITMARK }
|
|
98
|
+
)
|
|
99
|
+
console.log('private key WIF:', keyPair1.toWIF())
|
|
100
|
+
|
|
101
|
+
var { address } = bitcoin.payments.p2pkh({
|
|
102
|
+
pubkey: keyPair1.publicKey,
|
|
103
|
+
network: BITMARK
|
|
104
|
+
})
|
|
105
|
+
console.log('verify address computed from private key:', address)
|
|
106
|
+
|
|
107
|
+
console.log(
|
|
108
|
+
'https://chainz.cryptoid.info/marks/tx.dws?' +
|
|
109
|
+
subject.split(' ')[1].split(':')[0] +
|
|
110
|
+
'.htm'
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
package/bin/tx.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
RAWTX=$(bitmark-cli createrawtransaction '[{"txid": "'$1'", "vout": '$2'}]' '{"'$3'": '$4'}')
|
|
4
|
+
|
|
5
|
+
SENDTX=$(bitmark-cli signrawtransaction $RAWTX null '["'$5'"]' | grep ffff | sed 's/.*: "\(.*\)".*/\1/')
|
|
6
|
+
|
|
7
|
+
NEWTX=$(bitmark-cli sendrawtransaction $SENDTX)
|
|
8
|
+
|
|
9
|
+
echo $NEWTX
|
|
10
|
+
|
|
11
|
+
echo "git commit --allow-empty -m 'gitmark $NEWTX'"
|
package/lib/networks.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// network
|
|
2
|
+
exports.BITCOIN = {
|
|
3
|
+
baseNetwork: 'bitcoin',
|
|
4
|
+
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
5
|
+
bech32: 'bc',
|
|
6
|
+
bip32: {
|
|
7
|
+
public: 0x04b24746,
|
|
8
|
+
private: 0x04b2430c
|
|
9
|
+
},
|
|
10
|
+
pubKeyHash: 0x00,
|
|
11
|
+
scriptHash: 0x05,
|
|
12
|
+
wif: 0x80
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.BITMARK = {
|
|
16
|
+
messagePrefix: '\x19BITMARK Signed Message:\n',
|
|
17
|
+
bech32: 'btm',
|
|
18
|
+
bip32: {
|
|
19
|
+
public: 0x019da462,
|
|
20
|
+
private: 0x019d9cfe
|
|
21
|
+
},
|
|
22
|
+
pubKeyHash: 85,
|
|
23
|
+
scriptHash: 0x32,
|
|
24
|
+
wif: 213
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.LIQUID = {
|
|
28
|
+
messagePrefix: '\x18Liquid Signed Message:\n',
|
|
29
|
+
bech32: 'ex',
|
|
30
|
+
blech32: 'lq',
|
|
31
|
+
bip32: {
|
|
32
|
+
public: 0x0488b21e,
|
|
33
|
+
private: 0x0488ade4
|
|
34
|
+
},
|
|
35
|
+
pubKeyHash: 57,
|
|
36
|
+
scriptHash: 39,
|
|
37
|
+
wif: 0x80,
|
|
38
|
+
confidentialPrefix: 12,
|
|
39
|
+
assetHash: '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.TESTNET3 = {
|
|
43
|
+
baseNetwork: 'testnet',
|
|
44
|
+
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
45
|
+
bech32: 'tb',
|
|
46
|
+
bip32: {
|
|
47
|
+
public: 0x045f1cf6,
|
|
48
|
+
private: 0x045f18bc
|
|
49
|
+
},
|
|
50
|
+
pubKeyHash: 0x6f,
|
|
51
|
+
scriptHash: 0xc4,
|
|
52
|
+
wif: 0xef
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.REGTEST = {
|
|
56
|
+
baseNetwork: 'regtest',
|
|
57
|
+
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
58
|
+
bech32: 'bcrt',
|
|
59
|
+
bip32: {
|
|
60
|
+
public: 0x045f1cf6,
|
|
61
|
+
private: 0x045f18bc
|
|
62
|
+
},
|
|
63
|
+
pubKeyHash: 0x6f,
|
|
64
|
+
scriptHash: 0xc4,
|
|
65
|
+
wif: 0xef
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.LITECOIN = {
|
|
69
|
+
coin: 'ltc',
|
|
70
|
+
bech32: 'ltc',
|
|
71
|
+
bip32: {
|
|
72
|
+
private: 27106558, // xprv_magic
|
|
73
|
+
public: 28471030 // xpub_magic_segwit_p2sh
|
|
74
|
+
},
|
|
75
|
+
dustThreshold: 0, // doesn't matter, for type correctness,
|
|
76
|
+
messagePrefix: 'Litecoin Signed Message:\n',
|
|
77
|
+
pubKeyHash: 48, // address_type
|
|
78
|
+
scriptHash: 50, // address_type_p2sh
|
|
79
|
+
wif: 128 // doesn't matter, for type correctness
|
|
80
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gitmark",
|
|
3
|
+
"version": "0.0.23",
|
|
4
|
+
"description": "gitmark",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/solidpayorg/gitmark.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"gitmark"
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"git-mark": "bin/git-mark"
|
|
18
|
+
},
|
|
19
|
+
"author": "Melvin Carvalho",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/solidpayorg/gitmark/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/solidpayorg/gitmark#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"bitcoinjs-lib": "^5.2.0",
|
|
27
|
+
"child_process": "^1.0.2",
|
|
28
|
+
"fs": "^0.0.1-security",
|
|
29
|
+
"gitlog": "^4.0.4",
|
|
30
|
+
"minimist": "^1.2.5",
|
|
31
|
+
"tiny-secp256k1": "^1.1.6"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/resitry.json
ADDED