Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
offshiftXFT
offshift-frontend-public
Commits
bde794d5
Commit
bde794d5
authored
2 years ago
by
XFT
Browse files
Options
Download
Email Patches
Plain Diff
.
parent
67aa780a
master
No related merge requests found
Pipeline
#28
failed with stages
in 0 seconds
Changes
198
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
695725 additions
and
0 deletions
+695725
-0
src/app/core/services/contracts-abi.ts
src/app/core/services/contracts-abi.ts
+7148
-0
src/app/core/services/crypto.js
src/app/core/services/crypto.js
+105
-0
src/app/core/services/pedersen.js
src/app/core/services/pedersen.js
+26
-0
src/app/core/services/wallet.service.ts
src/app/core/services/wallet.service.ts
+164
-0
src/app/core/services/withdraw.json
src/app/core/services/withdraw.json
+687488
-0
src/app/core/types/index.ts
src/app/core/types/index.ts
+13
-0
src/app/views/error/error-routing.module.ts
src/app/views/error/error-routing.module.ts
+10
-0
src/app/views/error/error.component.html
src/app/views/error/error.component.html
+1
-0
src/app/views/error/error.component.scss
src/app/views/error/error.component.scss
+0
-0
src/app/views/error/error.component.spec.ts
src/app/views/error/error.component.spec.ts
+25
-0
src/app/views/error/error.component.ts
src/app/views/error/error.component.ts
+16
-0
src/app/views/error/error.module.ts
src/app/views/error/error.module.ts
+16
-0
src/app/views/mpc/contributions/contributions.component.html
src/app/views/mpc/contributions/contributions.component.html
+102
-0
src/app/views/mpc/contributions/contributions.component.scss
src/app/views/mpc/contributions/contributions.component.scss
+134
-0
src/app/views/mpc/contributions/contributions.component.spec.ts
...p/views/mpc/contributions/contributions.component.spec.ts
+25
-0
src/app/views/mpc/contributions/contributions.component.ts
src/app/views/mpc/contributions/contributions.component.ts
+157
-0
src/app/views/mpc/contributions/phase2/LICENSE-APACHE
src/app/views/mpc/contributions/phase2/LICENSE-APACHE
+201
-0
src/app/views/mpc/contributions/phase2/LICENSE-MIT
src/app/views/mpc/contributions/phase2/LICENSE-MIT
+23
-0
src/app/views/mpc/contributions/phase2/README.md
src/app/views/mpc/contributions/phase2/README.md
+47
-0
src/app/views/mpc/contributions/phase2/package.json
src/app/views/mpc/contributions/phase2/package.json
+24
-0
No files found.
src/app/core/services/contracts-abi.ts
0 → 100644
View file @
bde794d5
This diff is collapsed.
Click to expand it.
src/app/core/services/crypto.js
0 → 100644
View file @
bde794d5
import
crypto
from
'
crypto
'
import
{
BN
,
toBN
}
from
'
web3-utils
'
import
{
pedersen
}
from
'
./pedersen
'
const
CUT_LENGTH
=
31
export
function
parseNote
(
note
)
{
const
[,
currency
,
amount
,
netId
,
saveNote
]
=
note
.
split
(
'
-
'
)
return
{
...
parseSaveNote
(
saveNote
),
netId
,
amount
,
currency
}
}
export
function
parseSaveNote
(
saveNote
)
{
const
nullifier
=
BigInt
(
`0x
${
saveNote
.
slice
(
2
,
64
)}
`
)
const
secret
=
BigInt
(
`0x
${
saveNote
.
slice
(
64
,
126
)}
`
)
const
preimage
=
Buffer
.
concat
([
nullifier
.
leInt2Buff
(
31
),
secret
.
leInt2Buff
(
31
)])
let
hexNote
=
`0x
${
preimage
.
toString
(
'
hex
'
)}
`
const
buffNote
=
Buffer
.
from
(
hexNote
.
slice
(
2
),
'
hex
'
)
const
commitment
=
buffPedersenHash
(
buffNote
)
const
nullifierBuff
=
buffNote
.
slice
(
0
,
CUT_LENGTH
)
const
nullifierHash
=
BigInt
(
buffPedersenHash
(
nullifierBuff
))
return
{
secret
,
nullifier
,
commitment
,
nullifierBuff
,
nullifierHash
,
commitmentHex
:
toFixedHex
(
commitment
),
nullifierHex
:
toFixedHex
(
nullifierHash
)
}
}
export
function
leInt2Buff
(
value
,
bytes
)
{
return
new
BN
(
value
,
16
,
'
le
'
)
}
export
function
randomBN
(
nbytes
=
31
)
{
return
toBN
(
leInt2Buff
(
crypto
.
randomBytes
(
nbytes
)).
toString
())
}
export
function
buffPedersenHash
(
buffer
)
{
const
[
hash
]
=
pedersen
.
unpackPoint
(
buffer
)
return
pedersen
.
toStringBuffer
(
hash
)
}
export
function
toFixedHex
(
value
,
length
=
32
)
{
const
isBuffer
=
value
instanceof
Buffer
const
str
=
isBuffer
?
value
.
toString
(
'
hex
'
)
:
BigInt
(
value
).
toString
(
16
)
return
'
0x
'
+
str
.
padStart
(
length
*
2
,
'
0
'
)
}
export
const
isEmptyArray
=
(
arr
)
=>
!
Array
.
isArray
(
arr
)
||
!
arr
.
length
export
function
packEncryptedMessage
(
encryptedMessage
)
{
const
nonceBuf
=
Buffer
.
from
(
encryptedMessage
.
nonce
,
'
base64
'
)
const
ephemPublicKeyBuf
=
Buffer
.
from
(
encryptedMessage
.
ephemPublicKey
,
'
base64
'
)
const
ciphertextBuf
=
Buffer
.
from
(
encryptedMessage
.
ciphertext
,
'
base64
'
)
const
messageBuff
=
Buffer
.
concat
([
Buffer
.
alloc
(
24
-
nonceBuf
.
length
),
nonceBuf
,
Buffer
.
alloc
(
32
-
ephemPublicKeyBuf
.
length
),
ephemPublicKeyBuf
,
ciphertextBuf
])
return
'
0x
'
+
messageBuff
.
toString
(
'
hex
'
)
}
export
function
unpackEncryptedMessage
(
encryptedMessage
)
{
if
(
encryptedMessage
.
slice
(
0
,
2
)
===
'
0x
'
)
{
encryptedMessage
=
encryptedMessage
.
slice
(
2
)
}
const
messageBuff
=
Buffer
.
from
(
encryptedMessage
,
'
hex
'
)
const
nonceBuf
=
messageBuff
.
slice
(
0
,
24
)
const
ephemPublicKeyBuf
=
messageBuff
.
slice
(
24
,
56
)
const
ciphertextBuf
=
messageBuff
.
slice
(
56
)
return
{
version
:
'
x25519-xsalsa20-poly1305
'
,
nonce
:
nonceBuf
.
toString
(
'
base64
'
),
ephemPublicKey
:
ephemPublicKeyBuf
.
toString
(
'
base64
'
),
ciphertext
:
ciphertextBuf
.
toString
(
'
base64
'
)
}
}
export
function
checkCommitments
(
events
=
[])
{
events
.
forEach
(({
leafIndex
},
i
)
=>
{
if
(
leafIndex
!==
i
)
{
console
.
error
(
`Missing deposit event for deposit #
${
i
}
`
)
throw
new
Error
(
window
.
$nuxt
.
$t
(
'
failedToFetchAllDepositEvents
'
))
}
})
}
This diff is collapsed.
Click to expand it.
src/app/core/services/pedersen.js
0 → 100644
View file @
bde794d5
import
{
buildPedersenHash
}
from
'
circomlibjs
'
class
Pedersen
{
constructor
()
{
this
.
pedersenHash
=
null
this
.
babyJub
=
null
this
.
initPedersen
()
}
async
initPedersen
()
{
this
.
pedersenHash
=
await
buildPedersenHash
()
this
.
babyJub
=
this
.
pedersenHash
.
babyJub
}
unpackPoint
(
buffer
)
{
return
this
.
babyJub
.
unpackPoint
(
this
.
pedersenHash
.
hash
(
buffer
))
}
toStringBuffer
(
buffer
)
{
return
this
.
babyJub
.
F
.
toString
(
buffer
)
}
}
const
pedersen
=
new
Pedersen
()
export
{
pedersen
}
This diff is collapsed.
Click to expand it.
src/app/core/services/wallet.service.ts
0 → 100644
View file @
bde794d5
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Store
}
from
'
@ngrx/store
'
;
import
{
environment
}
from
'
../../../environments/environment
'
;
import
WalletConnect
from
'
@walletconnect/web3-provider
'
;
import
{
BehaviorSubject
,
Subject
}
from
'
rxjs
'
;
import
Web3
from
'
web3
'
;
import
Web3Modal
from
'
web3modal
'
;
import
{
SetAccountAddress
}
from
'
../actions
'
;
import
{
EthEvents
,
EthMethods
}
from
'
../enums
'
;
import
{
ConnectInfo
,
EthChainParams
,
Ethereum
,
ProviderMessage
,
ProviderRpcError
,
}
from
'
../interfaces/ethereum
'
;
import
{
BaseService
}
from
'
./base.service
'
;
@
Injectable
({
providedIn
:
'
root
'
})
export
class
WalletService
extends
BaseService
{
public
get
web3
():
Web3
{
return
this
.
_web3
;
}
public
get
web3Modal
():
Web3Modal
{
return
this
.
_web3Modal
;
}
private
_web3
:
Web3
;
private
_web3Modal
:
Web3Modal
;
private
_accountsChanged$
:
BehaviorSubject
<
string
[]
>
=
new
BehaviorSubject
<
string
[]
>
([]);
private
_chainChanged$
:
BehaviorSubject
<
string
|
null
>
=
new
BehaviorSubject
<
string
>
(
null
);
private
_networkChanged$
:
BehaviorSubject
<
number
|
null
>
=
new
BehaviorSubject
<
number
|
null
>
(
null
);
private
_balanceChanged$
:
BehaviorSubject
<
string
|
null
>
=
new
BehaviorSubject
<
string
>
(
null
);
private
_connectChanged$
:
Subject
<
ConnectInfo
>
=
new
Subject
<
ConnectInfo
>
();
private
_disconnectChanged$
:
Subject
<
ProviderRpcError
>
=
new
Subject
<
ProviderRpcError
>
();
private
_messageChanged$
:
Subject
<
ProviderMessage
>
=
new
Subject
<
ProviderMessage
>
();
constructor
(
store
:
Store
,
)
{
super
(
store
);
}
public
async
initialize
():
Promise
<
void
>
{
const
providerOptions
=
{
walletconnect
:
{
package
:
WalletConnect
,
// required
options
:
{
infuraId
:
environment
.
walletConnectId
// required
},
},
};
this
.
_web3Modal
=
new
Web3Modal
({
network
:
'
mainnet
'
,
// optional
cacheProvider
:
true
,
// optional
providerOptions
,
// required
theme
:
{
background
:
'
#FFFFFF
'
,
main
:
'
#1B0D3D
'
,
secondary
:
'
#1B0D3D
'
,
border
:
'
rgba(88, 0, 176, 0.05)
'
,
hover
:
'
rgba(88, 0, 176, 0.15)
'
,
},
});
if
(
this
.
web3Modal
.
cachedProvider
)
{
return
this
.
connect
();
}
}
public
async
connect
():
Promise
<
void
>
{
try
{
const
provider
=
await
this
.
_web3Modal
.
connect
();
await
this
.
_subscribeProvider
(
provider
);
this
.
_web3
=
new
Web3
(
provider
);
const
[
accountAddress
]
=
await
this
.
_web3
.
eth
.
getAccounts
();
let
account
=
{
[
accountAddress
]:
{
'
noStorage
'
:
''
,
'
password
'
:
''
}
}
localStorage
.
setItem
(
"
account
"
,
accountAddress
)
if
(
!
localStorage
.
getItem
(
"
config
"
)){
localStorage
.
setItem
(
"
config
"
,
JSON
.
stringify
(
account
))
}
else
{
let
config
=
JSON
.
parse
(
localStorage
.
getItem
(
"
config
"
))
if
(
!
config
[
accountAddress
]){
config
[
accountAddress
]
=
account
[
accountAddress
];
localStorage
.
setItem
(
"
config
"
,
JSON
.
stringify
(
config
))
}
}
this
.
store
.
dispatch
(
SetAccountAddress
({
accountAddress
}));
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
public
clearCachedProvider
():
void
{
this
.
_web3Modal
.
clearCachedProvider
();
}
public
async
switchEthereumChain
(
chainId
:
string
):
Promise
<
void
>
{
await
this
.
_request
(
EthMethods
.
SwitchEthereumChain
,
[{
chainId
}]);
}
public
async
addEthereumChain
(
params
:
Partial
<
EthChainParams
>
):
Promise
<
void
>
{
await
this
.
_request
(
EthMethods
.
AddEthereumChain
,
[
params
]);
}
private
_request
<
T
=
any
>
(
method
:
EthMethods
,
params
?:
unknown
[]
|
Record
<
string
,
unknown
>
,
):
Promise
<
T
>
{
const
eth
=
(
window
as
any
).
ethereum
as
Ethereum
;
return
eth
.
request
({
method
,
params
});
}
private
async
_subscribeProvider
(
provider
:
any
)
{
if
(
!
provider
.
on
)
{
return
;
}
provider
.
on
(
EthEvents
.
ChainChanged
,
(
chainId
:
string
)
=>
{
console
.
log
(
EthEvents
.
ChainChanged
,
'
:
'
,
chainId
);
// It's recommended to reload the page on chain changes, unless you have good reason not to.
window
.
location
.
reload
();
});
provider
.
on
(
EthEvents
.
AccountsChanged
,
([
accountAddress
]:
string
[])
=>
{
this
.
connect
();
this
.
store
.
dispatch
(
SetAccountAddress
({
accountAddress
}));
window
.
location
.
reload
();
});
provider
.
on
(
EthEvents
.
Connect
,
(
connectInfo
:
ConnectInfo
)
=>
{
console
.
log
(
EthEvents
.
Connect
,
'
:
'
,
connectInfo
);
this
.
_connectChanged$
.
next
(
connectInfo
);
});
provider
.
on
(
EthEvents
.
Disconnect
,
(
error
:
ProviderRpcError
)
=>
{
console
.
log
(
EthEvents
.
Disconnect
,
'
:
'
,
error
);
this
.
_disconnectChanged$
.
next
(
error
);
});
provider
.
on
(
EthEvents
.
Message
,
(
message
:
ProviderMessage
)
=>
{
console
.
log
(
EthEvents
.
Message
,
'
:
'
,
message
);
this
.
_messageChanged$
.
next
(
message
);
});
}
}
This diff is collapsed.
Click to expand it.
src/app/core/services/withdraw.json
0 → 100644
View file @
bde794d5
This diff is collapsed.
Click to expand it.
src/app/core/types/index.ts
0 → 100644
View file @
bde794d5
import
{
Tokens
,
TokensName
}
from
'
../enums
'
;
export
type
TokenType
=
{
color
:
string
;
icon
:
string
;
name
:
string
;
balance
?:
string
;
symbol
:
string
;
//TokensName;
zkSymbol
:
string
;
//Tokens;
denom
:
BigInt
;
shifter
:
string
;
contract
:
string
;
}
This diff is collapsed.
Click to expand it.
src/app/views/error/error-routing.module.ts
0 → 100644
View file @
bde794d5
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
RouterModule
,
Routes
}
from
'
@angular/router
'
;
const
routes
:
Routes
=
[];
@
NgModule
({
imports
:
[
RouterModule
.
forChild
(
routes
)],
exports
:
[
RouterModule
]
})
export
class
ErrorRoutingModule
{
}
This diff is collapsed.
Click to expand it.
src/app/views/error/error.component.html
0 → 100644
View file @
bde794d5
<p>
error works!
</p>
This diff is collapsed.
Click to expand it.
src/app/views/error/error.component.scss
0 → 100644
View file @
bde794d5
This diff is collapsed.
Click to expand it.
src/app/views/error/error.component.spec.ts
0 → 100644
View file @
bde794d5
import
{
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ErrorComponent
}
from
'
./error.component
'
;
describe
(
'
ErrorComponent
'
,
()
=>
{
let
component
:
ErrorComponent
;
let
fixture
:
ComponentFixture
<
ErrorComponent
>
;
beforeEach
(
async
()
=>
{
await
TestBed
.
configureTestingModule
({
declarations
:
[
ErrorComponent
]
})
.
compileComponents
();
});
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
ErrorComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
This diff is collapsed.
Click to expand it.
src/app/views/error/error.component.ts
0 → 100644
View file @
bde794d5
import
{
Component
,
OnInit
,
ChangeDetectionStrategy
}
from
'
@angular/core
'
;
@
Component
({
selector
:
'
os-error
'
,
templateUrl
:
'
./error.component.html
'
,
styleUrls
:
[
'
./error.component.scss
'
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
})
export
class
ErrorComponent
implements
OnInit
{
constructor
()
{
}
public
ngOnInit
():
void
{
}
}
This diff is collapsed.
Click to expand it.
src/app/views/error/error.module.ts
0 → 100644
View file @
bde794d5
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
CommonModule
}
from
'
@angular/common
'
;
import
{
ErrorRoutingModule
}
from
'
./error-routing.module
'
;
import
{
ErrorComponent
}
from
'
./error.component
'
;
@
NgModule
({
declarations
:
[
ErrorComponent
],
imports
:
[
CommonModule
,
ErrorRoutingModule
]
})
export
class
ErrorModule
{
}
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/contributions.component.html
0 → 100644
View file @
bde794d5
<div
class=
"contributions__content"
>
<ng-container
[ngSwitch]=
"buttonState"
>
<span
*ngSwitchCase =
"'Contributing'"
class =
"p-input-icon-right"
>
<div>
Contribution in progress, please wait.
</div>
</span>
<span
*ngSwitchCase =
"'Tweet'"
class =
"p-input-icon-right"
>
<div>
Contribution complete!
<br>
Post your attestation to Twitter using the link below:
</div>
</span>
<span
*ngSwitchDefault
class =
"p-input-icon-right"
>
<div
style=
"margin: 0.5em"
>
Enter a random text string in the box below.
</div>
<input
#inputElement
[ngModel]=
"value"
[placeholder]=
"placeholder"
(ngModelChange)=
"onChange($event)"
type=
"text"
pInputText
class=
"contributions__input"
>
</span>
</ng-container>
</div>
<div
class =
"contributions__content"
>
<ng-container
[ngSwitch]=
"buttonState"
>
<button
*ngSwitchCase =
"'Contributing'"
[disabled]=
"true"
pButton
class=
"contributions__button"
id=
"button"
type=
"button"
label=
"Contributing"
>
<i
class=
"pi pi-spin pi-spinner"
style=
"font-size: 1rem;"
></i>
</button>
<button
*ngSwitchCase=
"'Tweet'"
(click)=
"makeTweet()"
pButton
class=
"contributions__twitter"
id=
"tweet"
type=
"button"
label=
" Tweet"
>
<i
class=
"pi pi-twitter"
></i>
</button>
<button
*ngSwitchCase=
"'Tweet'"
(click)=
"copyHash()"
pButton
pTooltip=
"Copy the Attestation to clipboard"
[showDelay]=
"1000"
id=
"button"
type=
"button"
label=
"Copy Attestation"
>
<i
class=
"pi pi-copy"
></i>
</button>
<button
*ngSwitchDefault
(click)=
"onRandomInput()"
pButton
pTooltip=
"Make a contribution"
[showDelay]=
"1000"
class=
"contributions__button"
type=
"button"
id=
"button"
label=
"Submit"
>
</button>
</ng-container>
</div>
<ng-template
#inProgressView
>
<div
class =
"contributions__content"
>
<button
[disabled]=
"true"
pButton
class=
"contributions__button"
id=
"button"
type=
"button"
label=
"In Progress"
>
<i
class=
"pi pi-spin pi-spinner"
style=
"font-size: 1rem;"
></i>
</button>
</div>
</ng-template>
<ng-template
#tweet
>
<button
(click)=
"makeTweet()"
pButton
id=
"tweet"
type=
"button"
style=
"margin-top: 0.5em; padding: 0.75rem 3rem;"
label=
" Make Tweet"
>
<i
class=
"pi pi-twitter"
></i>
</button>
<!--a >Tweet Your Contribution</a-->
</ng-template>
<ng-template
#default
>
<button
(click)=
"onRandomInput()"
pButton
class=
"contributions__button"
type=
"button"
style=
"width: 66%; margin-top: 0.5rem; padding: 0.75rem 3rem;"
label=
"Make Contribution"
>
</button>
</ng-template>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/contributions.component.scss
0 → 100644
View file @
bde794d5
@use
"sass:math"
;
@import
"~src/styles/variables"
;
:host
{
display
:
block
;
}
#tweet
{
background
:
#1DA1F2
;
border
:
none
;
gap
:
math
.
div
(
$offshift-gap
*
3
,
6
);
margin
:
0
.5em
;
padding
:
0
.75rem
2
.5rem
;
}
#button
{
border
:
none
;
gap
:
math
.
div
(
$offshift-gap
*
3
,
6
);
margin
:
0
.5em
;
padding
:
0
.75rem
2
.5rem
;
}
.contributions
{
display
:
flex
;
flex-direction
:
column
;
margin
:
5
.25rem
auto
0
;
padding
:
2rem
1
.5rem
;
width
:
50rem
;
bottom
:
10
.8125rem
;
background
:
#1B0D3D
;
box-shadow
:
0
0
.75rem
2rem
rgba
(
0
,
0
,
0
,
0
.32
);
border-radius
:
0
.5rem
;
gap
:
math
.
div
(
$offshift-gap
*
3
,
2
);;
&
&
__button
{
display
:
block
;
width
:
100%
;
margin
:
2em
;
}
&
&
__twitter
{
display
:
block
;
width
:
100%
;
background
:
#1DA1F2
;
}
&
&
__header
{
display
:
flex
;
align-items
:
center
;
justify-content
:
space-between
;
}
&
&
__label
{
font-weight
:
600
;
font-size
:
0
.75rem
;
line-height
:
1
.1875rem
;
margin-bottom
:
0
.75rem
;
}
&
&
__content
{
height
:
2
.25rem
;
display
:
flex
;
align-items
:
center
;
gap
:
0
.75rem
;
>
.pi.pi-angle-down
{
color
:
#AA8CFF
;
font-size
:
1
.125rem
;
&
:hover
{
cursor
:
pointer
;
}
}
}
&
&
__manual
{
font-weight
:
600
;
font-size
:
0
.75rem
;
line-height
:
1
.1875rem
;
color
:
#AA8CFF
;
margin-bottom
:
0
.75rem
;
margin-left
:
auto
;
margin-top
:
-0
.5rem
;
&
:hover
{
cursor
:
pointer
;
}
}
&
&
__input
{
font-family
:
$offshift-font-family
;
font-weight
:
600
;
font-size
:
1rem
;
color
:
#FFFFFF
;
width
:
100%
;
height
:
100%
;
border
:
0
;
background-color
:
transparent
;
display
:
flex
;
margin
:
2em
;
&
::placeholder
{
font-family
:
inherit
;
font-weight
:
normal
;
font-size
:
0
.875rem
;
color
:
#FFFFFF
;
opacity
:
0
.5
;
}
}
&
&
__max
,
&
&
__name
{
font-weight
:
600
;
font-size
:
1rem
;
}
&
&
__max
{
color
:
#AA8CFF
;
&
:hover
{
cursor
:
pointer
;
}
}
&
&
__name
{
color
:
#FFFFFF
;
}
&
&
__image
{
width
:
2
.25rem
;
height
:
2
.25rem
;
display
:
block
;
}
}
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/contributions.component.spec.ts
0 → 100644
View file @
bde794d5
import
{
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ContributionsComponent
}
from
'
./contributions.component
'
;
describe
(
'
ContributionsComponent
'
,
()
=>
{
let
component
:
ContributionsComponent
;
let
fixture
:
ComponentFixture
<
ContributionsComponent
>
;
beforeEach
(
async
()
=>
{
await
TestBed
.
configureTestingModule
({
declarations
:
[
ContributionsComponent
]
})
.
compileComponents
();
});
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
ContributionsComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/contributions.component.ts
0 → 100644
View file @
bde794d5
import
{
Component
,
OnInit
,
ChangeDetectionStrategy
,
Input
,
Output
,
EventEmitter
,
ViewChild
,
ElementRef
,
ChangeDetectorRef
}
from
'
@angular/core
'
;
import
{
ControlValueAccessor
}
from
'
@angular/forms
'
;
import
{
contribute
}
from
'
./phase2/phase2.js
'
;
import
{
Clipboard
}
from
'
@angular/cdk/clipboard
'
;
import
init
from
'
./phase2/phase2.js
'
const
crypto
=
require
(
'
crypto
'
)
import
{
environment
}
from
'
../../../../environments/environment
'
const
host
=
environment
.
ceremonyHost
const
port
=
environment
.
ceremonyPort
const
Web3Utils
=
require
(
"
web3-utils
"
)
function
buf2hex
(
buffer
:
ArrayBuffer
)
{
// buffer is an ArrayBuffer
return
Array
.
prototype
.
map
.
call
(
new
Uint8Array
(
buffer
),
(
x
)
=>
(
'
00
'
+
x
.
toString
(
16
)).
slice
(
-
2
))
.
join
(
''
)
}
@
Component
({
selector
:
'
os-contributions
'
,
templateUrl
:
'
./contributions.component.html
'
,
styleUrls
:
[
'
./contributions.component.scss
'
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
})
export
class
ContributionsComponent
implements
OnInit
,
ControlValueAccessor
{
@
ViewChild
(
'
inputElement
'
,
{
static
:
true
})
public
inputElement
!
:
ElementRef
<
HTMLInputElement
>
@
Input
()
public
placeholder
!
:
string
;
@
Output
(
'
getDatabase
'
)
getDatabaseEventEmitter
:
EventEmitter
<
any
>
=
new
EventEmitter
<
any
>
();
public
value
!
:
string
;
public
tweet
:
string
;
public
attestation
:
string
;
public
contributionComplete
:
boolean
;
public
inProgress
:
boolean
;
public
buttonState
:
'
Contributing
'
|
'
Tweet
'
;
constructor
(
private
readonly
_cdr
:
ChangeDetectorRef
,
private
clipboard
:
Clipboard
)
{
}
public
async
makeContribution
({
userInput
=
''
,
retry
=
0
}
=
{})
{
this
.
buttonState
=
'
Contributing
'
let
_wasmFile
=
(
await
fetch
(
`
${
host
}
:
${
port
}
/api/wasm`
));
let
_wasmBuffer
=
await
_wasmFile
.
arrayBuffer
()
let
_wasm
=
await
WebAssembly
.
compile
(
_wasmBuffer
)
init
(
_wasm
)
try
{
let
_data
=
await
fetch
(
`
${
host
}
:
${
port
}
/api/challenge`
)
let
dataBuffer
=
await
_data
.
arrayBuffer
()
let
data
=
new
Uint8Array
(
dataBuffer
)
await
this
.
sleep
(
100
)
// allow UI to update before freezing in wasm
const
msgBuffer
=
new
TextEncoder
().
encode
(
userInput
)
const
hashBuffer
=
await
window
.
crypto
.
subtle
.
digest
(
'
SHA-256
'
,
msgBuffer
)
const
entropyFromUser
=
new
Uint8Array
(
hashBuffer
)
const
entropyFromBrowser
=
window
.
crypto
.
getRandomValues
(
new
Uint8Array
(
32
))
// double check this call
// suffle the browser and user random
const
entropy
=
new
Uint8Array
(
entropyFromBrowser
.
length
)
for
(
let
i
=
0
;
i
<
entropyFromBrowser
.
length
;
i
++
)
{
entropy
[
i
]
=
entropyFromBrowser
[
i
]
+
entropyFromUser
[
i
]
}
await
this
.
sleep
(
100
)
// so browser can render the messages
const
result
=
contribute
(
data
,
entropy
)
const
hash
=
'
0x
'
+
buf2hex
(
result
.
slice
(
0
,
64
))
const
contribution
=
result
.
slice
(
64
)
// Generate 32 byte attestation preimage and commit it to Keccak256 hash
const
attestPreimage
=
Web3Utils
.
randomHex
(
32
)
const
attestHex
=
Web3Utils
.
sha3
(
attestPreimage
)
this
.
attestation
=
attestPreimage
const
formData
=
new
FormData
()
formData
.
append
(
'
response
'
,
new
Blob
([
contribution
],
{
type
:
'
application/octet-stream
'
}))
formData
.
append
(
'
attestHex
'
,
attestHex
)
formData
.
append
(
'
contributionHash
'
,
hash
)
const
resp
=
await
fetch
(
`
${
host
}
:
${
port
}
/api/response`
,
{
method
:
'
POST
'
,
body
:
formData
})
if
(
resp
.
ok
)
{
const
entry
=
await
fetch
(
`
${
host
}
:
${
port
}
/api/latest`
)
const
body
=
await
entry
.
json
()
const
responseData
=
await
resp
.
json
()
this
.
buttonState
=
'
Tweet
'
this
.
tweet
=
`https://twitter.com/intent/tweet?text=I made contribution number
${
body
[
"
id
"
]}
to the @OffshiftXFT multiparty computation, my attestation preimage is:
${
this
.
attestation
}
.`
console
.
log
(
`contribution complete:
${
this
.
contributionComplete
}
`
)
console
.
log
(
this
.
tweet
)
this
.
_cdr
.
markForCheck
();
// Success
}
else
if
(
resp
.
status
===
422
)
{
if
(
retry
<
3
)
{
// Retry 3 times
console
.
log
(
`Looks like someone else uploaded contribution ahead of us, retrying`
)
await
this
.
makeContribution
({
userInput
,
retry
:
retry
++
})
}
else
{
// Contribution failed to upload after multiple retries
}
}
else
{
// Contribution failed to upload
}
}
catch
(
e
)
{
console
.
error
(
e
)
}
finally
{
this
.
getDatabaseEventEmitter
.
emit
();
//this.$root.$emit('disableLoading')
}
}
public
copyHash
()
{
const
copy
=
this
.
clipboard
.
copy
(
this
.
attestation
)
}
public
sleep
(
ms
:
number
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
))
}
public
makeTweet
():
void
{
window
.
location
.
href
=
this
.
tweet
}
public
onRandomInput
():
void
{
this
.
makeContribution
()
this
.
_cdr
.
markForCheck
();
}
ngOnInit
():
void
{
}
public
writeValue
(
value
:
string
):
void
{
this
.
value
=
value
;
this
.
_cdr
.
markForCheck
();
}
registerOnChange
(
fn
:
any
):
void
{
}
registerOnTouched
(
fn
:
any
):
void
{
}
setDisabledState
?(
isDisabled
:
boolean
):
void
{
}
public
onChange
(
value
:
string
):
void
{
this
.
value
=
value
;
if
(
this
.
inputElement
?.
nativeElement
)
{
const
inputElement
=
this
.
inputElement
.
nativeElement
as
HTMLInputElement
;
inputElement
.
value
=
this
.
value
?
this
.
value
:
''
;
}
this
.
_cdr
.
markForCheck
();
}
}
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/phase2/LICENSE-APACHE
0 → 100644
View file @
bde794d5
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/phase2/LICENSE-MIT
0 → 100644
View file @
bde794d5
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/phase2/README.md
0 → 100644
View file @
bde794d5
# phase2 [](https://crates.io/crates/phase2) #
This library is still under development.
## WebAssembly how-to
Build wasm package using
`wasm-pack build --release -- --no-default-features --features wasm`
this will generate
`./pkg`
directory with wasm file and js bindings. After that you
can use this package in your browser application like so:
```
js
async
function
main
()
{
const
phase2
=
await
import
(
"
./pkg/phase2.js
"
)
let
data
=
await
fetch
(
'
params
'
)
data
=
await
data
.
arrayBuffer
()
data
=
new
Uint8Array
(
data
)
console
.
log
(
'
Source params
'
,
data
)
const
result
=
phase2
.
contribute
(
data
)
console
.
log
(
'
Updated params
'
,
result
)
// upload updated params
}
main
().
catch
(
console
.
error
)
```
## [Documentation](https://docs.rs/phase2/)
## Security Warnings
This library does not make any guarantees about constant-time operations, memory access patterns, or resistance to side-channel attacks.
## License
Licensed under either of
*
Apache License, Version 2.0, (
[
LICENSE-APACHE
](
LICENSE-APACHE
)
or http://www.apache.org/licenses/LICENSE-2.0)
*
MIT license (
[
LICENSE-MIT
](
LICENSE-MIT
)
or http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.
This diff is collapsed.
Click to expand it.
src/app/views/mpc/contributions/phase2/package.json
0 → 100644
View file @
bde794d5
{
"name"
:
"phase2"
,
"collaborators"
:
[
"Sean Bowe <ewillbefull@gmail.com>"
],
"description"
:
"Library for performing MPCs for creating zk-SNARK public parameters"
,
"version"
:
"0.2.2"
,
"license"
:
"MIT/Apache-2.0"
,
"repository"
:
{
"type"
:
"git"
,
"url"
:
"https://github.com/ebfull/phase2"
},
"files"
:
[
"phase2_bg.wasm"
,
"phase2.js"
,
"phase2.d.ts"
,
"LICENSE-APACHE"
,
"LICENSE-MIT"
],
"module"
:
"phase2.js"
,
"homepage"
:
"https://github.com/ebfull/phase2"
,
"types"
:
"phase2.d.ts"
,
"sideEffects"
:
false
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
6
7
8
…
10
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help