Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vignette
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engélibert
vignette
Commits
145d80b4
Commit
145d80b4
authored
3 years ago
by
matograine
Browse files
Options
Downloads
Patches
Plain Diff
adapt Tuxmain code to generate checksums. For lightness.
parent
32e9f8db
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
source/files/index.html
+2
-2
2 additions, 2 deletions
source/files/index.html
source/scr/checksum.js
+139
-0
139 additions, 0 deletions
source/scr/checksum.js
source/scr/duniter_tools.js
+0
-59
0 additions, 59 deletions
source/scr/duniter_tools.js
source/scr/main.js
+6
-4
6 additions, 4 deletions
source/scr/main.js
with
147 additions
and
65 deletions
source/files/index.html
+
2
−
2
View file @
145d80b4
...
...
@@ -178,7 +178,7 @@
</div>
</div>
<script
src=
"../theme/materialize.min.js"
></script>
<script
src=
"../scr/
duniter_tools
.js"
></script>
<script
src=
"../scr/
checksum
.js"
></script>
<script
src=
"../scr/qrcode.js"
></script>
<script>
//---- allow side-navigation for mobiles ----
...
...
This diff is collapsed.
Click to expand it.
source/scr/checksum.js
0 → 100644
+
139
−
0
View file @
145d80b4
// From https://github.com/45678/Base58
var
ALPHABET
,
ALPHABET_MAP
,
Base58
,
i
;
var
Base58
=
{};
ALPHABET
=
"
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
"
;
ALPHABET_MAP
=
{};
i
=
0
;
while
(
i
<
ALPHABET
.
length
)
{
ALPHABET_MAP
[
ALPHABET
.
charAt
(
i
)]
=
i
;
i
++
;
}
Base58
.
encode
=
function
(
buffer
)
{
var
carry
,
digits
,
j
;
if
(
buffer
.
length
===
0
)
{
return
""
;
}
i
=
void
0
;
j
=
void
0
;
digits
=
[
0
];
i
=
0
;
while
(
i
<
buffer
.
length
)
{
j
=
0
;
while
(
j
<
digits
.
length
)
{
digits
[
j
]
<<=
8
;
j
++
;
}
digits
[
0
]
+=
buffer
[
i
];
carry
=
0
;
j
=
0
;
while
(
j
<
digits
.
length
)
{
digits
[
j
]
+=
carry
;
carry
=
(
digits
[
j
]
/
58
)
|
0
;
digits
[
j
]
%=
58
;
++
j
;
}
while
(
carry
)
{
digits
.
push
(
carry
%
58
);
carry
=
(
carry
/
58
)
|
0
;
}
i
++
;
}
i
=
0
;
while
(
buffer
[
i
]
===
0
&&
i
<
buffer
.
length
-
1
)
{
digits
.
push
(
0
);
i
++
;
}
return
digits
.
reverse
().
map
(
function
(
digit
)
{
return
ALPHABET
[
digit
];
}).
join
(
""
);
};
Base58
.
decode
=
function
(
string
)
{
var
bytes
,
c
,
carry
,
j
;
if
(
string
.
length
===
0
)
{
return
""
;
}
i
=
void
0
;
j
=
void
0
;
bytes
=
[
0
];
i
=
0
;
while
(
i
<
string
.
length
)
{
c
=
string
[
i
];
if
(
!
(
c
in
ALPHABET_MAP
))
{
throw
"
Base58.decode received unacceptable input. Character '
"
+
c
+
"
' is not in the Base58 alphabet.
"
;
}
j
=
0
;
while
(
j
<
bytes
.
length
)
{
bytes
[
j
]
*=
58
;
j
++
;
}
bytes
[
0
]
+=
ALPHABET_MAP
[
c
];
carry
=
0
;
j
=
0
;
while
(
j
<
bytes
.
length
)
{
bytes
[
j
]
+=
carry
;
carry
=
bytes
[
j
]
>>
8
;
bytes
[
j
]
&=
0xff
;
++
j
;
}
while
(
carry
)
{
bytes
.
push
(
carry
&
0xff
);
carry
>>=
8
;
}
i
++
;
}
i
=
0
;
while
(
string
[
i
]
===
"
1
"
&&
i
<
string
.
length
-
1
)
{
bytes
.
push
(
0
);
i
++
;
}
return
bytes
.
reverse
();
};
// ---- in html (from Tuxmain)----
const
FORMAT_ERR
=
"
Invalid format
"
;
function
fill_pubkey
(
pubkey
)
{
return
"
\
x00
"
.
repeat
(
32
-
pubkey
.
length
)
+
pubkey
;
}
// This is a simple oneliner in Python. JS is one of the worst scripting languages ever.
async
function
gen_checksum
(
pubkey
)
{
// Why does this need async?
var
checksum
=
await
window
.
crypto
.
subtle
.
digest
(
'
SHA-256
'
,
new
Uint8Array
(
pubkey
));
console
.
log
(
checksum
);
// Why on Earth the await needs an assignation and can't be used directly? This is stupid.
var
checksum
=
await
window
.
crypto
.
subtle
.
digest
(
'
SHA-256
'
,
new
Uint8Array
(
checksum
));
return
Base58
.
encode
(
new
Uint8Array
(
checksum
)).
slice
(
0
,
3
);
}
// Matograine mix
function
check_B58
(
str
)
{
return
str
.
match
(
/^
[
1-9A-HJ-NP-Za-km-z
]
*$/
)
!==
null
;
}
//public_key_checksum_from_b58(string_b58) → (string_b58)
//return a checksum of a public key
//return -1 if bad format of public key
async
function
public_key_checksum_from_b58
(
public_keyb58
)
{
if
(
check_B58
(
public_keyb58
)
==
false
)
return
-
1
;
var
public_key
=
Base58
.
decode
(
public_keyb58
);
if
(
public_key
.
bytesLength
>
32
){
return
-
1
;
}
//pubkey = fill_pubkey(pubkey);
return
await
gen_checksum
(
public_key
);
};
This diff is collapsed.
Click to expand it.
source/scr/duniter_tools.js
deleted
100644 → 0
+
0
−
59
View file @
32e9f8db
This diff is collapsed.
Click to expand it.
source/scr/main.js
+
6
−
4
View file @
145d80b4
...
...
@@ -36,7 +36,7 @@
//----------- main script -----------------
function
createVignette
(
event
)
{
async
function
createVignette
(
event
)
{
event
.
preventDefault
();
// get elements
let
title
=
document
.
forms
[
"
formulaire
"
][
"
title
"
].
value
;
...
...
@@ -52,7 +52,7 @@
}
// check pubkey + ck and add checksum if necessary
// alert if pubkey+ck is wrong
pubkey
=
checkPubKeyAndChecksum
(
pubkey
);
pubkey
=
await
checkPubKeyAndChecksum
(
pubkey
);
if
(
pubkey
==
0
)
{
return
;
}
...
...
@@ -127,7 +127,7 @@
return
true
;
}
function
checkPubKeyAndChecksum
(
pubkey
)
{
async
function
checkPubKeyAndChecksum
(
pubkey
)
{
// separate pubkey from checksum and test formats.
let
separatePubkey
;
let
checksum
;
...
...
@@ -136,7 +136,9 @@
return
0
};
// compute pubkey checksum
checksum
=
public_key_checksum_from_b58
(
separatePubkey
[
0
]);
//checksum = public_key_checksum_from_b58(separatePubkey[0]);
checksum
=
await
public_key_checksum_from_b58
(
separatePubkey
[
0
])
console
.
log
(
checksum
)
if
(
checksum
===
-
1
)
{
alert
(
Function_STRING_ERROR_INVALID_PUBKEY
(
separatePubkey
[
0
])
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment