-
Notifications
You must be signed in to change notification settings - Fork 3
/
pix.js
51 lines (48 loc) · 1.5 KB
/
pix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//https://www.bcb.gov.br/content/estabilidadefinanceira/forumpireunioes/AnexoI-PadroesParaIniciacaodoPix.pdf
//https://www.bcb.gov.br/content/estabilidadefinanceira/SiteAssets/Manual%20do%20BR%20Code.pdf
pixRef = {
'0' : '01',
'26' : {
'00' : 'br.gov.bcb.pix',
'01' : '123e4567-e12b-12d1-a456-426655440000'
},
'52' : '0000',
'53' : '986',
'58' : 'BR',
'59' : 'Fulano de Tal',
'60' : 'BRASILIA',
'62' : {
'05' : '***'
}
}
function pixparse(o,deep=0){
let k = Object.keys(o)
let s = ''
for (let i=0; i<k.length; i++){
if (typeof(o[k[i]]) == 'string'){
console.debug(''.padStart(deep,'*'),
k[i].toString().padStart(2,'0'),
o[k[i]].length.toString().padStart(2,'0'),
o[k[i]])
s += '' +
k[i].toString().padStart(2,'0') +
o[k[i]].length.toString().padStart(2,'0') +
o[k[i]]
} else {
let si = pixparse(o[k[i]],deep+1)
console.debug(''.padStart(deep,'*'),
k[i],
si.length.toString().padStart(2,'0'),
si)
s += '' +
k[i].toString().padStart(2,'0') +
si.length.toString().padStart(2,'0') +
si
}
}
return s
}
function pixGenerate(pix){
let p = pixparse(pix)+'6304'
return p+(crc16(p)).toString(16).toUpperCase()
}